<?php $_shouldextend[1]=1; ?>

<?php $this->startSection('content'); ?>
 <?php echo $this->runChild('manager.parts.button', [
 'text' => __('manager.add'), 
 'click' => '$dispatch("openmodal", {
 target: "details",
 })',
 ]); ?>
 <br><br>
 
 <div>
 <?php echo $this->runChild('manager.parts.list', ['action' => 'coupon']); ?>
 </div>

 <div x-data="{ 
 defaultData: { 
 id: 0,
 title: '',
 code: '',
 percent: '',
 active: 0,
 all: 0,
 }, 
 hideAfterSubmit: true,
 }">
 <div id="modal-details" class="modal eins-modal" x-data="modal" @openmodal.window="open">
 <div class="modal__outer eins-modal-content" style="width: 400px">
 <div class="modal__title">
 <?php echo \htmlentities(__('manager_coupon.coupon')??'', ENT_QUOTES, 'UTF-8', false); ?>


 <template x-if="data.id > 0">
 <span x-text="'#' + data.id"></span>
 </template>

 <div class="modal__close x-tool x-tool-close" x-bind="close">&nbsp;</div>
 </div>

 <div class="modal__content">
 <form @submit.prevent="submit()" class="form">
 <input type="hidden" name="action" value="coupon">
 <template x-if="data.id > 0">
 <input type="hidden" name="key" :value="data.id">
 </template>

 <table class="x-grid3-row-table" x-data="{
 params: {
 title: {
 title: '<?php echo \htmlentities(__('manager_coupon.title')??'', ENT_QUOTES, 'UTF-8', false); ?>',
 type: 'text',
 },
 code: {
 title: '<?php echo \htmlentities(__('manager_coupon.code')??'', ENT_QUOTES, 'UTF-8', false); ?>',
 type: 'text',
 },
 percent: {
 title: '<?php echo \htmlentities(__('manager_coupon.percent')??'', ENT_QUOTES, 'UTF-8', false); ?>',
 type: 'text',
 },
 active: {
 title: '<?php echo \htmlentities(__('manager_coupon.active')??'', ENT_QUOTES, 'UTF-8', false); ?>',
 type: 'checkbox',
 },
 all: {
 title: '<?php echo \htmlentities(__('manager_coupon.all')??'', ENT_QUOTES, 'UTF-8', false); ?>',
 type: 'checkbox',
 },
 },
 }">
 <tbody>
 <template x-for="(param, key) in params">
 <tr>
 <td>
 <div class="list__value x-grid3-hd-inner" x-text="param.title"></div>
 </td>
 
 <td>
 <div class="list__value x-grid3-cell-inner">
 <template x-if="param.type == 'checkbox'">
 <input type="checkbox" 
 :name="key" 
 :checked="data[key] == 1"
 value="1"
 :class="errors[key] ? 'textfield x-form-text x-form-field error' : 'textfield x-form-text x-form-field'">
 </template>

 <template x-if="param.type != 'checkbox'">
 <input :type="param.type" 
 :name="key" 
 :value="data[key]"
 :class="errors[key] ? 'textfield x-form-text x-form-field error' : 'textfield x-form-text x-form-field'">
 </template>
 </div>
 </td>
 </tr>
 </template>
 </tbody>
 </table>

 <br>

 <?php echo $this->runChild('manager.parts.buttonPrimary', [
 'text' => __('manager.save'), 
 'style' => '',
 'click' => '',
 'type' => 'submit',
 ]); ?>
 
 <?php echo $this->runChild('manager.parts.button', [
 'text' => __('manager.close'), 
 'style' => 'margin-left: 20px;',
 'click' => 'hide()',
 'type' => 'button',
 ]); ?>

 <?php echo $this->runChild('manager.parts.buttonDelete', [
 'style' => 'margin-left: 20px;',
 'click' => 'remove("coupon", data.id)'
 ]); ?>
 </form>
 </div>
 </div>
 </div>
 </div>
<?php $this->stopSection(); ?>

<?php if (isset($_shouldextend[1])) { echo $this->runChild('manager.layouts.main'); } ?>