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

@push('scripts')
<script>
  $(function() {
   'use strict';
    $("#list_ids").change(function () {
      loadListCustomFieldsWebForms($('#list_ids').val(), 'dropdown_custom_fields_form');
    });

    $("#is_recaptcha").change(function() {
      $("#div_recaptcha_site_key").slideToggle('slow');
    });
  });

  loadListCustomFieldsWebForms("{{$webform->list_id}}", 'dropdown_custom_fields_form', "{{$webform->custom_field_ids}}");
</script>
@endpush

@php $attributes = json_decode($webform->attributes); @endphp
@section('content')
<div class="card custom-card">
   <div class="card-body">
      <form method="POST" action="{{ route('webforms.update', $webform->id) }}" class="row g-3 mt-0 needs-validation" novalidate>
         @csrf
         @method('PUT')
         <div class="col-md-6">
            <label class="form-label">{{__('app.name')}}</label>
            <input type="text" class="form-control" placeholder="{{__('app.name')}}"
            aria-label="{{__('app.name')}}" value="{{ $webform->name }}"  name="name" required>
         </div>
         <div class="col-md-6">
            <label class="form-label">{{__('app.duplicate')}}
            <a tabindex="-1" role="button"
                data-bs-toggle="popover" data-bs-trigger="focus" data-bs-placement="right" title="{{__('app.duplicate')}}"
                data-bs-content="{{__('app.webform_duplicate_help')}}" data-bs-custom-class="header-primary"><i class="bi bi-question-square text-primary"></i>
              </a>
            </label>
            <select class="form-select form-select-lg" name="duplicates">
               <option value="Skip" {{ $webform->duplicates == 'Skip' ? 'selected' : '' }}>{{__('app.skip')}}</option>
               <option value="Overwrite" {{ $webform->duplicates == 'Overwrite' ? 'selected' : '' }}>{{__('app.overwrite')}}</option>
            </select>
         </div>
         <div class="col-md-12">
            <label class="form-label">{{__('app.list')}}
               <a href="{{ route('lists.create') }}">
                  <i class="bi bi-plus-circle text-primary"></i>
               </a>
               <a tabindex="-1" role="button"
                data-bs-toggle="popover" data-bs-trigger="focus" data-bs-placement="right" title="{{__('app.lists')}}"
                data-bs-content="{{__('app.list_webform_help')}}" data-bs-custom-class="header-primary"><i class="bi bi-question-square text-primary"></i>
              </a>
            </label>
            @php $list_id = $webform->list_id @endphp
            @include('includes.dropdown_lists', ['popup' => 0, 'multiselect' => 0, 'required' => 1, 'client_package_lists' => 0])
         </div>
         <div class="col-md-12">
            <label class="form-label">{{__('app.webform_fields')}}
            <a tabindex="-1" role="button"
                data-bs-toggle="popover" data-bs-trigger="focus" data-bs-placement="right" title="{{__('app.webform_fields')}}"
                data-bs-content="{{__('app.list_webform_fields_help')}}" data-bs-custom-class="header-primary"><i class="bi bi-question-square text-primary"></i>
              </a></label>
            <div id="list_custom_fields"><select class="form-select form-select-lg"></select></div>
         </div>
         <div class="col-md-12">
            <label class="form-label">{{__('app.thankyou_page_custom_url')}}
            <a tabindex="-1" role="button"
                data-bs-toggle="popover" data-bs-trigger="focus" data-bs-placement="right" title="{{__('app.thankyou_page_custom_url')}}"
                data-bs-content="{{__('app.webfrom_thankyou_page_url_help')}}" data-bs-custom-class="header-primary"><i class="bi bi-question-square text-primary"></i>
              </a></label>
            <input type="text" class="form-control" placeholder="{{__('app.thankyou_page_custom_url_help')}}"
            aria-label="{{__('app.thankyou_page_custom_url_help')}}" value="{{$attributes->thankyou_page_custom_url ?? ''}}"  name="thankyou_page_custom_url" required>
         </div>
         <div class="col-md-12">
            <label class="form-label">{{__('app.google_recaptcha')}}
            <a tabindex="-1" role="button"
                data-bs-toggle="popover" data-bs-trigger="focus" data-bs-placement="right" title="{{__('app.google_recaptcha')}}"
                data-bs-content="{{__('app.google_recaptcha_help')}}" data-bs-custom-class="header-primary"><i class="bi bi-question-square text-primary"></i>
              </a>
            </label>
            <select class="form-select form-select-lg" name="is_recaptcha" id="is_recaptcha">
               <option value="0" {{ $webform->is_recaptcha ? '' : 'selected' }}>{{__('app.no')}}</option>
               <option value="1" {{ $webform->is_recaptcha ? 'selected' : '' }}>{{__('app.yes')}}</option>
            </select>
         </div>
         <div class="col-md-12" id="div_recaptcha_site_key" style="{{ $webform->is_recaptcha ? '' : 'display: none;' }}">
            <label class="form-label">{{__('app.recaptcha_site_key')}}</label>
            <input type="text" class="form-control" placeholder="{{__('app.recaptcha_site_key')}}"
            aria-label="{{__('app.recaptcha_site_key')}}" value="{{ $webform->recaptcha_site_key ?? '' }}"  name="recaptcha_site_key">
         </div>
         

         <div class="col-12">
            <button type="submit" class="btn btn-primary btn-loading"><i class=""></i> {{__('app.edit')}}</button>
            <button type="button" class="btn btn-info"onclick="viewModal('modal', '{{route('webforms.show', [$webform->id, 'get_html' => 1])}}');"><i class=""></i> {{__('app.webform_get_html')}}</button>
            <a href="{{route('users.index')}}">
             <button type="button" class="btn btn-danger btn-loading"><i class=""></i> {{__('app.exit')}}</button>
           </a>
         </div>
      </form>
   </div>
</div>
@endsection
