@extends('store.layouts.container')

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



<div class="border-item">
    <ul class="nav nav-pills bg-nav-pills nav-justified mb-3">
        <li class="nav-item">
            <a href="#main" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0 active">
                <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                <span class="d-none d-lg-block">{{__('stores.details')}}</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="#section_images" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                <span class="d-none d-lg-block">{{__('stores.images')}}</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="#section_payment" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                <span class="d-none d-lg-block">{{__('stores.payment')}}</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="#section_work" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                <span class="d-none d-lg-block">{{__('stores.work_days')}}</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="#section_integration" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                <span class="d-none d-lg-block">{{__('stores.integration')}}</span>
            </a>
        </li>

    </ul>
    <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}" enctype="multipart/form-data">
        @csrf

        <div class="tab-content row col-12">
            <div class="tab-pane col-lg-12 active" id="main">
                <div class="form-row">


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

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


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

                    <div class="form-group col-lg-6">
                        <label>{{ meta('status_active', getCurrentLocale()) ?? __('stores.status_active') }} </label>
                        <select id="status_active" class="form-control {{ $errors->has('status_active') ? 'is-invalid' : '' }}" name="status_active" >
                            @foreach($statuses_active as $row)
                                <option @if((isset($store) ? $store->status_active : "") == $row ) selected @endif value="{{$row}}">{{__('stores.statuses_active.'.$row)}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>{{ __('stores.category_id') }} </label>
                        <select onchange="categorySelect(this)" id="category_id" class="form-control {{ $errors->has('category_id') ? 'is-invalid' : '' }}" name="category_id">
                            <option value="">{{__('dashboard.select')}}</option>
                            @foreach($categories as $row)
                                <option {{ (isset($store) ? $store->category_id : null) == $row->id ? 'selected' : '' }} value="{{$row->id}}">{{$row->title}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>{{ __('stores.sub_category_id') }} </label>
                        <select id="sub_category_id" class="form-control {{ $errors->has('sub_category_id') ? 'is-invalid' : '' }}" name="sub_category_id">
                            <option value="">{{__('dashboard.select')}}</option>
                            @if(isset($sub_categories))
                                @foreach($sub_categories as $row)
                                    <option {{ (isset($store) ? $store->sub_category_id : null) == $row->id ? 'selected' : '' }} value="{{$row->id}}">{{$row->title}}</option>
                                @endforeach
                            @endif
                        </select>
                    </div>

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

                </div>

            </div>
            <div class="tab-pane col-lg-12" id="section_images">
                <div class="row">
                    <div class="col-lg-12">
                        <h3> {{__('stores.images')}} </h3>
                    </div>

                    <div class="form-group col-lg-6">
                        <label>{{ meta('logo', getCurrentLocale()) ?? __('stores.logo') }} </label>
                        <input type="file" class="form-control {{ $errors->has('logo') ? 'is-invalid' : '' }}" name="logo" placeholder="{{ meta('logo', getCurrentLocale()) ?? __('stores.logo') }}" value='{{ old("logo", $store->logo ?? "") }}'/>
                    </div>
                    <div class="form-group col-lg-6" >
                        <a href="{{asset($store->logo)}}" target="_blank">{{__('stores.show')}}</a>
                    </div>

                    <div class="form-group col-lg-6">
                        <label>{{ meta('header', getCurrentLocale()) ?? __('stores.header') }} </label>
                        <input type="file" class="form-control {{ $errors->has('header') ? 'is-invalid' : '' }}" name="header" placeholder="{{ meta('header', getCurrentLocale()) ?? __('stores.header') }}" value='{{ old("header", $store->header ?? "") }}'/>
                    </div>
                    <div class="form-group col-lg-6" >
                        <a href="{{asset($store->header)}}" target="_blank">{{__('stores.show')}}</a>
                    </div>



                </div>
            </div>
            <div class="tab-pane col-lg-12" id="section_work">
                <div class="row">
                    <div class="col-lg-12">
                        <h3> {{__('stores.work_days')}} </h3>
                    </div>
                    @foreach($days as $row)
                        <div class="col-lg-12">
                            <h4>{{ __('stores.days.'.$row) }}</h4>
                        </div>
                        <div class="form-group col-lg-6">
                            <label>{{ __('stores.start_time') }} </label>
                            <input type="time" class="form-control " id="days_{{$row}}_start_time" name="days[{{$row}}][start_time]" placeholder="{{  __('stores.start_time') }}" value='{{ isset($store) ? $store->days($row)->start_time : "" }}'/>
                        </div>
                        <div class="form-group col-lg-6">
                            <label>{{ __('stores.end_time') }} </label>
                            <input type="time" class="form-control " id="days_{{$row}}_end_time" name="days[{{$row}}][end_time]" placeholder="{{  __('stores.end_time') }}" value='{{ isset($store) ? $store->days($row)->end_time : "" }}'/>
                        </div>
                        <div class="col-lg-12"><hr></div>
                    @endforeach

                </div>
            </div>
            <div class="tab-pane col-lg-12" id="section_payment">
                <div class="row">
                    <div class="col-lg-12">
                        <h3> {{__('stores.payment')}} </h3>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>{{ meta('bank_account', getCurrentLocale()) ?? __('stores.bank_account') }} </label>
                        <input type="text" class="form-control {{ $errors->has('bank_account') ? 'is-invalid' : '' }}" name="bank_account" placeholder="{{ meta('bank_account', getCurrentLocale()) ?? __('stores.bank_account') }}" value='{{ old("bank_account", $store->bank_account ?? "") }}'/>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>{{ meta('bank_num', getCurrentLocale()) ?? __('stores.bank_num') }} </label>
                        <input type="text" class="form-control {{ $errors->has('bank_num') ? 'is-invalid' : '' }}" name="bank_num" placeholder="{{ meta('bank_num', getCurrentLocale()) ?? __('stores.bank_num') }}" value='{{ old("bank_num", $store->bank_num ?? "") }}'/>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>{{ meta('iban', getCurrentLocale()) ?? __('stores.iban') }} </label>
                        <input type="text" class="form-control {{ $errors->has('iban') ? 'is-invalid' : '' }}" name="iban" placeholder="{{ meta('iban', getCurrentLocale()) ?? __('stores.iban') }}" value='{{ old("iban", $store->iban ?? "") }}'/>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>{{ meta('bank', getCurrentLocale()) ?? __('stores.bank') }} </label>
                        <input type="text" class="form-control {{ $errors->has('bank') ? 'is-invalid' : '' }}" name="bank" placeholder="{{ meta('bank', getCurrentLocale()) ?? __('stores.bank') }}" value='{{ old("bank", $store->bank ?? "") }}'/>
                    </div>

                </div>
            </div>
            <div class="tab-pane col-lg-12" id="section_integration">
                <div class="row">
                    <div class="col-lg-12">
                        <h3> {{__('stores.integration')}} </h3>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>{{ meta('status_account', getCurrentLocale()) ?? __('stores.status_account') }} </label>
                        <select id="status_account" onchange="selectStatus()" class="form-control {{ $errors->has('status_account') ? 'is-invalid' : '' }}" name="status_account" >
                            @foreach($statuses_account as $row)
                                <option @if((isset($store) ? $store->status_account : "") == $row ) selected @endif value="{{$row}}">{{__('stores.statuses_account.'.$row)}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="form-group col-lg-6"></div>

                    <div class="form-group col-lg-6 user_id_front_image" >
                        <label>{{ meta('user_id_front_image', getCurrentLocale()) ?? __('stores.user_id_front_image') }} </label>
                        <input type="file" class="form-control {{ $errors->has('user_id_front_image') ? 'is-invalid' : '' }}" name="user_id_front_image" placeholder="{{ meta('user_id_front_image', getCurrentLocale()) ?? __('stores.user_id_front_image') }}" value='{{ old("user_id_front_image", $store->user_id_front_image ?? "") }}'/>
                    </div>
                    @if($store ?? ''  && $store->id)
                        <div class="form-group col-lg-6 user_id_front_image" >
                            <a href="{{asset($store->user_id_front_image)}}" target="_blank">{{__('stores.show')}}</a>
                        </div>
                    @endif
                    <div class="form-group col-lg-6 user_id_back_image" >
                        <label>{{ meta('user_id_back_image', getCurrentLocale()) ?? __('stores.user_id_back_image') }} </label>
                        <input type="file" class="form-control {{ $errors->has('user_id_back_image') ? 'is-invalid' : '' }}" name="user_id_back_image" placeholder="{{ meta('user_id_back_image', getCurrentLocale()) ?? __('stores.user_id_back_image') }}" value='{{ old("user_id_back_image", $store->user_id_back_image ?? "") }}'/>
                    </div>
                    @if($store ?? ''  && $store->id)
                        <div class="form-group col-lg-6 user_id_back_image" >
                            <a href="{{asset($store->user_id_back_image)}}" target="_blank">{{__('stores.show')}}</a>
                        </div>
                    @endif
                    <div class="form-group col-lg-6 iban_card" >
                        <label>{{ meta('iban_card', getCurrentLocale()) ?? __('stores.iban_card') }} </label>
                        <input type="file" class="form-control {{ $errors->has('iban_card') ? 'is-invalid' : '' }}" name="iban_card" placeholder="{{ meta('iban_card', getCurrentLocale()) ?? __('stores.iban_card') }}" value='{{ old("iban_card", $store->iban_card ?? "") }}'/>
                    </div>
                    @if($store ?? ''  && $store->id)
                        <div class="form-group col-lg-6 iban_card" >
                            <a href="{{asset($store->iban_card)}}" target="_blank">{{__('stores.show')}}</a>
                        </div>
                    @endif
                    <div class="form-group col-lg-6 license_work" >
                        <label>{{ meta('license_work', getCurrentLocale()) ?? __('stores.license_work') }} </label>
                        <input type="file" class="form-control {{ $errors->has('license_work') ? 'is-invalid' : '' }}" name="license_work" placeholder="{{ meta('license_work', getCurrentLocale()) ?? __('stores.license_work') }}" value='{{ old("license_work", $store->license_work ?? "") }}'/>
                    </div>
                    @if($store ?? ''  && $store->id)
                        @if($store->license_work)
                            <div class="form-group col-lg-6 license_work" >
                                <a href="{{asset($store->license_work)}}" target="_blank">{{__('stores.show')}}</a>
                            </div>
                        @endif
                    @endif
                    <div class="form-group col-lg-6 commercial_log">
                        <label>{{ meta('commercial_log', getCurrentLocale()) ?? __('stores.commercial_log') }} </label>
                        <input type="file" class="form-control {{ $errors->has('commercial_log') ? 'is-invalid' : '' }}" name="commercial_log" placeholder="{{ meta('commercial_log', getCurrentLocale()) ?? __('stores.commercial_log') }}" value='{{ old("commercial_log", $store->commercial_log ?? "") }}'/>
                    </div>
                    @if($store ?? ''  && $store->id)
                        @if($store->commercial_log)
                            <div class="form-group col-lg-6 commercial_log" >
                                <a href="{{asset($store->commercial_log)}}" target="_blank">{{__('stores.show')}}</a>
                            </div>
                        @endif
                    @endif
                    <div class="form-group col-lg-6 manager_id" >
                        <label>{{ meta('manager_id', getCurrentLocale()) ?? __('stores.manager_id') }} </label>
                        <input type="file" class="form-control {{ $errors->has('manager_id') ? 'is-invalid' : '' }}" name="manager_id" placeholder="{{ meta('manager_id', getCurrentLocale()) ?? __('stores.manager_id') }}" value='{{ old("manager_id", $store->manager_id ?? "") }}'/>
                    </div>
                    @if($store ?? ''  && $store->id)
                        @if($store->manager_id)
                            <div class="form-group col-lg-6 manager_id" >
                                <a href="{{asset($store->manager_id)}}" target="_blank">{{__('stores.show')}}</a>
                            </div>
                        @endif
                    @endif
                    <div class="form-group col-lg-6 contract_establish">
                        <label>{{ meta('contract_establish', getCurrentLocale()) ?? __('stores.contract_establish') }} </label>
                        <input type="file" class="form-control {{ $errors->has('contract_establish') ? 'is-invalid' : '' }}" name="contract_establish" placeholder="{{ meta('contract_establish', getCurrentLocale()) ?? __('stores.contract_establish') }}" value='{{ old("contract_establish", $store->contract_establish ?? "") }}'/>
                    </div>
                    @if($store ?? ''  && $store->id)
                        @if($store->contract_establish)
                            <div class="form-group col-lg-6 contract_establish" >
                                <a href="{{asset($store->contract_establish)}}" target="_blank">{{__('stores.show')}}</a>
                            </div>
                        @endif
                    @endif
                    <div class="form-group col-lg-6 owner_id">
                        <label>{{ meta('owner_id', getCurrentLocale()) ?? __('stores.owner_id') }} </label>
                        <input type="file" class="form-control {{ $errors->has('owner_id') ? 'is-invalid' : '' }}" name="owner_id" placeholder="{{ meta('owner_id', getCurrentLocale()) ?? __('stores.owner_id') }}" value='{{ old("owner_id", $store->owner_id ?? "") }}'/>
                    </div>
                    @if($store ?? ''  && $store->id)
                        @if($store->owner_id)
                            <div class="form-group col-lg-6 owner_id" >
                                <a href="{{asset($store->owner_id)}}" target="_blank">{{__('stores.show')}}</a>
                            </div>
                        @endif
                    @endif



                </div>
            </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 orders -->
    {{--        <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>--}}
    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>

    <script>
        function DeleteImg(elem)
        {
            $(elem).closest('.col-md-4').remove();
        }
    </script>
    <script>
        function categorySelect(elem)
        {
            let category_id = $(elem).val()
            $.ajax({
                url : url_model,
                type : 'GET',
                data : 'category_id='+category_id,
                success:function(data)
                {
                    $('#sub_category_id').html(data);
                }
            })
        }

        function selectStatus()
        {
            let status = $('#status_account').val()
            $('.user_id_front_image').hide()
            $('.user_id_back_image').hide()
            $('.iban_card').hide()
            $('.license_work').hide()
            $('.commercial_log').hide()
            $('.manager_id').hide()
            $('.contract_establish').hide()
            $('.owner_id').hide()

            if (status == "{{\Modules\Store\Enums\StoreStatusAccountEnum::MEMBER->value}}")
            {
                $('.user_id_front_image').show()
                $('.user_id_back_image').show()
                $('.iban_card').show()
                $('.license_work').show()
            }
            if (status == "{{\Modules\Store\Enums\StoreStatusAccountEnum::FOUNDATION->value}}")
            {
                $('.user_id_front_image').show()
                $('.user_id_back_image').show()
                $('.iban_card').show()
                $('.commercial_log').show()
                $('.manager_id').show()
            }
            if (status == "{{\Modules\Store\Enums\StoreStatusAccountEnum::COMPANY->value}}")
            {
                $('.user_id_front_image').show()
                $('.user_id_back_image').show()
                $('.iban_card').show()
                $('.commercial_log').show()
                $('.manager_id').show()
                $('.contract_establish').show()
                $('.owner_id').show()
            }
        }
        $('#status_account').trigger('change');
    </script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_model = "{{route('admin.model')}}",
            currentLanguage = "{{getCurrentLocale()}}",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection



