@extends('layouts.app')
@section('title', $page_title)

@push('scripts')
<script src="{{asset('assets/js/show-password.js')}}"></script>
@endpush

@section('content')
<div class="card custom-card">
  <div class="card-body">
    <form method="POST" action="{{ route('reply_servers.update', $reply_server->id) }}" class="row g-3 mt-0 needs-validation" novalidate>
      @csrf
      @method('PUT')
      <div class="col-md-6">
        <label class="form-label">{{__('app.email')}}</label>
        <input type="email" class="form-control" placeholder="{{__('app.email')}}" value="{{ $reply_server->email }}" name="email" required>
      </div>
      <div class="col-md-6">
        <label class="form-label">{{__('app.status')}}</label>
        <select name="is_active" class="form-select form-select-lg">
          <option value="1" {{ $reply_server->is_active ? 'selected' : '' }}>{{ __('app.active')}}</option>
          <option value="0" {{ $reply_server->is_active ? '' : 'selected' }}>{{ __('app.in_active') }}</option>
        </select>
      </div>
      <div class="col-md-6">
        <label class="form-label">{{__('app.method')}}</label>
        <select name="method" class="form-select form-select-lg">
          <option value="imap" {{ $reply_server->method == 'imap' ? 'selected' : '' }}>IMAP</option>
          <option value="pop3" {{ $reply_server->method == 'pop3' ? 'selected' : '' }}>POP3</option>
        </select>
      </div>
      <div class="col-md-6">
        <label class="form-label">{{__('app.host')}}</label>
        <input type="text" class="form-control" placeholder="{{__('app.host')}}" value="{{ $reply_server->host }}" name="host" required>
      </div>
      <div class="col-md-6">
        <label class="form-label">{{__('app.username')}}</label>
        <input type="text" class="form-control" placeholder="{{__('app.username')}}" value="{{ $reply_server->username }}" name="username" required>
      </div>
      <div class="col-md-6 position-relative">
        <label class="form-label">{{__('app.password')}}</label>
        <input id="password" type="password" class="form-control" placeholder="{{__('app.password')}}" name="password" value="{{Crypt::decrypt($reply_server->password)}}">
        <a href="javascript:void(0);" class="show-password-button text-muted" onclick="createpassword('password',this)" id="button-addon2"><i class="ri-eye-off-line align-middle"></i></a>
      </div>
      <div class="col-md-6">
        <label class="form-label">{{__('app.port')}}</label>
        <input type="number" class="form-control" placeholder="{{__('app.port')}}" value="{{ $reply_server->port }}" name="port" required min="0">
      </div>
      <div class="col-md-6">
        <label class="form-label">{{__('app.encryption')}}</label>
        <select name="encryption" class="form-select form-select-lg">
          <option value="none" {{ $reply_server->encryption == 'none' ? 'selected' : '' }}>None</option>
          <option value="ssl" {{ $reply_server->encryption == 'ssl' ? 'selected' : '' }}>SSL</option>
          <option value="tls" {{ $reply_server->encryption == 'tls' ? 'selected' : '' }}>TLS</option>
        </select>
      </div>
      <div class="col-md-6">
        <label class="form-label">{{__('app.validate_cert')}}</label>
        <select name="validate_cert" class="form-select form-select-lg">
          <option value="Yes" {{ $reply_server->validate_cert == 'Yes' ? 'selected' : '' }}>{{ __('app.yes') }}</option>
          <option value="No" {{ $reply_server->validate_cert == 'No' ? 'selected' : '' }}>{{ __('app.no') }}</option>
        </select>
      </div>
      <div class="col-md-6">
        <label class="form-label">{{__('app.delete_after_processing')}}
        <a tabindex="-1" role="button"
          data-bs-toggle="popover" data-bs-trigger="focus" data-bs-placement="right" title="{{__('app.delete_after_processing')}}"
          data-bs-content="{{__('app.delete_after_processing_help')}}" data-bs-custom-class="header-primary"><i class="bi bi-question-square text-primary"></i>
          </a>
        </label>
        <select name="delete_after_processing" class="form-select form-select-lg">
          <option value="No" {{ $reply_server->delete_after_processing == 'No' ? 'selected' : '' }}>{{ __('app.no') }}</option>
          <option value="Yes" {{ $reply_server->delete_after_processing == 'Yes' ? 'selected' : '' }}>{{ __('app.yes') }}</option>
        </select>
      </div>
      <div class="col-12">
        <input type="hidden" name="id" value="{{$reply_server->id}}">
        <button type="submit" class="btn btn-primary btn-loading"><i class=""></i> {{__('app.update')}}</button>
        <a href="{{route('reply_servers.index')}}">
        <button type="button" class="btn btn-danger btn-loading"><i class=""></i> {{__('app.exit')}}</button></a>
        <button type="button" id="validate-imap" onclick="validateImap(this.form, '{{route('validateReplyServerImap')}}')" class="btn btn-info btn-loading"><i class=""></i> {{__('app.validate')}}</button>
        <span id="imap-msg" class="mx-3"></span>
      </div>
    </form>
  </div>
</div>
@endsection