@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($supplier ?? ''  && $supplier->id)
                @method('PUT')
            @endif
            @csrf

            <div class="form-group col-lg-6">
                <label>{{ __('suppliers.country_id') }} </label>
                <select class="form-control {{ $errors->has('country_id') ? 'is-invalid' : '' }}" name="country_id">
                    <option value="">{{__('dashboard.select')}}</option>
                    @foreach($countries as $row)
                        <option {{ (isset($supplier) ? $supplier->country_id : null) == $row->id ? 'selected' : '' }} value="{{$row->id}}">{{$row->currentDescription->title}}</option>
                    @endforeach
                </select>
            </div>

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


                <div class="form-group col-lg-6">
                    <label>{{ meta('phone', getCurrentLocale()) ?? __('suppliers.phone') }} </label>
                    <input type="number" class="form-control {{ $errors->has('phone') ? 'is-invalid' : '' }}" name="phone" placeholder="{{ meta('phone', getCurrentLocale()) ?? __('suppliers.phone') }}" value='{{ old("phone", $supplier->phone ?? "") }}'/>
                </div>
                <div class="form-group col-lg-6">
                    <label>{{ meta('contract_date', getCurrentLocale()) ?? __('suppliers.contract_date') }} </label>
                    <input type="date" class="form-control {{ $errors->has('contract_date') ? 'is-invalid' : '' }}" name="contract_date" placeholder="{{ meta('contract_date', getCurrentLocale()) ?? __('suppliers.contract_date') }}" value='{{ old("contract_date", $supplier->contract_date ?? "") }}'/>
                </div>
                <div class="form-group col-lg-12">
                    <label>{{ meta('address', getCurrentLocale()) ?? __('suppliers.address') }} </label>
                    <input type="text" class="form-control {{ $errors->has('address') ? 'is-invalid' : '' }}" name="address" placeholder="{{ meta('address', getCurrentLocale()) ?? __('suppliers.address') }}" value='{{ old("address", $supplier->address ?? "") }}'/>
                </div>
            @foreach($languages as $language)

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

                <div class="form-group col-lg-12">
                    <label>{{ meta('note', getCurrentLocale()) ?? __('suppliers.note') }} </label>
                    <textarea type="date" class="form-control {{ $errors->has('note') ? 'is-invalid' : '' }}" name="note" placeholder="{{ meta('note', getCurrentLocale()) ?? __('suppliers.note') }}">{{ old("note", $supplier->note ?? "") }}</textarea>
                </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 orders -->
    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>

    <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



