@extends('layouts.app')

@section('content')
<section class="page-header row">
    <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/missingcashbackclaims?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> Missing Cashback Claim </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-user_id">
                                    <label for="user_id" class="control-label"> User <span class="asterix text-danger">
                                            * </span></label>
                                    <?php if (!isset($row['user_id']))
    $row['user_id'] = null; ?>
                                    <?php $row['user_id'] = trim($row['user_id'], '[]'); ?>
                                    <select name='user_id' rows='5' id='user_id' class='select2'
                                        data-placeholder='Select User' placeholder='Select User'></select>
                                </div>

                                <div class="form-group depen- wrap-click_id">
                                    <label for="click_id" class="control-label"> Click ID </label>
                                    <?php if (!isset($row['click_id']))
    $row['click_id'] = null; ?>
                                    <input type='text' name='click_id' id='click_id' value='{{ $row['click_id'] }}'
                                        class='form-control input-sm' />
                                </div>

                                <div class="form-group depen- wrap-click_time">
                                    <label for="click_time" class="control-label"> Click Time </label>
                                    <?php if (!isset($row['click_time']))
    $row['click_time'] = null; ?>
                                    <div class="input-group m-b" style="width:150px !important;">
                                        <input type='text' name='click_time' id='click_time'
                                            value='{{ $row['click_time'] }}'
                                            class='form-control input-sm @if(trim('  ') != 'readonly') datetime @endif ' />
                                        <span class="input-group-addon calwrap"><i class="fa fa-calendar"></i></span>
                                    </div>
                                </div>

                                <div class="form-group depen- wrap-store_id">
                                    <label for="store_id" class="control-label"> Store <span
                                            class="asterix text-danger"> * </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'></select>
                                </div>

                                <div class="form-group depen- wrap-network_id">
                                    <label for="network_id" class="control-label"> Network <span
                                            class="asterix text-danger"> * </span></label>
                                    <?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>

                                <div class="form-group depen- wrap-currency_iso">
                                    <label for="currency_iso" class="control-label"> Currency ISO <span
                                            class="asterix text-danger"> * </span></label>
                                    <?php if (!isset($row['currency_iso']))
    $row['currency_iso'] = null; ?>
                                    <?php $row['currency_iso'] = trim($row['currency_iso'], '[]'); ?>
                                    <select name='currency_iso' rows='5' id='currency_iso' class='select2'
                                        data-placeholder='Select Currency ISO'
                                        placeholder='Select Currency ISO'></select>
                                </div>

                                <div class="form-group depen- wrap-platform">
                                    <label for="platform" class="control-label"> Platform <span
                                            class="asterix text-danger"> * </span></label>
                                    <?php if (strlen($row['platform']) < 1)
    $row['platform'] = 'website'; ?>
                                    <?php $platform = (isset($row['platform'])) ? $row['platform'] : null; ?>
                                    <input type='radio' name='platform' value='website' required
                                        @if($platform == 'website') checked="checked" @endif class='minimal-red'> Website
                                    <input type='radio' name='platform' value='mobile' required @if($platform == 'mobile')
                                    checked="checked" @endif class='minimal-red'> Mobile
                                    <input type='radio' name='platform' value='ios' required @if($platform == 'ios')
                                    checked="checked" @endif class='minimal-red'> iOS
                                    <input type='radio' name='platform' value='android' required
                                        @if($platform == 'android') checked="checked" @endif class='minimal-red'> Android
                                </div>

                                <div class="form-group depen- wrap-closed_by">
                                    <label for="closed_by" class="control-label"> Closed By </label>
                                    <?php if (!isset($row['closed_by']))
    $row['closed_by'] = null; ?>
                                    <?php $closed_by = (isset($row['closed_by'])) ? $row['closed_by'] : null; ?>
                                    <input type='radio' name='closed_by' value='admin' @if($closed_by == 'admin')
                                    checked="checked" @endif class='minimal-red'> Admin
                                    <input type='radio' name='closed_by' value='user' @if($closed_by == 'user')
                                    checked="checked" @endif class='minimal-red'> User
                                </div>

                                <div class="form-group depen- wrap-attachments">
                                    <label for="closed_by" class="control-label"> Attachments </label>
                                    @if ($row['id'])
                                        @if ($row['attachments'])
                                            @foreach($row['attachments'] as $attachment)
                                                <a href="{{ $attachment }}" target="_blank" class="d-inline-block mx-2">
                                                    <img src="{{ $attachment }}" alt="" class="img-thumbnail" width="100"
                                                        height="100">
                                                </a>
                                            @endforeach
                                        @endif
                                    @else
                                        <input type="file" accept=".jpeg,.bmp,.png,.gif,.svg,.jpg,.webp"
                                            name="attachments[]" class="form-control" id="attachments"
                                            style="line-height:1.2" multiple>
                                    @endif
                                </div>
                            </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-transaction_date">
                                    <label for="transaction_date" class="control-label"> Transaction Date </label>
                                    <?php if (!isset($row['transaction_date']))
    $row['transaction_date'] = null; ?>
                                    <div class="input-group m-b" style="width:150px !important;">
                                        <input type='text' name='transaction_date' id='transaction_date'
                                            value='{{ $row['transaction_date'] }}' class='form-control input-sm date' />
                                        <span class="input-group-addon calwrap"><i class="fa fa-calendar"></i></span>
                                    </div>
                                </div>

                                <div class="form-group depen- wrap-order_id">
                                    <label for="order_id" class="control-label"> Order ID </label>
                                    <?php if (!isset($row['order_id']))
    $row['order_id'] = null; ?>
                                    <input type='text' name='order_id' id='order_id' value='{{ $row['order_id'] }}'
                                        class='form-control input-sm ' />
                                </div>

                                <div class="form-group depen- wrap-order_amount">
                                    <label for="order_amount" class="control-label"> Order Amount </label>
                                    <?php if (!isset($row['order_amount']))
    $row['order_amount'] = null; ?>
                                    <input type='text' name='order_amount' id='order_amount'
                                        value='{{ $row['order_amount'] }}' class='form-control is_decimal'
                                        onkeypress='return isNumberKey(event,this)' />
                                </div>

                                <div class="form-group depen- wrap-message">
                                    <label for="message" class="control-label"> Message </label>
                                    <?php if (!isset($row['message']))
    $row['message'] = null; ?>
                                    <textarea name='message' rows='5' id='message'
                                        class='form-control input-sm'>{{ $row['message'] }}</textarea>
                                </div>

                                <div class="form-group depen- wrap-note">
                                    <label for="note" class="control-label"> Note </label>
                                    <?php if (!isset($row['note']))
    $row['note'] = null; ?>
                                    <textarea name='note' rows='5' id='note'
                                        class='form-control input-sm'>{{ $row['note'] }}</textarea>
                                </div>

                                <div class="form-group depen- wrap-status">
                                    <label for="status" class="control-label"> Status <span class="asterix text-danger">
                                            * </span> </label>
                                    <?php if (strlen($row['status']) < 1)
    $row['status'] = 'open'; ?>
                                    <?php $status = (isset($row['status'])) ? $row['status'] : null; ?>
                                    <input type='radio' name='status' value='open' required @if($status == 'open')
                                    checked="checked" @endif class='minimal-red'> Open
                                    <input type='radio' name='status' value='hold' required @if($status == 'hold')
                                    checked="checked" @endif class='minimal-red'> Hold
                                    <input type='radio' name='status' value='answered' required @if($status == 'answered')
                                    checked="checked" @endif class='minimal-red'> Answered
                                    <input type='radio' name='status' value='closed' required @if($status == 'closed')
                                    checked="checked" @endif class='minimal-red'> Closed
                                </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>


