<?php
include 'includ/header.php';
?>
        <div class="container grid px-6 mx-auto ">


            <a style="font-size: 20px"
               class="text-xs font-semibold tracking-wide text-left text-gray-500 0 dark:text-gray-400 inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
            >
                <svg id="Layer_1" height="21" viewBox="0 0 24 24" width="21" fill="gray"
                     xmlns="http://www.w3.org/2000/svg" data-name="Layer 1">
                    <path d="m24 12a1 1 0 0 1 -2 0 10.011 10.011 0 0 0 -10-10 1 1 0 0 1 0-2 12.013 12.013 0 0 1 12 12zm-8 1a1 1 0 0 0 0-2h-2.277a2 2 0 0 0 -.723-.723v-3.277a1 1 0 0 0 -2 0v3.277a1.994 1.994 0 1 0 2.723 2.723zm-14.173-6.216a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm.173 5.216a1 1 0 1 0 -1 1 1 1 0 0 0 1-1zm10 10a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm-7.779-18.793a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm3.558-2.366a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm-5.952 14.375a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm2.394 3.577a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm3.558 2.366a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm14.394-5.943a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm-2.394 3.577a1 1 0 1 0 1 1 1 1 0 0 0 -1-1zm-3.558 2.366a1 1 0 1 0 1 1 1 1 0 0 0 -1-1z"/>
                </svg>

                <span class="ml-4"><?php echo $_LANG['Volumetitle']?></span>
                <span class="ml-4 justify-end inline-flex">
                          <button @click="openModal"
                                  class=" text-sm font-medium leading-5 text-white transition-colors duration-150 border border-transparent rounded-lg focus:outline-none ">
                          <img src="icons/add.svg" width="30px">
                          </button>
                    </span>
                <?php session_notif_wizwiz() ?>
            </a>


            <div style='margin-top:40px'  class="grid gap-6 mb-8 xl:grid-cols-4 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-2">
                <?php
                discounts_delete($conn);

                $discounts_select = discounts_select($conn);
                if (is_array($discounts_select) || is_object($discounts_select)) {
                    foreach ($discounts_select
                             as $value):
                        $timestamp = $value["expire_date"];
                        $date = jdate('Y-m-d', $timestamp);
                        ?>

                        <div class="shadow-sm rounded-2xl bg-white dark:bg-gray-800 p-4 ">
                            <div class="flex-row gap-8 flex justify-center items-center">
                                <div class=" flex flex-col">
            <span style="font-weight: bold" class="text-lg text-left font-medium text-gray-600 dark:text-white ">
                <?php echo $value['hash_id']; ?>
            </span>
                                    <span class="text-xs text-gray-700 mt-2 text-left dark:hover:text-gray-200 dark:text-gray-100">
                <?php
                if ($timestamp == '0') {
                    echo '<p class="mt-2" style="font-size: 13px">Expiry-date:<span style="color: #ef233c;"> 0 </span></p>';
                } else {
                    echo '<p class="mt-2" style="font-size: 13px">Expiry-date: <span style="color: #38b000;">' . $date . ' </span></p>';
                }
                if ($value["expire_count"] == '0') {
                    echo '<p class="mt-2" style="font-size: 13px">Expiry-count:<span style="color: #ef233c;"> 0</span></p>';
                } else {
                    echo '<p class="mt-2" style="font-size: 13px">Expiry-count: <span style="color: #38b000;">' . $value["expire_count"] . '</span></p>';
                }
                if ($value["can_use"] == '0') {
                    echo '<p class="mt-2" style="font-size: 13px">can_use:<span style="color: #ef233c;"> 0</span></p>';
                } else {
                    echo '<p class="mt-2" style="font-size: 13px">can_use: <span style="color: #38b000;">' . $value["can_use"] . '</span></p>';
                }
                if ($value["type"] == 'amount') {
                    echo '<p class="mt-2 " style="font-size: 13px">Price:<span style="color: #38b000;"> ' . $value["amount"] . 'T </span></p>';
                } else {
                    echo '<p class="mt-2" style="font-size: 13px">Percent:<span style="color: #38b000;"> ' . $value["amount"] . '% </span></p>';
                }
                ?>
            </span>
                                </div>
                                <a id="ts-error" href="discount.php?delete=<?php echo $value['id']; ?>">
                                    <button type="button" name="delete_category"
                                            style="background-color: #fbe9ed;color:#c6030c;width: 50px"
                                            class="mx-auto py-2 px- text-white w-full transition ease-in duration-200 text-center text-base font-semibold focus:outline-none focus:ring-2 focus:ring-offset-2  rounded-lg ">
                                        <svg style="width: 20px;" class="mx-auto" aria-hidden="true" fill="currentColor"
                                             viewBox="0 0 20 20">
                                            <path fill-rule="evenodd"
                                                  d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z"
                                                  clip-rule="evenodd"></path>
                                        </svg>
                                    </button>
                                </a>
                            </div>
                        </div>
                    <?php
                    endforeach;
                }
                ?>
            </div>


        </div>


    </main>
