
<?php
    use App\Helpers\Form as FormTemplate;
    use App\Helpers\Template;
    
    $formInputAttr = config('zvn.template.form_input');
    $formLabelAttr = config('zvn.template.form_label');
    $formCkeditor = config('zvn.template.form_ckeditor');
    $statusValue = ['default' => 'Select status', 'active' => config('zvn.template.status.active.name'), 'inactive' => config('zvn.template.status.inactive.name')];
    
    $srcThumb = asset('images/coupon');
    $inputHiddenID = Form::hidden('id', @$item['id']);

    $elements_1 = [
        [
            'label' => Form::label('code', 'Mã khuyến mãi', $formLabelAttr),
            'element' => Form::text('code', @$item['code'], $formInputAttr),
        ],
        [
            'element' => Form::button('Generate', ['id' => 'generate_code', 'class' => 'btn btn-success']),
            'type' => 'btn',
        ],
        [
            'label' => Form::label('value_percent', 'Giá trị %', $formLabelAttr),
            'element' => Form::number('value_percent', @$item['value_percent'], $formInputAttr),
        ],
        [
            'label' => Form::label('value_price', 'Giá trị thật', $formLabelAttr),
            'element' => Form::number('value_price', @$item['value_price'], $formInputAttr),
        ],
        [
            'label' => Form::label('total_use', 'Số lần sử dụng', $formLabelAttr),
            'element' => Form::number('total_use', @$item['total_use'], $formInputAttr),
        ],
    ];
    $elements_2 = [
        [
            'label' => Form::label('date_start', 'Từ', $formLabelAttr),
            'element' => Form::date('date_start', \Carbon\Carbon::now(), $formInputAttr),
        ],
        [
            'label' => Form::label('date_end', 'Đến', $formLabelAttr),
            'element' => Form::date('date_end', \Carbon\Carbon::now(), $formInputAttr),
        ],
    ];
    $elements_3 = [
        [
            'label' => Form::label('total_start', 'Từ', $formLabelAttr),
            'element' => Form::number('total_start', @$item['total_start'], $formInputAttr),
        ],
        [
            'label' => Form::label('total_end', 'Đến', $formLabelAttr),
            'element' => Form::number('total_end', @$item['total_end'], $formInputAttr),
        ],
        [
            'element' => $inputHiddenID . Form::submit('Save', ['class' => 'btn btn-success']),
            'type' => 'btn-submit',
        ],
    ];
?>

<?php $__env->startSection('content'); ?>
    <?php echo $__env->make('admin.templates.page_header', ['pageIndex' => false], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('admin.templates.error', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                <?php echo e(Form::open([
                    'method' => 'POST',
                    'url' => route("$controllerName/save"),
                    'accept-charset' => 'UTF-8',
                    'enctype' => 'multipart/form-data',
                    'class' => 'form-horizontal form-label-left',
                    'id' => 'main-form',
                ])); ?>

                <?php echo $__env->make('admin.templates.x_title', ['title' => 'Thông tin chung'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <div class="x_content">
                    <?php echo FormTemplate::show($elements_1); ?>

                </div>
                <?php echo $__env->make('admin.templates.x_title', ['title' => 'Áp dụng trong khoảng thời gian'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <div class="x_content">
                    <?php echo FormTemplate::show($elements_2); ?>

                </div>
                <?php echo $__env->make('admin.templates.x_title', ['title' => 'Áp dụng khi giá trị đơn hàng'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <div class="x_content">
                    <?php echo FormTemplate::show($elements_3); ?>

                </div>
            </div>
            <?php echo e(Form::close()); ?>

        </div>
    </div>
    <input type="hidden" name="url-coupon-code" value="<?php echo e(route($controllerName . '/code')); ?>">
<?php $__env->stopSection(); ?>

<?php $__env->startPush('custom-script'); ?>
    <script>
        function generateCode() { 
            $.ajax({
                type: "get",
                url: $('[name="url-coupon-code"]').val(),
                dataType: "json",
                success: function (response) {
                    $('#code').val(response.code);
                }
            });
        }
        $(document).ready(function() {
            var id = $('[name="id"]').val();
            if (!id) {
                generateCode();
            }
            $('#generate_code').click(function (e) { 
                generateCode();
                
            });
            
            
        });
    </script>
<?php $__env->stopPush(); ?>

    

<?php echo $__env->make('admin.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\offline_laravel_duongle\resources\views/admin/pages/coupon/form.blade.php ENDPATH**/ ?>