<table class="hidden">
    <tr class="clone clonedInput dataRow hidden" id="masterClone">
        <?php $curTime = "01"; ?>

        <?php $row['id'] = null; ?>
        <?php if (!isset($row['id']))
    $row['id'] = null; ?>
        <input type='hidden' name='bulk_id[{{$row['id']}}]' id='id' value='{{$row['id']}}' />

        <?php $row['claim_id'] = null;  ?>
        <?php if (!isset($row['claim_id']))
    $row['claim_id'] = null; ?>
        <input type='hidden' name='bulk_claim_id[{{$row['id']}}]' id='claim_id' value='{{$row['claim_id']}}' />

        <input type='hidden' name='bulk_is_new[{{$row['id']}}]' id='is_new' value='1' />

        <td>
            <?php $row['comment'] = null; ?>
            <?php if (!isset($row['comment']))
    $row['comment'] = null; ?>
            <textarea name='bulk_comment[{{$row['id']}}]' rows='5' id='comment' class='form-control input-sm'
                required>{{ $row['comment'] }}</textarea>
        </td>

        <td>
            <?php $row['commented_by'] = null; ?>
            <?php if (strlen($row['commented_by']) < 1)
    $row['commented_by'] = 'admin'; ?>
            <?php $commented_by = explode(',', $row['commented_by']);
