@extends('layouts.app')

@section('content')
    <section class="page-header row">
        <h2> Store Contents </h2>
        <ol class="breadcrumb">
            <li><a href="{{ url('') }}"> Dashboard </a></li>
            <li><a href="{{ url('/manage/store_contents') }}"> Store Contents </a></li>
            <li class="active"> Form </li>
        </ol>
    </section>

    <div class="page-content row">
        <div class="page-content-wrapper no-margin">
            {!! Form::open(array('url' => '/manage/store_contents', 'class' => 'form-horizontal validated', 'files' => true)) !!}

            <div class="sbox-title clearfix">
                <div class="sbox-tools pull-right">
                    <a href="{{ url('/manage/store_contents') }}" class="tips btn btn-sm" title="{{ __('core.btn_back') }}"><i class="fa  fa-times"></i></a>
                </div>
                <div class="sbox-tools1 pull-left1">
                    <button name="apply" class="btn btn-sm btn-primary" title="{{ __('core.btn_back') }}"><i class="fa fa-check"></i> {{ __('core.sb_apply') }} </button>
                    <button name="save" class="btn btn-sm btn-success" title="{{ __('core.btn_back') }}"><i class="fa fa-paste"></i> {{ __('core.sb_save') }} </button>
                </div>
            </div>

            <div class="sbox1">
                <div class="sbox-content clearfix row">
                    <div class="col-xs-12">
                        <ul class="parsley-error-list">
                            @foreach($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>

                        <?php $curTime = time();?>

                        <div class="sbox1">
                            <div class="col-md-12">
                                <fieldset class="sbox" style="border-top:0; border-radius: 5px;">
                                    <legend> Store Content </legend>
                                    <?php if (!isset($row['id'])) $row['id'] = null; ?>
                                    <input type='hidden' name='id' id='id' value='{{$row['id']}}'/>

                                    <div class="form-group col-md-6 depen- wrap-store_id">
                                        <label for="store_id" class="control-label col-md-3 text-left"> Store
                                            <span class="asterix text-danger"> * </span>
                                        </label>

                                        <div class="col-md-9">
                                            <?php if (!isset($row['store_id'])) $row['store_id'] = null; ?>
                                            <select name='store_id' id='store_id' class='select2'
                                                    data-placeholder='Select Store' placeholder='Select Store'
                                                    required>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-region_code">
                                        <label for="region_code" class="control-label col-md-3 text-left"> Region
                                            <span class="asterix text-danger"> * </span>
                                        </label>

                                        <div class="col-md-9">
                                            <?php if (!isset($row['region_code'])) $row['region_code'] = null; ?>
                                            <select name='region_code' id='region_code' class='select2'
                                                    data-placeholder='Select Region' placeholder='Select Region'
                                                    required>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-12 depen- wrap-name">
                                        <div class="col-md-6">
                                            <label for="name" class="control-label"> Name </label>

                                            <?php if( !isset($row['name']))  $row['name'] = null; ?>
                                            <?php $val = is_array($row['name']) ? (object) $row['name'] : json_decode($row['name']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a  href='#name_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='name_{{$ilang}}_{{$curTime}}'>
                                                        <input type='text' name="name[{{$ilang}}]" id='name'
                                                               value='{{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}'
                                                               placeholder='Name - {{$ilang}}' class='form-control input-sm'/>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-about_store">
                                        <div class="col-md-12">
                                            <label for="about_store" class="control-label"> About Store </label>
                                            <?php if (!isset($row['about_store'])) $row['about_store'] = null; ?>
                                            <?php $val = is_array($row['about_store']) ? (object)$row['about_store'] : json_decode($row['about_store']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a href='#about_store_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='about_store_{{$ilang}}_{{$curTime}}'>
                                                    <textarea name="about_store[{{$ilang}}]" rows='5' id='about_store' class='form-control editor input-sm '>
                                                        {{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}
                                                    </textarea>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-cb_terms">
                                        <div class="col-md-12">
                                            <label for="cb_terms" class="control-label"> Cashback Terms </label>
                                            <?php if(!isset($row['cb_terms']))  $row['cb_terms'] = null; ?>
                                            <?php $val = is_array($row['cb_terms']) ? (object) $row['cb_terms'] : json_decode($row['cb_terms']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#cb_terms_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
                                                <?php $is_first = false;?>
                                                @endforeach </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='cb_terms_{{$ilang}}_{{$curTime}}'>
                                                    <textarea name="cb_terms[{{$ilang}}]" rows='5' id='cb_terms'   class='form-control editor input-sm '>
                                                        {{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}
                                                    </textarea>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-more_about_store_title">
                                        <div class="col-md-12">
                                            <label for="more_about_store_title" class="control-label"> More About Store Title </label>

                                            <?php if( !isset($row['more_about_store_title']))  $row['more_about_store_title'] = null;   ?>
                                            <?php $val = is_array($row['more_about_store_title']) ? (object) $row['more_about_store_title'] : json_decode($row['more_about_store_title']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#more_about_store_title_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
                                                <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='more_about_store_title_{{$ilang}}_{{$curTime}}'>
                                                        <input type='text' name="more_about_store_title[{{$ilang}}]" id='more_about_store_title'
                                                               value='{{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}'
                                                               placeholder='More About Store Title - {{$ilang}}' class='form-control input-sm'/>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-sp_terms_title" >
                                        <div class="col-md-12">
                                            <label for="sp_terms_title" class="control-label"> Special Term Title </label>

                                            <?php if( !isset($row['sp_terms_title']))  $row['sp_terms_title'] = null;   ?>
                                            <?php $val = is_array($row['sp_terms_title']) ? (object) $row['sp_terms_title'] : json_decode($row['sp_terms_title']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a  href='#sp_terms_title_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='sp_terms_title_{{$ilang}}_{{$curTime}}'>
                                                        <input type='text' name="sp_terms_title[{{$ilang}}]" id='sp_terms_title'
                                                               value='{{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}'
                                                               placeholder='Special Term Title - {{$ilang}}' class='form-control input-sm'/>
                                                    </div>
                                                    <?php  $is_first = false;?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-more_about_store">
                                        <div class="col-md-12">
                                            <label for="more_about_store" class="control-label"> More About Store </label>

                                            <?php if( !isset($row['more_about_store']))  $row['more_about_store'] = null;   ?>
                                            <?php $val = is_array($row['more_about_store']) ? (object) $row['more_about_store'] : json_decode($row['more_about_store']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a href='#more_about_store_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='more_about_store_{{$ilang}}_{{$curTime}}'>
                                                    <textarea name="more_about_store[{{$ilang}}]" rows='5' id='more_about_store'   class='form-control editor input-sm '>
                                                        {{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}
                                                    </textarea>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-sp_terms">
                                        <div class="col-md-12">
                                            <label for="sp_terms" class="control-label"> Special Term Description </label>

                                            <?php if( !isset($row['sp_terms']))  $row['sp_terms'] = null; ?>
                                            <?php $val = is_array($row['sp_terms']) ? (object) $row['sp_terms'] : json_decode($row['sp_terms']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a href='#sp_terms_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php  $is_first = false;?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='sp_terms_{{$ilang}}_{{$curTime}}'>
                                                    <textarea name="sp_terms[{{$ilang}}]" rows='5' id='sp_terms' class='form-control editor input-sm'>
                                                        {{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}
                                                    </textarea>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-h1_tag">
                                        <div class="col-md-12">
                                            <label for="h1_tag" class="control-label"> H1 Tag </label>

                                            <?php if( !isset($row['h1_tag']))  $row['h1_tag'] = null;   ?>
                                            <?php $val = is_array($row['h1_tag']) ? (object) $row['h1_tag'] : json_decode($row['h1_tag']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a  href='#h1_tag_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content ">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='h1_tag_{{$ilang}}_{{$curTime}}'>
                                                        <input type='text' name="h1_tag[{{$ilang}}]" id='h1_tag'
                                                               value='{{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}'
                                                               placeholder='H1 Tag - {{$ilang}}' class='form-control input-sm'/>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-h2_tag">
                                        <div class="col-md-12">
                                            <label for="h2_tag" class="control-label"> H2 Tag </label>

                                            <?php if( !isset($row['h2_tag']))  $row['h2_tag'] = null; ?>
                                            <?php $val = is_array($row['h2_tag']) ? (object) $row['h2_tag'] : json_decode($row['h2_tag']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a href='#h2_tag_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='h2_tag_{{$ilang}}_{{$curTime}}'>
                                                        <input type='text' name="h2_tag[{{$ilang}}]" id='h2_tag'
                                                               value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}'
                                                               placeholder='H2 Tag - {{$ilang}}' class='form-control input-sm'/>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-meta_title">
                                        <div class="col-md-12">
                                            <label for="meta_title" class="control-label"> Meta Title </label>

                                            <?php if( !isset($row['meta_title']))  $row['meta_title'] = null; ?>
                                            <?php $val = is_array($row['meta_title']) ? (object) $row['meta_title'] : json_decode($row['meta_title']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a href='#meta_title_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php $is_first = false; ?>
                                                @endforeach </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='meta_title_{{$ilang}}_{{$curTime}}'>
                                                        <input type='text' name="meta_title[{{$ilang}}]" id='meta_title'
                                                               value='{{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}'
                                                               placeholder='Meta Title - {{$ilang}}' class='form-control input-sm'/>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-meta_kw">
                                        <div class="col-md-12">
                                            <label for="meta_kw" class=" control-label "> Meta Keywords </label>

                                            <?php if( !isset($row['meta_kw']))  $row['meta_kw'] = null; ?>
                                            <?php $val = is_array($row['meta_kw']) ? (object) $row['meta_kw'] : json_decode($row['meta_kw']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a  href='#meta_kw_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='meta_kw_{{$ilang}}_{{$curTime}}'>
                                                        <input type='text' name="meta_kw[{{$ilang}}]" id='meta_kw'
                                                               value='{{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}'
                                                               placeholder='Meta Keywords - {{$ilang}}' class='form-control input-sm'/>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-secrets">
                                        <div class="col-md-12">
                                            <label for="secrets" class="control-label"> Cashback Secrets </label>

                                            <?php if( !isset($row['secrets'])) $row['secrets'] = null; ?>
                                            <?php $val = is_array($row['secrets']) ? (object) $row['secrets'] : json_decode($row['secrets']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a  href='#secrets_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang)
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='secrets_{{$ilang}}_{{$curTime}}'>
                                                        <textarea name="secrets[{{$ilang}}]" rows='5' id='secrets' class='form-control editor input-sm '>
                                                            {{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}
                                                        </textarea>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-6 depen- wrap-meta_desc">
                                        <div class="col-md-12">
                                            <label for="meta_desc" class="control-label"> Meta Description </label>

                                            <?php if( !isset($row['meta_desc']))  $row['meta_desc'] = null;   ?>
                                            <?php $val = is_array($row['meta_desc']) ? (object) $row['meta_desc'] : json_decode($row['meta_desc']); $is_first = true; ?>
                                            <ul class='editor-nav nav nav-tabs'>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <li class='{{$is_first ? "active" : null}} '>
                                                        <a  href='#meta_desc_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a>
                                                    </li>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </ul>

                                            <div class="tab-content">
                                                <?php $is_first = true; ?>
                                                @foreach(explode(',', config('website.cnf_langs')) as $ilang )
                                                    <div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='meta_desc_{{$ilang}}_{{$curTime}}'>
                                                    <textarea name="meta_desc[{{$ilang}}]" rows='5' id='meta_desc' class='form-control input-sm '>
                                                        {{ isset($val->{$ilang}) ? $val->{$ilang} : '' }}
                                                    </textarea>
                                                    </div>
                                                    <?php $is_first = false; ?>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="sbox-title clearfix">
                <div class="sbox-tools pull-right">
                    <a href="{{ url('/manage/store_contents') }}" class="tips btn btn-sm" title="{{ __('core.btn_back') }}">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
                <div class="sbox-tools pull-left">
                    <button name="apply" class="btn btn-sm btn-primary" title="{{ __('core.btn_back') }}"><i class="fa fa-check"></i> {{ __('core.sb_apply') }} </button>
                    <button name="save" class="btn btn-sm btn-success" title="{{ __('core.btn_back') }}"><i class="fa fa-paste"></i> {{ __('core.sb_save') }} </button>
                </div>
            </div>

            <input type="hidden" name="action_task" value="save"/>
            {!! Form::close() !!}
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            /** Store Select **/
            $("#store_id").select2({
                ajax: {
                    url: "{{url('/manage/store_contents/ajaxselect?filter=stores:id:slug')}}",
                    data: function (params) {
                        return {
                            search: params.term,
                            page: params.page || 1
                        };
                    },
                    dataType: 'json',
                    processResults: function (data) {
                        data.page = data.page || 1;
                        return {
                            results: data.items.map(function (item) {
                                return {
                                    id: item.id,
                                    text: selctToJson(item, 'slug')
                                };
                            }),
                            pagination: {
                                more: data.pagination
                            }
                        }
                    },
                    cache: true,
                    delay: 250
                },
                multiple: 0,
                width: '100%'
            });

            @if(strlen($row["store_id"]) > 0)
            let storeIdSelect = $('#store_id');

            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/store_contents/ajaxselect?filter=stores:id:slug&values=' . urlencode($row["store_id"])) !!}",
            }).then(function (data) {
                data.items.map(function (item) {
                    var option = new Option(selctToJson(item, 'slug'), item.id, true, true);
                    storeIdSelect.append(option).trigger('change');

                });
                storeIdSelect.trigger({
                    type: 'select2:select',
                    params: {
                        data: data
                    }
                });
            });

            storeIdSelect.select2_sortable();
            @endif
            /** *********** **/

            /** Region Select **/
            $("#region_code").select2({
                ajax: {
                    url: "{{url('/manage/store_contents/ajaxselect?filter=regions:code:name')}}",
                    data: function (params) {
                        return {
                            search: params.term,
                            page: params.page || 1
                        };
                    },
                    dataType: 'json',
                    processResults: function (data) {
                        data.page = data.page || 1;
                        return {
                            results: data.items.map(function (item) {
                                return {
                                    id: item.code,
                                    text: selctToJson(item, 'name')
                                };
                            }),
                            pagination: {
                                more: data.pagination
                            }
                        }
                    },
                    cache: true,
                    delay: 250
                },
                multiple: 0,
                width: '100%'
            });

            @if(strlen($row["region_code"]) > 0)
            let regionSelect = $('#region_code');
            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/store_contents/ajaxselect?filter=regions:code:name&values=' . urlencode($row["region_code"])) !!}",
            }).then(function (data) {
                data.items.map(function (item) {
                    var option = new Option(selctToJson(item, 'name'), item.code, true, true);
                    regionSelect.append(option).trigger('change');

                });
                regionSelect.trigger({
                    type: 'select2:select',
                    params: {
                        data: data
                    }
                });
            });

            regionSelect.select2_sortable();
            @endif
            /** *********** **/
        });

    </script>
@endsection