@extends('admin.layouts.container')

@section('content')
<div class="side-title">
    <h3>{{ $head ?? ''}}</h3>
</div>

<div class="border-item">
    <form class="form-row" method="post" action="{{ $action }}" enctype="multipart/form-data">
        
        @if($cobon ?? ''  && $cobon->id)
            @method('PUT')
        @endif
        @csrf
<input type="hidden" id="cobon_id" name="cobon_id" value="@if($cobon ?? ''  && $cobon->id){{$cobon->id}}@endif">
       

        @foreach($languages as $language)
        <div class="form-group col-lg-6">
            <label>{{ meta('title', $language->local) ?? __('cobons.title') }} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
            <input type="text" class="form-control {{ $errors->has('title_'.$language->local) ? 'is-invalid' : '' }}" name="title_{{ $language->local }}" placeholder="{{ meta('title', $language->local) ?? __('cobons.title') }}" value='{{ old("title_{$language->local}", $cobon[$language->local]->title ?? "") }}'/>
        </div>

     

        @endforeach
        <div class="form-group col-lg-6">
            <label>{{ meta('discount_type', getCurrentLocale()) ?? __('cobons.discount_type')}}</label>
            <select class="form-control {{ $errors->has('discount_type') ? 'is-invalid' : '' }}" name="discount_type">
                <option @if($cobon ?? ''  && $cobon->id) @if($cobon->discount_type == '1') selected @endif @endif value="1">{{__('cobons.value')}}</option>
                <option @if($cobon ?? ''  && $cobon->id) @if($cobon->discount_type == '2') selected @endif @endif  value="2">{{__('cobons.percentage')}}</option>
            </select>
        </div>
        <div class="form-group col-lg-6">
            <label>{{ meta('discount_amount', getCurrentLocale()) ?? __('cobons.discount_amount')}}</label>
            <input type="number" step="2" class="form-control  {{ $errors->has('discount_amount') ? 'is-invalid' : '' }}" name="discount_amount" placeholder="{{ meta('discount_amount', getCurrentLocale()) ?? __('cobons.discount_amount') }}" value='{{ old("discount_amount", $cobon->discount_amount ?? "") }}'/>
        </div>
        
          <div class="form-group col-lg-6">
            <label>{{ meta('start_date', getCurrentLocale()) ?? __('cobons.start_date')}}</label>
          <input type="text" placeholder="{{ meta('start_date', getCurrentLocale()) ?? __('cobons.start_date') }}" name="start_date" value='{{ old("start_date", $cobon->start_date ?? "") }}' class="date_from form-control {{ $errors->has('start_date') ? 'is-invalid' : '' }}">
        </div>
          <div class="form-group col-lg-6">
            <label>{{ meta('end_date', getCurrentLocale()) ?? __('cobons.end_date')}}</label>
          <input type="text" placeholder="{{ meta('end_date', getCurrentLocale()) ?? __('cobons.end_date') }}" name="end_date" value='{{ old("end_date", $cobon->end_date ?? "") }}' class="date_from form-control {{ $errors->has('end_date') ? 'is-invalid' : '' }}">

        </div>
        <div class="form-group col-lg-12">
            <label>{{ meta('type', getCurrentLocale()) ?? __('cobons.type')}}</label>
            <select class="form-control {{ $errors->has('type') ? 'is-invalid' : '' }}" name="type" id="type">
                <option disabled="" selected="">{{__('cobons.select')}}</option>
                <option @if($cobon ?? ''  && $cobon->id) @if($cobon->type == '1') selected @endif @endif  value="1">{{__('cobons.products')}}</option>
                <option @if($cobon ?? ''  && $cobon->id) @if($cobon->type == '2') selected @endif @endif  value="2">{{__('cobons.categories')}}</option>
            </select>
        </div>

        <div class="form-group col-lg-12" >
            <div class="row" id="data">
                 @if($cobon ?? ''  && $cobon->id)
                @if($cobon->type == '1')

                @foreach($products as $row)
                 <div class="col-lg-3">
            <input type="checkbox" @if(cobonitem($cobon->id,$row->id)) checked @endif name="item_id[]" value="{{$row->id}}"> {{productname($row->id)}}          
        </div>
 @endforeach
                @else

                 @foreach($categories as $row)
                  <div class="col-lg-3">
            <input type="checkbox" name="item_id[]" @if(cobonitem($cobon->id,$row->id)) checked @endif value="{{$row->id}}"> {{categoryname($row->id)}}          
        </div>
 @endforeach
                @endif
                 @endif
            </div>
        </div>
      
        <div class="text-center mt-5 col-12">
            <button class="butn"><span>{{ __('dashboard.save') }}</span></button>
        </div>
    </form>
</div>

@endsection

@section('inner_js')
    <!-- Editor JS files -->
{{--    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>--}}
        <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_type = {!! json_encode(url(getCurrentLocale().'/admin/type/')) !!},
            currentLanguage = "{{getCurrentLocale()}}",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
    <script src="{{ asset('assets/admin/js/articles.js') }}"></script>
    <script src="{{ asset('assets/admin/js/cobons.js') }}"></script>
@endsection



