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

                @foreach($languages as $language)
                    <div class="form-group col-lg-6">
                        <label>{{ meta('name', $language->local) ?? __('companies.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) ?? __('companies.name') }}" value='{{ old("name_{$language->local}", $company[$language->local]->name ?? "") }}'/>
                    </div>
                    <div class="form-group col-lg-6">
                        <label>{{ meta('purchasing', $language->local) ?? __('companies.purchasing') }} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
                        <input type="text" class="form-control {{ $errors->has('purchasing_'.$language->local) ? 'is-invalid' : '' }}" name="purchasing_{{ $language->local }}" placeholder="{{ meta('purchasing', $language->local) ?? __('companies.purchasing') }}" value='{{ old("purchasing_{$language->local}", $company[$language->local]->purchasing ?? "") }}'/>
                    </div>
                @endforeach

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


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

            @if($type_certificate_commercial == 'pdf')
                <div class="form-group col-lg-6">
                    <label>{{ meta('certificate_commercial', getCurrentLocale()) ?? __('companies.certificate_commercial') }} </label>
                    <input type="file" class="form-control {{ $errors->has('certificate_commercial') ? 'is-invalid' : '' }}" name="certificate_commercial" placeholder="{{ meta('certificate_commercial', getCurrentLocale()) ?? __('companies.certificate_commercial') }}" value='{{ old("certificate_commercial", $company->certificate_commercial ?? "") }}'/>
                    <a target="_blank" class="butn" href="{{asset($company->certificate_commercial)}}">عرض ملف pdf</a>

                </div>
            
            @else
                <div class="form-group col-lg-6">
                    <label>{{ meta('certificate_commercial', getCurrentLocale()) ?? __('companies.certificate_commercial') }} </label>
                    <input id="image_certificate_commercial_thumbnail" class="image_certificate_commercial_thumbnail" type="hidden" name="certificate_commercial" value="{{old("certificate_commercial", $company->certificate_commercial ?? "")}}"/>
    
                    <div class="photos main_certificate_commercial_photo {{ old('certificate_commercial', $company->certificate_commercial ?? '') ? ' wow fadeInUp' : 'hide' }}">
                        <div class="col-lg-12">
                            <div class="items">
                                <div class="img">
                                    <a href="#" id="lfm" data-input=".image_certificate_commercial_thumbnail" data-preview=".image_certificate_commercial_holder" class="lfm" data-hide=".pick_certificate_commercial_button">
                                        <img src="{{asset(old('certificate_commercial', $company->certificate_commercial ?? ''))}} "  id="image_certificate_commercial_holder" class="image_certificate_commercial_holder"/>
                                    </a>
                                </div>
                                <a href="#" class="showHide resetImage close" data-empty=".image_certificate_commercial_thumbnail" data-hide=".main_certificate_commercial_photo" data-show=".pick_certificate_commercial_button"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    </div>
    
                    <div class="clearfix"></div>
                    <span class="input-group-btn pick_certificate_commercial_button {{ old('certificate_commercial', $company->certificate_commercial ?? '') ? 'hide' : '' }} ">
                        <a id="lfm" data-input=".image_certificate_commercial_thumbnail" data-preview=".image_certificate_commercial_holder" data-show=".main_certificate_commercial_photo" data-hide=".pick_certificate_commercial_button" class="lfm btn btn-primary text-light">
                            <i class="fas fa-camera-retro"></i> Choose
                        </a>
                    </span>
                </div>
            @endif
            @if($type_tax_certificate == 'pdf')
                <div class="form-group col-lg-6">
                    <label>{{ meta('tax_certificate', getCurrentLocale()) ?? __('companies.tax_certificate') }} </label>
                    <input type="file" class="form-control {{ $errors->has('tax_certificate') ? 'is-invalid' : '' }}" name="tax_certificate" placeholder="{{ meta('tax_certificate', getCurrentLocale()) ?? __('companies.tax_certificate') }}" value='{{ old("tax_certificate", $company->tax_certificate ?? "") }}'/>
                    <a target="_blank" class="butn" href="{{asset($company->tax_certificate)}}">عرض ملف pdf</a>
                </div>
            @else
                <div class="form-group col-lg-6">
                    <label>{{ meta('tax_certificate', getCurrentLocale()) ?? __('companies.tax_certificate') }} </label>
                    <input id="image_tax_certificate_thumbnail" class="image_tax_certificate_thumbnail" type="hidden" name="tax_certificate" value="{{old("tax_certificate", $company->tax_certificate ?? "")}}"/>

                    <div class="photos main_tax_certificate_photo {{ old('tax_certificate', $company->tax_certificate ?? '') ? ' wow fadeInUp' : 'hide' }}">
                        <div class="col-lg-12">
                            <div class="items">
                                <div class="img">
                                    <a href="#" id="lfm" data-input=".image_tax_certificate_thumbnail" data-preview=".image_tax_certificate_holder" class="lfm" data-hide=".pick_tax_certificate_button">
                                        <img src="{{asset(old('tax_certificate', $company->tax_certificate ?? ''))}} "  id="image_tax_certificate_holder" class="image_tax_certificate_holder"/>
                                    </a>
                                </div>
                                <a href="#" class="showHide resetImage close" data-empty=".image_tax_certificate_thumbnail" data-hide=".main_tax_certificate_photo" data-show=".pick_tax_certificate_button"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <span class="input-group-btn pick_tax_certificate_button {{ old('tax_certificate', $company->tax_certificate ?? '') ? 'hide' : '' }} ">
                    <a id="lfm" data-input=".image_tax_certificate_thumbnail" data-preview=".image_tax_certificate_holder" data-show=".main_tax_certificate_photo" data-hide=".pick_tax_certificate_button" class="lfm btn btn-primary text-light">
                        <i class="fas fa-camera-retro"></i> Choose
                    </a>
                </span>
                </div>
            @endif
                <div class="form-group col-lg-12"><hr></div>

                @if($company ?? ''  && $company->id)
                <div class="form-group col-lg-12">
                    <label>{{ meta('company_exhibition', getCurrentLocale()) ?? __('companies.company_exhibition') }} </label>
                    
                    <div id="img_360_1"></div>
                </div>
                <div class="form-group col-lg-12">
                    <label>{{ meta('company_showroom', getCurrentLocale()) ?? __('companies.company_showroom') }} </label>
                    
                    <div id="img_360"></div>
                </div>
                @else

                <div class="form-group col-lg-6">
                    <label>{{ meta('company_exhibition', getCurrentLocale()) ?? __('companies.company_exhibition') }} </label>
                    <input id="image_company_exhibition_thumbnail" class="image_company_exhibition_thumbnail" type="hidden" name="company_exhibition" value="{{old("company_exhibition", $company->company_exhibition ?? "")}}"/>

                    <div class="photos main_company_exhibition_photo {{ old('company_exhibition', $company->company_exhibition ?? '') ? ' wow fadeInUp' : 'hide' }}">
                        <div class="col-lg-12">
                            <div class="items">
                                <div class="img">
                                    <a href="#" id="lfm" data-input=".image_company_exhibition_thumbnail" data-preview=".image_company_exhibition_holder" class="lfm" data-hide=".pick_company_exhibition_button">
                                        <img src="{{asset(old('company_exhibition', $company->company_exhibition ?? ''))}} "  id="image_company_exhibition_holder" class="image_company_exhibition_holder"/>
                                    </a>
                                </div>
                                <a href="#" class="showHide resetImage close" data-empty=".image_company_exhibition_thumbnail" data-hide=".main_company_exhibition_photo" data-show=".pick_company_exhibition_button"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <span class="input-group-btn pick_company_exhibition_button {{ old('company_exhibition', $company->company_exhibition ?? '') ? 'hide' : '' }} ">
                    <a id="lfm" data-input=".image_company_exhibition_thumbnail" data-preview=".image_company_exhibition_holder" data-show=".main_company_exhibition_photo" data-hide=".pick_company_exhibition_button" class="lfm btn btn-primary text-light">
                        <i class="fas fa-camera-retro"></i> Choose
                    </a>
                </span>
                </div>
                
                <div class="form-group col-lg-6">
                    <label>{{ meta('company_showroom', getCurrentLocale()) ?? __('companies.company_showroom') }} </label>
                    <input id="image_company_showroom_thumbnail" class="image_company_showroom_thumbnail" type="hidden" name="company_showroom" value="{{old("company_showroom", $company->company_showroom ?? "")}}"/>

                    <div class="photos main_company_showroom_photo {{ old('company_showroom', $company->company_showroom ?? '') ? ' wow fadeInUp' : 'hide' }}">
                        <div class="col-lg-12">
                            <div class="items">
                                <div class="img">
                                    <a href="#" id="lfm" data-input=".image_company_showroom_thumbnail" data-preview=".image_company_showroom_holder" class="lfm" data-hide=".pick_company_showroom_button">
                                        <img src="{{asset(old('company_showroom', $company->company_showroom ?? ''))}} "  id="image_company_showroom_holder" class="image_company_showroom_holder"/>
                                    </a>
                                </div>
                                <a href="#" class="showHide resetImage close" data-empty=".image_company_showroom_thumbnail" data-hide=".main_company_showroom_photo" data-show=".pick_company_showroom_button"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <span class="input-group-btn pick_company_showroom_button {{ old('company_showroom', $company->company_showroom ?? '') ? 'hide' : '' }} ">
                    <a id="lfm" data-input=".image_company_showroom_thumbnail" data-preview=".image_company_showroom_holder" data-show=".main_company_showroom_photo" data-hide=".pick_company_showroom_button" class="lfm btn btn-primary text-light">
                        <i class="fas fa-camera-retro"></i> Choose
                    </a>
                </span>
                </div>
                @endif

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

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


                <div class="col-12">
                    <div  class="row pricing-list-item border-item mb-4" style="background-color: white;height:auto">
                        <div class="col-lg-12">
                            <h3> {{__('companies.links')}} </h3>
                            <div class="col-lg-12" style="height:100%;" id="links">
                                @if($company ?? ''  && $company->id)
                                    @foreach($links as $link)
                                        <div class="row pricing-list-item border-item mb-4"  style="background-color: rgba(21,97,203,0.1);height:auto">
                                            <div class="form-group col-lg-6">
                                                <label>{{ __('companies.link') }} </label>
                                                <input type="url" required class="form-control" name="links[]" value="{{$link->link}}" placeholder="{{  __('companies.link') }}" />
                                            </div>
                                            <div class="form-group col-lg-4"></div>
                                            <div class="form-group col-lg-2" style="font-size: 30px;margin-top:35px;">
                                                <i class="fas fa-times-circle" onclick="remove(this)"></i>
                                            </div>
                                        </div>
                                    @endforeach
                                @endif
                            </div>
                        </div>
                        <div class="col-lg-12">
                            <a style="cursor: pointer;" onclick="addlink()" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("companies.addlink")}}</a>
                        </div>
                    </div>
                </div>


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

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


                <div class="border-item photos col-md-12 other_image_container">
                    <div class="row">
                        @if ($company ?? false)
                            @foreach ($company['photos'] as $photo)
                                <div class="col-md-4">
                                    <div class="items">
                                        <div class="img">
                                            <a href="{{ asset($photo->photo ?? '')}}" data-fancybox="gallery"><img src="{{ asset($photo->photo ?? '')}}" alt=""></a>
                                        </div>
                                        <input type="hidden" name="images[]" value="{{ $photo->photo ?? "" }}">
                                        <a href="#" class="close"><i class="fas fa-times"></i></a>
                                    </div>
                                </div>
                            @endforeach
                        @endif
                    </div>
                    <div class="text-center">
                        <input id="other_image_thumbnail" class="other_image_thumbnail" type="hidden"/>
                        <div class="clearfix"></div>
                        <span id="add">
                    <a id="lfm" data-width="" data-cache="article_gallery" data-input=".other_image_thumbnail" data-preview="" data-show="" data-hide="" class="lfm add">
                        Add New Item
                    </a>
                </span>
                    </div>
                </div>
                @if($company ?? ''  && $company->id)
                    @if($company->verification_pdf)
                        <div class="text-center mt-5 col-12">
                            <a href="{{asset($company->verification_pdf)}}" target="_blank" class="butn"><span>عرض ملف التعاقد بعد توقيع العقد</span></a>
                        </div>
                    @endif
                @endif
            <div class="text-center mt-5 col-12">
                <button class="butn"><span>{{ __('dashboard.save') }}</span></button>
            </div>
        </form>
    </div>

@endsection

@section('inner_js')
    <script src="{{ asset('assets/admin/js/three.min.js') }}"></script>
    <script src="{{ asset('assets/admin/js/panolens.min.js') }}"></script>
    <script>
        var panorama, viewer, container, infospot;

@if($company ?? ''  && $company->id)
        container = document.querySelector( '#img_360' );
        panorama = new PANOLENS.ImagePanorama( '{{ asset($company->company_showroom) }}' );
        
        viewer = new PANOLENS.Viewer( { container: container } );
        viewer.add( panorama );
        viewer.OrbitControls.noZoom = true;
        
        container = document.querySelector( '#img_360_1' );
        panorama = new PANOLENS.ImagePanorama( '{{ asset($company->company_exhibition) }}' );
        
        viewer = new PANOLENS.Viewer( { container: container } );
        viewer.add( panorama );
        viewer.OrbitControls.noZoom = true;
@endif
        // infospot = new PANOLENS.Infospot( 350, PANOLENS.DataImage.Info );
        // infospot.position.set( 0, 0, -5000 );
        // infospot.addHoverText( 'Hello Panolens', 30 );
        // panorama.add( infospot );

        
    </script>
    <!-- Editor JS files -->
    <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
    <script>
        function addlink()
        {
            $.ajax({
                url : url_addLink,
                type : 'GET',
                success:function(data)
                {
                    $('#links').append(data);
                }
            })
        }
        function remove(elem){
            $(elem).closest('.row').remove();
        }
    </script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_addLink = "{{url('/')}}/admin/addlink",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
