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

@section('styles')
<style type="text/css">
  #group_id + .select2-container {
    z-index: 0 !important;
  }
</style>
@endsection

@push('scripts')
<script src="{{asset('components/ckeditor/ckeditor.js')}}"></script>
<script src="{{asset('components/ckeditor/plugins/mc_uploader/plugin.js')}}"></script>
<script src="{{asset('assets/js/campaign.js')}}"></script>
@endpush


@section('content')
<div class="card custom-card">
   <div class="card-body">
      <form method="POST" action="{{ route('drips.update', $drip->id) }}" class="row g-3 mt-0 needs-validation" novalidate>
         @csrf       
         @method('PUT')
         <div class="col-md-6">
           <label class="form-label">{{__('app.drip_group')}}
             <a href="javascript:;" onclick="viewModal('modal', '{{route('group.create', ['type_id' => config('custom.group_drips')])}}');">
               <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.drip_group')}}"
            data-bs-content="{{__('app.drip_group_help')}}" data-bs-custom-class="header-primary">   <i class="bi bi-question-square text-primary"></i>
            </a>
           </label>
           <select name="group_id" class="single-select form-select" id="group_id" required>
             <option value="">{{__('app.select_drip_group')}}</option>
             @foreach($groups as $id => $group_name)
                <option value="{{ $id }}" {{ $drip->group_id == $id ? 'selected' : '' }}>{{$group_name}}</option>
             @endforeach
           </select>
           <div class="invalid-feedback">{{ __('app.select_group_error')}}</div>
         </div>
         <div class="col-md-6">
            <label class="form-label">{{__('app.active')}}</label>
            <select name="is_active" class="form-select form-select-lg">
               <option value="1" {{ $drip->is_active ? 'selected' : '' }}>{{ __('app.yes') }}</option>
               <option value="0" {{ $drip->is_active ? '' : 'selected' }}>{{ __('app.no')}}</option>
            </select>
         </div>
         <div class="col-md-12 mt-3">
            <label class="form-label">{{__('app.name')}}</label>
            <input type="name" class="form-control" placeholder="{{__('app.name')}}" value="{{ $drip->name ?? '' }}" name="name" required>
         </div>
         <div class="col-md-12 mt-3">
           <label class="col-md-2 form-label">{{ __('app.send') }} 
           <a tabindex="-1" role="button"
            data-bs-toggle="popover" data-bs-trigger="focus" data-bs-placement="right" title="{{__('app.send')}}"
            data-bs-content="{{__('app.drip_sending_speed_help')}}" data-bs-custom-class="header-primary">   <i class="bi bi-question-square text-primary"></i>
            </a></label>
           <select name="send" id="send" class="form-select form-select-lg">
             <option value="Instant" {{ $drip->send == 'Instant' ? 'selected' : '' }}>{{ __('app.drip_instant') }}</option>
             <option value="After" {{ $drip->send == 'After' ? 'selected' : '' }}>{{ __('app.drip_after') }}</option>
           </select>
         </div>
         <div class="col-md-12" id="send-datetime" style="{{ $drip->send == 'After' ? '' : 'display: none;' }}">
         <div class="row">
            <div class="col-md-6 mt-3" >
               <input type="number" min="0" class="form-control" name="time" value="{{ json_decode($drip->send_attributes)->time }}" placeholder="">
            </div>
            <div class="col-md-6 mt-3" >
                <select name="duration" id="duration" class="form-select form-select-lg" >
                  <option value="minutes" {{ json_decode($drip->send_attributes)->duration == 'minutes' ? 'selected="selected"' : '' }}>{{ __('app.minutes') }}</option>
                  <option value="hours" {{ json_decode($drip->send_attributes)->duration == 'hours' ? 'selected="selected"' : '' }}>{{ __('app.hours') }}</option>
                  <option value="days" {{ json_decode($drip->send_attributes)->duration == 'days' ? 'selected="selected"' : '' }}>{{ __('app.days') }}</option>
                </select>
            </div>
          </div>
         </div>
         <div class="col-md-12">
              <label class="form-label">{{__('app.subject')}}</label>
              <a tabindex="-1" role="button"
              data-bs-toggle="popover" data-bs-trigger="focus" data-bs-placement="right" title="{{__('app.subject')}}"
              data-bs-content="{{__('app.subject_help')}}" data-bs-custom-class="header-primary"><i class="bi bi-question-square text-primary"></i>
            </a>
            <input type="text" class="form-control" placeholder="{{__('app.subject')}}" value="{{ $drip->email_subject ?? '' }}" name="email_subject" id="email_subject" required>
            </div>

            <div class="col-md-12 mt-3">
              <label class="form-label">{{__('app.content')}} <span class="ps-5"></span></label>
              <button type="button" class="btn btn-outline-primary btn-sm" onclick="viewModal('modal', '{{ route('shortcodes') }}');" tabindex="-1">{{ __('app.shortcodes') }}</button><span class="ps-1"></span>
              <button type="button" class="btn btn-outline-primary btn-sm" onclick="viewModal('modal', '{{ route('broadcasts.all') }}');" tabindex="-1">{{__('app.import_campaign')}}</button><span class="ps-1"></span>
              <button type="button" class="btn btn-outline-primary btn-sm" onclick="viewModal('modal', '{{ route('templates.all') }}');" tabindex="-1">{{__('app.import_template')}}</button> 
              <textarea class="form-control" id="content_html" name="content" rows="10">{{ $drip->content ?? '' }}</textarea>
            </div>

         <div class="col-12">
            <button type="submit" name="submit"  class="btn btn-primary btn-loading"><i class=""></i> {{__('app.update')}}</button>     
            <a href="{{route('drips.index')}}">
             <button type="button" class="btn btn-danger btn-loading"><i class=""></i> {{__('app.exit')}}</button>
           </a>
         </div>
      </form>
   </div>
</div>
@endsection