@extends('admin.layouts.container')

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

    <div class="border-item">
        <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}" enctype="multipart/form-data">
            @if($seller ?? ''  && $seller->id)
                @method('PUT')
            @endif
            @csrf

            <div class="form-group col-lg-6">
                <label>{{ __('sellers.user_id') }} </label>
                <select id="user_id" class="form-control {{ $errors->has('user_id') ? 'is-invalid' : '' }}" name="user_id">
                    <option value="">{{__('sellers.select')}}</option>
                    @foreach($users as $row)
                        <option {{isset($seller) ? ($seller->user_id == $row->id ? 'selected' : '') : ''}} value="{{$row->id}}">{{$row->name}}</option>
                    @endforeach
                </select>
            </div>

                <div class="form-group col-lg-6">
                    <label>{{ meta('code', getCurrentLocale()) ?? __('coupons.code')}}</label>
                    <input type="text"  class="form-control  {{ $errors->has('code') ? 'is-invalid' : '' }}" name="code" placeholder="{{ meta('code', getCurrentLocale()) ?? __('coupons.code') }}" value='{{ old("code", $coupon->code ?? "") }}'/>
                </div>

                <div class="form-group col-lg-6">
                    <label>{{ __('coupons.status_discount') }} </label>
                    <select id="status_discount" class="form-control {{ $errors->has('status_discount') ? 'is-invalid' : '' }}" name="status_discount">
                        @foreach($discount_statuses as $row)
                            <option {{isset($coupon) ? ($coupon->status_discount == $row ? 'selected' : '') : ''}} value="{{$row}}">{{__('coupons.status_discountes.'.$row)}}</option>
                        @endforeach
                    </select>
                </div>

                <div class="form-group col-lg-6" >
                    <label>{{ __('coupons.discount') }} </label>
                    <input type="number" class="form-control {{ $errors->has('discount') ? 'is-invalid' : '' }}" name="discount" placeholder="{{ __('coupons.discount') }}" value='{{ old("discount", $coupon->discount ?? "") }}'/>
                </div>

                <div class="form-group col-lg-6" >
                    <label>{{ __('coupons.user_count') }} </label>
                    <input type="number" class="form-control {{ $errors->has('user_count') ? 'is-invalid' : '' }}" name="user_count" placeholder="{{ __('coupons.user_count') }}" value='{{ old("user_count", $coupon->user_count ?? "") }}'/>
                </div>

                <div class="form-group col-lg-6" >
                    <label>{{ __('coupons.count') }} </label>
                    <input type="number" class="form-control {{ $errors->has('count') ? 'is-invalid' : '' }}" name="count" placeholder="{{ __('coupons.count') }}" value='{{ old("count", $coupon->count ?? "") }}'/>
                </div>

                <div class="form-group col-lg-6" >
                    <label>{{ __('coupons.start_date') }} </label>
                    <input type="date" class="form-control {{ $errors->has('start_date') ? 'is-invalid' : '' }}" name="start_date" placeholder="{{ __('coupons.start_date') }}" value='{{ old("start_date", $coupon->start_date ?? "") }}' />
                </div>

                <div class="form-group col-lg-6" >
                    <label>{{ __('coupons.end_date') }} </label>
                    <input type="date" class="form-control {{ $errors->has('end_date') ? 'is-invalid' : '' }}" name="end_date" placeholder="{{ __('coupons.end_date') }}" value='{{ old("end_date", $coupon->end_date ?? "") }}' />
                </div>

                @foreach($languages as $language)

                    <div class="form-group col-lg-6">
                        <label>{{ meta('title', $language->local) ?? __('coupons.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) ?? __('coupons.title') }}" value='{{ old("title_{$language->local}", $coupon[$language->local]->title ?? "") }}'/>
                    </div>
                @endforeach

            <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 orders -->
    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            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>
@endsection



