<?php $__env->startSection('tab-title', ' | تنظیمات قالب سایت'); ?>

<?php $__env->startSection("page-title" , 'تنظیمات قالب سایت'); ?>

<?php $__env->startSection("page-body"); ?>
    <div class="box">
        <div class="box-header with-border">
            <h3 class="box-title">ثبت / ویرایش محتوای قالب</h3>
        </div>
        <div class="box-body">
            <form action="<?php echo e(route('template-settings.submit')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="row">
                    <div class="col-md-2 col-12">
                        <div class="form-group">
                            <select id="key" name="key" class="form-control ltr">
                                <option>Choose One...</option>
                                <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($item['item_key']); ?>"><?php echo e($item['item_key']); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <button id="change-input" class="btn btn-block btn-warning" type="button">متن / لینک</button>
                        <button id="submit" class="btn btn-block btn-info mt-4" type="submit">ثبت / ویرایش</button>
                    </div>
                    <div class="col-md-10 col-12">
                        <div id="value-box" class="form-group">
                            <input id="value" type="text" name="value" class="form-control ltr">
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection("page-scripts"); ?>

<script src="<?php echo e(asset('statics/vendor/tinymce/tinymce.min.js')); ?>"></script>
<script>
var changeCount = 0;
var changeState = 'textarea';
function initTextarea() {
    tinymce.init({
        selector: 'textarea',
        plugins: 'advlist link image lists emoticons',
        toolbar: 'undo redo | styles | bold italic | alignleft aligncenter alignright alignjustify | outdent indent | emoticons link'
    });
}
$('#change-input').click( function () {
    if (changeState === 'textarea') {
        changeCount++;
        changeState = 'input';
        $('#value-box').html('<textarea id="value" name="value" class="form-control"></textarea>');
        initTextarea();
    }
    else {
        changeCount++;
        changeState = 'textarea';
        $('#value-box').html('<input id="value" type="text" name="value" class="form-control ltr">');
    }
});
$('#key').change( function () {
    $.ajax({
        type:'POST',
        url: "<?php echo e(route('get-item-value.submit')); ?>",
        data: { key: $(this).val() },
        headers: { 'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>' },
        beforeSend: function () {
            console.clear();
            $("#key, #submit").attr('disabled', true);
        },
        success: (response) => {
            try {
                changeCount === 0 || changeState === 'textarea' ? $('#value').val(response.item_value) : tinymce.activeEditor.setContent(response.item_value);
            } catch (e) {
                tinymce.activeEditor.setContent('');
            }
        },
        error: function(response){
            console.log(response.responseJSON.message);
        },
        complete: function () {
            $("#key, #submit").attr('disabled', false);
        }
    });
});
</script>
<?php if(session()->has('message')): ?>
<script>
    $.toast({
        text: '<?php echo e(session()->get('message')); ?>',
        position: 'bottom-left',
        loaderBg: '#ff6849',
        icon: 'success',
        textAlign: 'center',
        hideAfter: 5000
    });
</script>
<?php endif; ?>

<?php $__env->stopSection(); ?>

<?php echo $__env->make("v1/02_dash-template/layouts/layout-admin", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\gpumonsters\core\resources\views/v1/02_dash-template/admin-pages/template-items.blade.php ENDPATH**/ ?>