@extends('layouts.app')

@section('content')
    <section class="page-header row" xmlns="http://www.w3.org/1999/html">
        <h2> {{ $pageTitle }} </h2>
        <ol class="breadcrumb">
            <li><a href="{{ url('') }}"> Dashboard </a></li>
            <li><a href="{{ url('/manage/'.$pageModule) }}"> {{ $pageTitle }} </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/coupons?return='.$return, 'class'=>'form-vertical validated','files' => true )) !!}
            <input type="hidden" name="status_type" value="{{ $pageTitle }}"/>

            <div class="sbox-title clearfix">
                <div class="sbox-tools pull-right">
                    <a href="{{ url('/manage/'.$pageModule.'?return='.$return) }}" 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>
                    <?php if ($frontendSlug != '') {
                        $fsconfig = explode('@', $frontendSlug);
                        if (($row[$fsconfig[1]]))
                            echo '<a  class="btn btn-sm btn-outline-primary" target="_blank"  title="FrontEnd" href="' . (config('website.cnf_appurl') . '/' . config('website.cnf_lang') . str_replace('//', '/', ('/' . $fsconfig[0] . '/' . $row[$fsconfig[1]]))) . '"><i class="fa  fa-desktop"></i> FrontEnd</a>';
                    } ?>
                </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-6">
                                <fieldset class="sbox" style="border-top:0; border-radius: 5px;">
                                    <legend> Coupons</legend>
                                    <?php if (!isset($row['id'])) $row['id'] = null; ?>
                                    <input type='hidden' name='id' id='id' value='{{$row['id']}}'/>

                                    <div class="form-group  depen-  wrap-store_id  ">
                                        <label for="ipt" class=" control-label "> Store <span class="asterix"> * </span>
                                        </label>


                                        <?php if (!isset($row['store_id'])) $row['store_id'] = null; ?>

                                        <?php $row['store_id'] = trim($row['store_id'], '[]'); ?>

                                        <select name='store_id' rows='5' id='store_id' class='select2 '
                                                data-placeholder='Select Store' placeholder='Select Store'
                                                required></select>
                                    </div>
                                    <div class="form-group  depen-  wrap-title  ">
                                        <label for="ipt" class=" control-label "> Coupon Title <span
                                                    class="asterix"> * </span> </label>


                                        <?php if (!isset($row['title'])) $row['title'] = null; ?>
                                        <?php $val = json_decode($row['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='#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='title_{{$ilang}}_{{$curTime}}'>
                                                    <input type='text' name="title[{{$ilang}}]" id='title'
                                                           value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}'
                                                           required placeholder='Coupon Title - {{$ilang}}'
                                                           class='form-control input-sm '/>
                                                </div>
                                                    <?php $is_first = false; ?>
                                            @endforeach
                                        </div>

                                    </div>
                                    <div class="form-group  depen-  wrap-description  ">
                                        <label for="ipt" class=" control-label "> Coupon Description </label>


                                        <?php if (!isset($row['description'])) $row['description'] = null; ?>
                                        <?php $val = json_decode($row['description']); $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='#description_{{$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='description_{{$ilang}}_{{$curTime}}'>
				<textarea name="description[{{$ilang}}]" id='description' rows='5' class='form-control editor input-sm'
                          placeholder='Coupon Description - {{$ilang}}' class='form-control input-sm '/>
                                                    {{ isset($val->{$ilang}) ? $val->{$ilang} : ''   }}
                                                    </textarea>
                                                </div>
                                                    <?php $is_first = false; ?>
                                            @endforeach
                                        </div>

                                    </div>
                                    <div class="form-group  depen-  wrap-type  ">
                                        <label for="ipt" class=" control-label "> Coupon Type <span
                                                    class="asterix"> * </span> </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Select Coupon if there is Coupon Code"><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['type']) || strlen($row['type']) < 1) $row['type'] = 'offer'; ?>
                                        <?php $type = (isset($row['type'])) ? $row['type'] : null; ?>

                                        <input type='radio' name='type' value='offer' required
                                               @if( $type == 'offer') checked="checked" @endif class='minimal-red'>
                                        Offer

                                        <input type='radio' name='type' value='coupon' required
                                               @if( $type == 'coupon') checked="checked" @endif class='minimal-red'>
                                        Coupon
                                    </div>

                                    <div class="form-group depen- wrap-thumbnail">
                                        <label for="ipt" class=" control-label ">Recommended Thumbnail</label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Preferred size xxx X xxx px"><i class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['thumbnail'])) $row['thumbnail'] = null; ?>
                                        <input type='hidden' name='thumbnail' id='thumbnail'
                                               value='{{ $row['thumbnail'] }}'
                                               class='thumbnail form-control input-sm '/>

                                        <button class='btn btn-primary mr-5' data-type='mediaUpload'
                                                data-target='.thumbnail' type='button'>Choose file
                                        </button>
                                        <button class='btn btn-danger unUploadImage' data-type='mediaUnUpload'
                                                data-target='thumbnail' type='button'>Remove File
                                        </button>

                                        <div class='thumbnail_preview'></div>
                                        <div class='thumbnailPreview'>
                                            <div class='img-preview'>
                                                {!! SiteHelpers::showUploadedFile($row['thumbnail'], '/uploads/images/coupons/thumbnails') !!}
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group depen- wrap-link  ">
                                        <label for="ipt" class=" control-label "> Link <span class="asterix"> * </span>
                                        </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Enter plain link without any deeplink or extra paramter/subID."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['link'])) $row['link'] = null; ?>
                                        <?php $val = is_array($row['link']) ? (object)$row['link'] : json_decode($row['link']); $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='#link_{{$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='link_{{$ilang}}_{{$curTime}}'>
                                                    <input type='text' name="link[{{$ilang}}]" id='link'
                                                           value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}'
                                                           required placeholder='Link - {{$ilang}}'
                                                           class='form-control input-sm '
                                                           style="direction: ltr;"/>
                                                </div>
                                                    <?php $is_first = false; ?>
                                            @endforeach
                                        </div>

                                    </div>
                                    <div class="form-group depen- wrap-app_deep_link  ">
                                        <label for="app_deep_link" class=" control-label col-md-3 text-left"> App
                                            DeepLink </label>

                                        <div class="col-md-9">
                                            <?php if (!isset($row['app_deep_link'])) $row['app_deep_link'] = null; ?>
                                            <input type='text' name='app_deep_link' id='app_deep_link'
                                                   value='{{ $row['app_deep_link'] }}'
                                                   class='form-control input-sm '/>
                                        </div>
                                        <div class="col-md-2">

                                        </div>
                                    </div>
                                    <div class="form-group  depen-  wrap-expiry_date  ">
                                        <label for="ipt" class=" control-label "> Expiry Date <span
                                                    class="asterix"> * </span> </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Coupons past expiry date will not be shown in front-end."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['expiry_date'])) $row['expiry_date'] = null; ?>

                                        <div class="input-group m-b" style="width:150px !important;">


                                            <input type='text' name='expiry_date' id='expiry_date'
                                                   value='{{ $row['expiry_date'] }}'
                                                   required class='form-control input-sm date '/>

                                            <span class="input-group-addon calwrap"><i
                                                        class="fa fa-calendar"></i></span>
                                        </div>
                                    </div> <?php if (strlen($row['clicks']) < 1) $row['clicks'] = '0'; ?>
                                    <input type='hidden' name='clicks' id='clicks' value='{{$row['clicks']}}'/>
                                    <?php if (!isset($row['created_mode'])) $row['created_mode'] = null; ?>
                                    <input type='hidden' name='created_mode' id='created_mode'
                                           value='{{$row['created_mode']}}'/>

                                    <div class="form-group  depen-  wrap-network_id  ">
                                        <label for="ipt" class=" control-label "> Network </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Optional, used when creating coupons using Network coupon API."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['network_id'])) $row['network_id'] = null; ?>

                                        <?php $row['network_id'] = trim($row['network_id'], '[]'); ?>

                                        <select name='network_id' rows='5' id='network_id' class='select2 '
                                                data-placeholder='Select Network' placeholder='Select Network'></select>
                                    </div> <?php if (!isset($row['network_coupon_id'])) $row['network_coupon_id'] = null; ?>
                                    <input type='hidden' name='network_coupon_id' id='network_coupon_id'
                                           value='{{$row['network_coupon_id']}}'/>
                                </fieldset>
                            </div>

                            <div class="col-md-6">
                                <fieldset class="sbox" style="border-top:0; border-radius: 5px;">
                                    <legend> Additional Details</legend>

                                    <div class="form-group  depen-  wrap-code  ">
                                        <label for="ipt" class=" control-label "> Code </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Optional, enter only if there's coupon code."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['code'])) $row['code'] = null; ?>
                                        <input type='text' name='code' id='code' value='{{ $row['code'] }}'
                                               class='form-control input-sm '/>
                                    </div>
                                    <div class="form-group  depen-  wrap-promo_text  ">
                                        <label for="ipt" class=" control-label "> Promo Text </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Applicable only for the Featured Offer, else leave it empty."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['promo_text'])) $row['promo_text'] = null; ?>
                                        <?php $val = json_decode($row['promo_text']); $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='#promo_text_{{$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='promo_text_{{$ilang}}_{{$curTime}}'>
                                                    <input type='text' name="promo_text[{{$ilang}}]" id='promo_text'
                                                           value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}'
                                                           placeholder='Promo Text - {{$ilang}}'
                                                           class='form-control input-sm '/>
                                                </div>
                                                    <?php $is_first = false; ?>
                                            @endforeach
                                        </div>

                                    </div>
                                    <div class="form-group  depen-  wrap-is_featured  ">
                                        <label for="ipt" class=" control-label "> Is Featured <span
                                                    class="asterix"> * </span> </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Switch this ON if you wish to show this on Homepage, Make sure to enter Promo Text"><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (strlen($row['is_featured']) < 1) $row['is_featured'] = '0'; ?>
                                        <div class='switch-wrap'><label class='switch'>
                                                <input type='hidden' name='is_featured' value='0'/>
                                                <input type='checkbox' name='is_featured' value='1'
                                                       @if($row['is_featured']) checked @endif
                                                /> <span class="slider round"></span></label></div>
                                    </div>
                                    <div class="form-group  depen-  wrap-is_recommended  ">
                                        <label for="ipt" class=" control-label "> Is Recommended <span
                                                    class="asterix"> * </span> </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="is this a recommended offer or not"><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (strlen($row['is_recommended']) < 1) $row['is_recommended'] = '0'; ?>
                                        <div class='switch-wrap'><label class='switch'>
                                                <input type='hidden' name='is_recommended' value='0'/>
                                                <input type='checkbox' name='is_recommended' value='1'
                                                       @if($row['is_recommended']) checked @endif
                                                /> <span class="slider round"></span></label></div>
                                    </div>
                                    <div class="form-group depen- wrap-coupon_rank">
                                        <label for="coupon_rank" class="control-label">
                                            Coupon Rank
                                        </label>

                                        <a class="adtip"
                                        data-toggle="tooltip"
                                        data-placement="bottom"
                                        title="Optional. Enter a value from 1 to 10. Ranked coupons appear first on the Store page.">
                                            <i class="fa fa-info-circle"></i>
                                        </a>

                                        <?php
                                        if (!isset($row['coupon_rank'])) {
                                            $row['coupon_rank'] = null;
                                        }
                                        ?>

                                        <input
                                            type="number"
                                            name="coupon_rank"
                                            id="coupon_rank"
                                            value="{{ old('coupon_rank', $row['coupon_rank']) }}"
                                            min="1"
                                            max="10"
                                            step="1"
                                            class="form-control input-sm"
                                            placeholder="1–10"
                                        />
                                    </div>
                                    <div class="form-group  depen-  wrap-is_exclusive  ">
                                        <label for="ipt" class=" control-label "> Is Exclusive <span
                                                    class="asterix"> * </span> </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="is this a Exclusive offer or not"><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (strlen($row['is_exclusive']) < 1) $row['is_exclusive'] = '0'; ?>
                                        <div class='switch-wrap'><label class='switch'>
                                                <input type='hidden' name='is_exclusive' value='0'/>
                                                <input type='checkbox' name='is_exclusive' value='1'
                                                       @if($row['is_exclusive']) checked @endif
                                                /> <span class="slider round"></span></label></div>
                                    </div>

                                    <div class="form-group  depen-  wrap-verified  ">
                                        <label for="ipt" class=" control-label "> Verified <span
                                                    class="asterix"> * </span> </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Marks this coupon as verified through direct partnership with the brand."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['verified']) || $row['verified'] === '') $row['verified'] = '1'; ?>
                                        <div class='switch-wrap'><label class='switch'>
                                                <input type='hidden' name='verified' value='0'/>
                                                <input type='checkbox' name='verified' value='1'
                                                       @if($row['verified']) checked @endif
                                                /> <span class="slider round"></span></label></div>
                                    </div>

                                    <div class="form-group  depen-  wrap-initial_usage_count  ">
                                        <label for="initial_usage_count" class="control-label">
                                            Initial Usage Count
                                        </label>

                                        <a class="adtip"
                                        data-toggle="tooltip"
                                        data-placement="bottom"
                                        title="Optional. The baseline usage count for a newly published coupon.">
                                            <i class="fa fa-info-circle"></i>
                                        </a>

                                        <?php
                                        if (!isset($row['initial_usage_count'])) {
                                            $row['initial_usage_count'] = null;
                                        }
                                        ?>

                                        <input
                                            type="number"
                                            name="initial_usage_count"
                                            id="initial_usage_count"
                                            value="{{ old('initial_usage_count', $row['initial_usage_count']) }}"
                                            min="0"
                                            step="1"
                                            class="form-control input-sm"
                                            placeholder="0"
                                        />
                                    </div>

                                    <div class="form-group  depen-  wrap-website_copy_count  ">
                                        <label for="ipt" class=" control-label "> Website Copy Count </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Read-only. Increases automatically each time a user copies this coupon code on the website."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <input type="text" class="form-control input-sm" value="{{ $row['website_copy_count'] ?? 0 }}" disabled />
                                    </div>

                                    <div class="form-group  depen-  wrap-usage_count  ">
                                        <label for="ipt" class=" control-label "> Usage Count </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Read-only. Initial Usage Count + Website Copy Count."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <input type="text" class="form-control input-sm" value="{{ $row['usage_count'] ?? 0 }}" disabled />
                                    </div>

                                    <div class="form-group  depen-  wrap-cats  ">
                                        <label for="ipt" class=" control-label "> Coupon Categories </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Select applicable coupon categories for this coupons, optional."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['cats'])) $row['cats'] = null; ?>

                                        <?php $row['cats'] = trim($row['cats'], '[]'); ?>

                                        <select name='cats[]' multiple rows='5' id='cats' class='select2 '
                                                data-placeholder='Select Coupon Categories'
                                                placeholder='Select Coupon Categories'></select>
                                    </div>
                                    <div class="form-group  depen-  wrap-brands  ">
                                        <label for="ipt" class=" control-label "> Brands </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Select applicable brands for this coupons, optional."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['brands'])) $row['brands'] = null; ?>

                                        <?php $row['brands'] = trim($row['brands'], '[]'); ?>

                                        <select name='brands[]' multiple rows='5' id='brands' class='select2 '
                                                data-placeholder='Select Brands' placeholder='Select Brands'></select>
                                    </div>
                                    <div class="form-group  depen-  wrap-tags  ">
                                        <label for="ipt" class=" control-label "> Tags </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Select applicable tags for this coupons, optional."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['tags'])) $row['tags'] = null; ?>

                                        <?php $row['tags'] = trim($row['tags'], '[]'); ?>

                                        <select name='tags[]' multiple rows='5' id='tags' class='select2 '
                                                data-placeholder='Select Tags' placeholder='Select Tags'></select>
                                    </div>

                                    <div class="form-group  depen-  wrap-region_code  ">
                                        <label for="ipt" class=" control-label "> Region *</label>

                                        <?php if (!isset($row['region_code'])) $row['region_code'] = null; ?>

                                        <?php $row['region_code'] = trim($row['region_code'], '[]'); ?>

                                        <select name='region_code[]' id='region_code' class='select2' multiple
                                                data-placeholder='Select Region' placeholder='Select Region'
                                                required></select>
                                    </div>
                                    <div class="form-group  depen-  wrap-highlight_title1  ">
                                        <label for="ipt" class=" control-label ">Highlight *</label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Highlight should be composed of two labels \n Ex1: “50% off” label1: 50% label2 :off\n Ex2: “عرض خاص“ label1: عرض  label2 :خاص”."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (!isset($row['highlight_title1'])) $row['highlight_title1'] = null;
                                        $val1 = json_decode($row['highlight_title1']);
                                        if (!isset($row['highlight_title2'])) $row['highlight_title2'] = null;
                                        $val2 = json_decode($row['highlight_title2']); $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='#highlight_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='highlight_title_{{$ilang}}_{{$curTime}}'>
                                                    <div class=" row">
                                                        <div class="col-xs-6">
                                                            <input type='text' name="highlight_title1[{{$ilang}}]"
                                                                   id='highlight_title1'
                                                                   value='{{   isset($val1->{$ilang}) ? $val1->{$ilang} : ''   }}'
                                                                   placeholder='Highlight title 1 - {{$ilang}}'
                                                                   class='form-control input-sm ' maxlength="7"/>
                                                        </div>
                                                        <div class="col-xs-6">
                                                            <input type='text' name="highlight_title2[{{$ilang}}]"
                                                                   id='highlight_title2'
                                                                   value='{{   isset($val2->{$ilang}) ? $val2->{$ilang} : ''   }}'
                                                                   placeholder='Highlight title 2 - {{$ilang}}'
                                                                   class='form-control input-sm ' maxlength="7"/>
                                                        </div>
                                                    </div>
                                                </div>
                                                    <?php $is_first = false; ?>
                                            @endforeach
                                        </div>
                                    </div>


                                    <div class="form-group  depen-  wrap-status  ">
                                        <label for="ipt" class=" control-label "> Status <span
                                                    class="asterix"> * </span> </label>
                                        <a class="adtip" data-toggle="tooltip" data-placement="bottom"
                                           title="Only Published coupons will be shown up in front-end."><i
                                                    class="fa fa-info-circle"></i></a>

                                        <?php if (strlen($row['status']) < 1) $row['status'] = 'publish'; ?>
                                        <?php $status = (isset($row['status'])) ? $row['status'] : null; ?>

                                        <input type='radio' name='status' value='publish' required
                                               @if( $status == 'publish') checked="checked" @endif class='minimal-red'>
                                        Publish

                                        <input type='radio' name='status' value='draft' required
                                               @if( $status == 'draft') checked="checked" @endif class='minimal-red'>
                                        Draft

                                        <input type='radio' name='status' value='trash' required
                                               @if( $status == 'trash') checked="checked" @endif class='minimal-red'>
                                        Trash
                                    </div>
                                </fieldset>
                            </div>


                        </div>


                    </div>
                </div>
            </div>
            @include('/manage/'.$pageModule.'/subform')


            <div class="sbox-title clearfix">
                <div class="sbox-tools pull-right">
                    <a href="{{ url('/manage/'.$pageModule.'?return='.$return) }}" 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_id").select2({
                ajax: {
                    url: "{{url('/manage/coupons/ajaxselect?filter=stores:id: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.id,
                                    text: selctToJson(item, 'name')
                                };
                            }),
                            pagination: {
                                more: data.pagination
                            }
                        }
                    },
                    cache: true,
                    delay: 250
                },
                // minimumInputLength: 2,
                multiple: 0,
                width: '100%'
            });


            @if( strlen($row["store_id"]) > 0  )
            // Fetch the preselected item, and add to the control
            var store_idSelect = $('#store_id');
            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/coupons/ajaxselect?filter=stores:id:name&values='.urlencode($row["store_id"])) !!}",
            }).then(function (data) {
                // create the option and append to Select2
                data.items.map(function (item) {
                    var option = new Option(selctToJson(item, 'name'), item.id, true, true);
                    store_idSelect.append(option).trigger('change');

                });


                // manually trigger the `select2:select` event
                store_idSelect.trigger({
                    type: 'select2:select',
                    params: {
                        data: data
                    }
                });
            });

            store_idSelect.select2_sortable();
            @endif

            $("#region_code").select2({
                ajax: {
                    url: "{{url('/manage/stores/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
                },
                // minimumInputLength: 2,
                multiple: 1,
                width: '100%'
            });


            @if( strlen($row["region_code"]) > 0  )
            // Fetch the preselected item, and add to the control
            var region_codeSelect = $('#region_code');
            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/coupons/ajaxselect?filter=regions:code:name&values='.urlencode($row["region_code"])) !!}",
            }).then(function (data) {
                // create the option and append to Select2
                data.items.map(function (item) {
                    var option = new Option(selctToJson(item, 'name'), item.code, true, true);
                    region_codeSelect.append(option).trigger('change');

                });
                // manually trigger the `select2:select` event
                region_codeSelect.trigger({
                    type: 'select2:select',
                    params: {
                        data: data
                    }
                });
            });

            region_codeSelect.select2_sortable();
            @endif


            $("#network_id").jCombo("{!! url('/manage/coupons/comboselect?filter=networks:id:name&values='.$row["network_id"]) !!}",
                {selected_value: '{{ $row["network_id"] }}'});

            $("#cats").select2({
                ajax: {
                    url: "{{url('/manage/coupons/ajaxselect?filter=categories_coupon:id: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.id,
                                    text: selctToJson(item, 'name')
                                };
                            }),
                            pagination: {
                                more: data.pagination
                            }
                        }
                    },
                    cache: true,
                    delay: 250
                },
                // minimumInputLength: 2,
                multiple: 1,
                width: '100%'
            });


            @if( strlen($row["cats"]) > 0  )
            // Fetch the preselected item, and add to the control
            var catsSelect = $('#cats');
            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/coupons/ajaxselect?filter=categories_coupon:id:name&values='.urlencode($row["cats"])) !!}",
            }).then(function (data) {
                // create the option and append to Select2
                data.items.map(function (item) {
                    var option = new Option(selctToJson(item, 'name'), item.id, true, true);
                    catsSelect.append(option).trigger('change');

                });


                // manually trigger the `select2:select` event
                catsSelect.trigger({
                    type: 'select2:select',
                    params: {
                        data: data
                    }
                });
            });

            catsSelect.select2_sortable();
            @endif


            $("#brands").select2({
                ajax: {
                    url: "{{url('/manage/coupons/ajaxselect?filter=brands:id: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.id,
                                    text: selctToJson(item, 'name')
                                };
                            }),
                            pagination: {
                                more: data.pagination
                            }
                        }
                    },
                    cache: true,
                    delay: 250
                },
                // minimumInputLength: 2,
                multiple: 1,
                width: '100%'
            });


            @if( strlen($row["brands"]) > 0  )
            // Fetch the preselected item, and add to the control
            var brandsSelect = $('#brands');
            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/coupons/ajaxselect?filter=brands:id:name&values='.urlencode($row["brands"])) !!}",
            }).then(function (data) {
                // create the option and append to Select2
                data.items.map(function (item) {
                    var option = new Option(selctToJson(item, 'name'), item.id, true, true);
                    brandsSelect.append(option).trigger('change');

                });


                // manually trigger the `select2:select` event
                brandsSelect.trigger({
                    type: 'select2:select',
                    params: {
                        data: data
                    }
                });
            });

            brandsSelect.select2_sortable();
            @endif


            $("#tags").select2({
                ajax: {
                    url: "{{url('/manage/coupons/ajaxselect?filter=tags:id: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.id,
                                    text: selctToJson(item, 'name')
                                };
                            }),
                            pagination: {
                                more: data.pagination
                            }
                        }
                    },
                    cache: true,
                    delay: 250
                },
                // minimumInputLength: 2,
                multiple: 1,
                width: '100%'
            });


            @if( strlen($row["tags"]) > 0  )
            // Fetch the preselected item, and add to the control
            var tagsSelect = $('#tags');
            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/coupons/ajaxselect?filter=tags:id:name&values='.urlencode($row["tags"])) !!}",
            }).then(function (data) {
                // create the option and append to Select2
                data.items.map(function (item) {
                    var option = new Option(selctToJson(item, 'name'), item.id, true, true);
                    tagsSelect.append(option).trigger('change');

                });


                // manually trigger the `select2:select` event
                tagsSelect.trigger({
                    type: 'select2:select',
                    params: {
                        data: data
                    }
                });
            });

            tagsSelect.select2_sortable();
            @endif



            $('.removeMultiFiles').on('click', function () {
                var removeUrl = '{{ url("coupons/removefiles?file=")}}' + $(this).attr('url');
                $(this).parent().remove();
                $.get(removeUrl, function (response) {
                });
                $(this).parent('div').empty();
                return false;
            });

        });
    </script>
@stop