$commented_by_opt = array('admin' => 'Admin', 'user' => 'User', ); ?>
            <select name='bulk_commented_by[{{$row['id']}}]' rows='5' placeholder='Select Commented By'
                data-placeholder='Select Commented By' class='select2'>
                <?php
foreach ($commented_by_opt as $key => $val) {
    echo "<option  value ='$key' " . ($row['commented_by'] == $key ? " selected='selected' " : '') . ">$val</option>";
}
                    ?>
            </select>
        </td>

        <td>
            <?php $row['created_at'] = null; ?>
            <?php if (strlen($row['created_at']) < 1)
    $row['created_at'] = '2019-11-05 06:30:43'; ?>

            <div class="input-group m-b" style="width:150px !important;">
                <input type='text' name='bulk_created_at[{{$row['id']}}]' id='created_at'
                    value='{{ date('Y-m-d h:i:s', time()) }}' readonly
                    class='form-control input-sm @if(trim(' readonly ') != 'readonly') datetime @endif ' />
                <span class="input-group-addon calwrap"><i class="fa fa-calendar"></i></span>
            </div>
        </td>

        <td>
            <input type="file" accept=".jpeg,.bmp,.png,.gif,.svg,.jpg,.webp" name="bulk_attachments[{{$row['id']}}][]"
                class="form-control" id="attachments" style="line-height:1.2" multiple>
        </td>

        <td>
            <a onclick="removeClone(this)" href="javascript:void(0);" class="remove btn btn-xs btn-danger"><i
                    class="fa fa-minus" aria-hidden="true"></i></a>
            <input type="hidden" name="counter[]">
        </td>
    </tr>
</table>

<script type="text/javascript">
    $(document).ready(function () {
        jQuery(document).ready(function ($) {
            moveCopySrc();
        });

        $('.addC').relCopyForm({ moveParent: "#addChildRows" });
        $("#user_id").select2({
            ajax: {
                url: "{{url('/manage/missingcashbackclaims/ajaxselect?filter=users:user_id:first_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.user_id,
                                text: selctToJson(item, 'first_name')
                            };
                        }),
                        pagination: {
                            more: data.pagination
                        }
                    }
                },
                cache: true,
                delay: 250
            },
            multiple: 0,
            width: '100%'
        });

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

                });

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

            user_idSelect.select2_sortable();
        @endif

        $("#store_id").select2({
            ajax: {
                url: "{{url('/manage/missingcashbackclaims/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)
            var store_idSelect = $('#store_id');
            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/missingcashbackclaims/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);
                    store_idSelect.append(option).trigger('change');

                });

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

            store_idSelect.select2_sortable();
        @endif

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

        $("#currency_iso").select2({
            ajax: {
                url: "{{url('/manage/missingcashbackclaims/ajaxselect?filter=currencies:iso_code:symbol')}}",
                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.iso_code,
                                text: selctToJson(item, 'symbol')
                            };
                        }),
                        pagination: {
                            more: data.pagination
                        }
                    }
                },
                cache: true,
                delay: 250
            },
            multiple: 0,
            width: '100%'
        });

        @if(strlen($row["currency_iso"]) > 0)
            var currency_isoSelect = $('#currency_iso');
            $.ajax({
                type: 'GET',
                url: "{!! url('/manage/missingcashbackclaims/ajaxselect?filter=currencies:iso_code:symbol&values=' . urlencode($row["currency_iso"])) !!}",
            }).then(function (data) {
                data.items.map(function (item) {
                    var option = new Option(selctToJson(item, 'symbol'), item.iso_code, true, true);
                    currency_isoSelect.append(option).trigger('change');

                });

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

            currency_isoSelect.select2_sortable();
        @endif

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