</div>
</div>


<!-- Modal backdrop. This what you want to place close to the closing body tag -->
<div
        x-show="isModalOpen"
        x-transition:enter="transition ease-out duration-150"
        x-transition:enter-start="opacity-0"
        x-transition:enter-end="opacity-100"
        x-transition:leave="transition ease-in duration-150"
        x-transition:leave-start="opacity-100"
        x-transition:leave-end="opacity-0"
        class="fixed inset-0 z-30 flex items-end bg-black bg-opacity-30 sm:items-center sm:justify-center"
>
    <!-- Modal -->
    <div
            x-show="isModalOpen"
            x-transition:enter="transition ease-out duration-150"
            x-transition:enter-start="opacity-0 transform translate-y-1/2"
            x-transition:enter-end="opacity-100"
            x-transition:leave="transition ease-in duration-150"
            x-transition:leave-start="opacity-100"
            x-transition:leave-end="opacity-0  transform translate-y-1/2"
            @click.away="closeModal"
            @keydown.escape="closeModal"
            class="w-full px-6 py-4 overflow-hidden bg-white rounded-t-lg dark:bg-gray-800 sm:rounded-lg sm:m-4 sm:max-w-xl"
            role="dialog"
            id="modal"
    >
        <!-- Remove header if you don't want a close icon. Use modal body to place modal tile. -->
        <header class="flex justify-end">
            <button
                    class="inline-flex items-center justify-center w-6 h-6 text-gray-400 transition-colors duration-150 rounded dark:hover:text-gray-200 hover: hover:text-gray-700"
                    aria-label="close"
                    @click="closeModal"
            >
                <svg
                        class="w-4 h-4"
                        fill="currentColor"
                        viewBox="0 0 20 20"
                        role="img"
                        aria-hidden="true"
                >
                    <path
                            d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
                            clip-rule="evenodd"
                            fill-rule="evenodd"
                    ></path>
                </svg>
            </button>
        </header>
        <?php
        discounts_insert($conn);
        ?>
        <form id="insert_discount">
            <!-- Modal body -->
            <div class="mt-4 mb-6">
                <!-- Modal title -->
                <p class="m-2 text-lg font-semibold text-gray-700 dark:text-gray-300">
                    <?php echo $_LANG['adddiscounts']?>
                </p>
                <p style="font-size: 14px; color: #d81159" class="mt-2">
                    <?php echo $_LANG['tozih']?>
                </p>
                <label class="block mt-5 text-sm mx-auto">
                    <select required name="category_discounts"
                            class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray">
                        <option value="amount"><?php echo $_LANG['price']?></option>
                        <option value="percent"><?php echo $_LANG['percent']?></option>
                    </select>
                </label>

                <div class="flex relative mt-4">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                        <?php echo $_LANG['pricepercent']?>
                    </span>
                    <input required name="percent_discounts" style="font-size: 14px;" type="number" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-blue-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           name="url" placeholder="Write a name for the category..."/>
                </div>
                <div class="flex relative mt-4">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                       <?php echo $_LANG['expiredate']?>
                    </span>
                    <input required name="discounts_date" style="font-size: 14px;" type="number" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-blue-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           name="url" placeholder="Write a name for the category..."/>
                </div>
                <div class="flex relative mt-4">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                        <?php echo $_LANG['expirecount']?>
                    </span>
                    <input required name="discounts_count" style="font-size: 14px;" type="number" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-blue-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           name="url" placeholder="Write a name for the category..."/>
                </div>
                <div class="flex relative mt-4">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                        <?php echo $_LANG['can_use']?>
                    </span>
                    <input required name="discounts_can_use" style="font-size: 14px;" type="number" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-blue-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           name="url" placeholder="Write a name for the category..."/>
                </div>
            </div>
            <footer class="flex flex-col items-center justify-end px-6 py-3 -mx-6 -mb-4 space-y-4 sm:space-y-0 sm:space-x-6 sm:flex-row bg-gray-50 dark:bg-gray-800">
                <button name="add_discount" type="submit" @click="closeModal"
                        class="w-full px-5 py-3 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-green-600 border border-transparent rounded-lg sm:w-auto sm:px-4 sm:py-2 active:bg-purple-600 hover:bg-green-700 focus:outline-none focus:shadow-outline-green">
                    <?php echo $_LANG['add']?>
                </button>
            </footer>
        </form>
<?php
include 'includ/footer.php';
?>
