<?php

/**
 * Provide a admin area view for the plugin
 *
 * This file is used to markup the admin-facing aspects of the plugin.
 *
 * @link       https://level5.se
 * @since      1.0.0
 *
 * @package    Arena_Scheduler
 * @subpackage Arena_Scheduler/admin/partials
 */

defined('ABSPATH') || exit;
?>

<section class="wrap manage-arena container-fluid pt-3">
    <div class="row">
        <div class="col-lg-8 col-md-8 col-sm-12 mb-3">
            <div class="d-flex justify-content-between align-items-center bg-red mb-3 px-3">
                <h3 class="wp-heading-inline text-white">Arena</h3>
            </div>
            <div class="px-3 py-2 bg-white">
                <div class="d-flex justify-content-end align-items-center">
                    <?php if ($canPerformArenaAction) : ?>
                        <!-- Button to open the Create Modal -->
                        <button type="button" data-bs-toggle="modal" data-bs-target="#createModal" class="btn btn-link action-button add-button pe-0">
                            <img src="<?php echo esc_url($this->plugin_url); ?>/admin/images/AddIcon.svg" alt="Add" />
                            <span class="ps-2 align-text-top">Add</span>
                        </button>
                    <?php endif; ?>
                </div>
                <!-- Loader animation -->
                <div id="loader">
                    <img src="<?php echo esc_url($this->plugin_url); ?>/admin/images/Spin.gif" alt="Loading..." width="68">
                </div>
                <!-- DataTable for displaying arenas -->
                <table id="datatable-toplevel_page_arena-schedule" class="datatable table table-responsive table-bordered border table-striped" style="display: inline-table;">
                    <thead>
                        <tr>
                            <th class="text-center">Number</th>
                            <th class="text-start">Name</th>
                            <th class="text-center">Status</th>
                            <th class="text-center">Default</th>
                            <th class="text-center">Edit</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="col-lg-4 col-md-4 col-sm-12 mb-3">
            <!-- Support card with links to knowledge base and ticket system -->
            <?php echo wp_kses_post($this->arena_scheduler_support_card_html()); ?>
        </div>
    </div>
</section>

<!-- Create Modal -->
<div id="createModal" class="arena-action-modal arena-modern-modal modal fade" tabindex="-1" aria-labelledby="createModalTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <form method="post" id="frmSubmit">
                <div class="modal-header">
                    <h4 class="mb-0">Create Arena</h4>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="form-group mb-4">
                        <label for="name" class="form-label">Arena Name</label>
                        <input type="text" class="form-control" id="name" name="name" placeholder="Enter arena name" required="required" maxlength="30">
                    </div>

                    <div class="form-group mb-4">
                        <label class="form-label">Slot Duration</label>
                        <div class="slot-duration-group d-flex gap-2">
                            <?php if ($canUsePremiumIntervals) : ?>
                                <input type="radio" class="btn-check" name="interval_time" id="interval_15" value="15">
                                <label class="btn btn-outline-slot" for="interval_15">15 min</label>
                                <input type="radio" class="btn-check" name="interval_time" id="interval_30" value="30">
                                <label class="btn btn-outline-slot" for="interval_30">30 min</label>
                            <?php endif; ?>
                            <input type="radio" class="btn-check" name="interval_time" id="interval_60" value="60" checked>
                            <label class="btn btn-outline-slot" for="interval_60">60 min</label>
                        </div>
                    </div>

                    <div class="form-group mb-4">
                        <label class="form-label">Opening Hours</label>
                        <div class="d-flex align-items-center gap-3">
                            <div class="time-select-wrapper flex-fill">
                                <select class="form-select" id="start_time" name="start_time" required="required">
                                    <?php for ($arena_scheduler_h = 0; $arena_scheduler_h <= 23; $arena_scheduler_h++) : ?>
                                        <option value="<?php echo esc_attr( $arena_scheduler_h ); ?>" <?php echo ($arena_scheduler_h === 6) ? 'selected' : ''; ?>><?php echo esc_html( sprintf('%02d:00', $arena_scheduler_h) ); ?></option>
                                    <?php endfor; ?>
                                </select>
                            </div>
                            <span class="time-separator">&ndash;</span>
                            <div class="time-select-wrapper flex-fill">
                                <select class="form-select" id="end_time" name="end_time" required="required">
                                    <?php for ($arena_scheduler_h = 0; $arena_scheduler_h <= 23; $arena_scheduler_h++) : ?>
                                        <option value="<?php echo esc_attr( $arena_scheduler_h ); ?>" <?php echo ($arena_scheduler_h === 22) ? 'selected' : ''; ?>><?php echo esc_html( sprintf('%02d:00', $arena_scheduler_h) ); ?></option>
                                    <?php endfor; ?>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group mb-2">
                        <label for="status" class="form-label">Status</label>
                        <select class="form-select" id="status" name="status" required="required">
                            <option value="1" selected>Active</option>
                            <option value="0">Inactive</option>
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="hidden" name="action" id="action" value="arena_scheduler_create_arena" />
                    <button type="button" class="btn btn-cancel" data-bs-dismiss="modal">Cancel</button>
                    <input type="submit" name="create" id="create" class="btn action-button" value="Save" />
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Update Modal -->
<div id="updateModal" class="arena-action-modal arena-modern-modal modal fade" tabindex="-1" aria-labelledby="updateModalTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <form method="post" id="frmUpdate">
                <div class="modal-header">
                    <h4 class="mb-0">Edit Arena</h4>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="form-group mb-4">
                        <label for="name" class="form-label">Arena Name</label>
                        <input type="text" class="form-control" id="name" name="name" placeholder="Enter arena name" required="required">
                    </div>
                    <div class="form-group mb-4">
                        <label for="status" class="form-label">Status</label>
                        <select class="form-select" id="status" name="status" required="required">
                            <option value="1" selected>Active</option>
                            <option value="0">Inactive</option>
                        </select>
                    </div>
                    <div class="form-group d-flex align-items-center">
                        <input type="checkbox" class="form-check-input mt-0 me-2" name="default" id="default">
                        <label for="default" class="form-check-label mt-0">Set as default</label>
                    </div>
                </div>
                <div class="modal-footer d-flex justify-content-between">
                    <input type="hidden" name="id" id="id" value="" readonly />
                    <input type="hidden" name="action" id="action" value="arena_scheduler_update_arena" readonly />
                    <button type="button" id="delete" class="btn btn-link text-decoration-none action-remove p-0" data-action="arena_scheduler_delete_arena">
                        <img src="<?php echo esc_url($this->plugin_url); ?>/admin/images/DeleteIcon.svg" alt="Delete" />
                        <span class="align-middle ps-1">Delete</span>
                    </button>
                    <div class="d-flex gap-2">
                        <button type="button" class="btn btn-cancel" data-bs-dismiss="modal">Cancel</button>
                        <input type="submit" name="save" id="save" class="btn action-button" value="Save" />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
