<?php
$assets_root_tab1 = plugin_dir_url(__FILE__);
$check = tm_12_check_license();
?>

<link href="<?= $assets_root_tab1 ?>style.css?v=<?= ASSETS_VERSION ?>" rel="stylesheet">

<div id="sport-plugin-tab4"
     class="sport-plugin-tab-panel <?php echo isset($_GET['tab']) && $_GET['tab'] === 'sport-plugin-tab4' ? 'active' : ''; ?>">
    <div>
        <?php if ($check['status']): ?>
            <div>
                <?php if (isset($_GET['license_status'], $_GET['message']) && $_GET['license_status'] === 'success' && $_GET['message']) : ?>
                    <div class="notice notice-success is-dismissible">
                        <p><?php echo $_GET['message'] ?? '' ?></p>
                    </div>
                <?php endif; ?>
                <h2><?php _e('Thông tin mã bản quyền', 'sport'); ?></h2>
                <div><?php echo $check['license_info']['key']; ?></div>
                <hr>
                <div>
                    <h4 style="margin-bottom: 2px"><?php _e('Địa chỉ Email', 'sport'); ?></h4>
                    <div><?php echo $check['license_info']['email']; ?></div>
                    <h4 style="margin-bottom: 2px"><?php _e('Ngày hết hạn', 'sport'); ?></h4>
                    <div><?php $date = new DateTime($check['license_info']['end_date']);
                        echo $date->format('d/m/Y H:i:s'); ?></div>
                    <br>
                    <form method="post">
                        <input type="hidden" name="active_tab"
                               value="<?php echo isset($_GET['tab']) ? esc_attr($_GET['tab']) : 'sport-plugin-tab4'; ?>">

                        <?php wp_nonce_field('bongdako_settings_save', 'bongdako_nonce'); ?>
                        <input type="hidden" name="my_plugin_license_key"
                               value="" class="regular-text">

                        <button class="button button-secondary" type="submit" name="bongdako_submit_key">
                            <?php _e('Đăng xuất', 'sport'); ?>
                        </button>
                    </form>

                </div>
            </div>

        <?php else: ?>
            <form method="post" id="r1" style="display: none">
                <input type="hidden" name="active_tab"
                       value="<?php echo isset($_GET['tab']) ? esc_attr($_GET['tab']) : 'sport-plugin-tab4'; ?>">

                <?php wp_nonce_field('bongdako_settings_save', 'bongdako_nonce'); ?>
                <h2><?php _e('Đăng ký giấy phép hoạt động', 'sport'); ?></h2>

                <div id="result">
                    <?php if (isset($_GET['license_status'], $_GET['message']) && $_GET['license_status'] === 'success' && $_GET['message']) : ?>
                        <div class="notice notice-success is-dismissible">
                            <p><?php echo $_GET['message'] ?? '' ?></p>
                        </div>
                    <?php endif; ?>
                    <?php if (isset($_GET['license_status'], $_GET['message']) && $_GET['license_status'] === 'error' && $_GET['message']) : ?>
                        <div class="notice notice-error is-dismissible">
                            <p><?php echo $_GET['message'] ?? '' ?></p>
                        </div>
                    <?php endif; ?>
                </div>
                <table class="form-table" role="presentation">
                    <tbody>
                    <tr>
                        <th scope="row"><?php _e('Địa chỉ Email', 'sport'); ?></th>
                        <td><input type="email" name="email"
                                   id="elEmail" placeholder="<?php _e('Nhập địa chỉ Email', 'sport'); ?>"
                                   class="regular-text">

                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <button type="button" id="registerLicenseBtn" name="bongdako_submit_key"
                                    class="button button-primary">
                                <?php _e('Đăng ký', 'sport'); ?>
                            </button>
                            <p><?php _e('Bạn đã có mã bản quyền chưa?', 'sport'); ?> <a href="#"
                                                                                         id="changeActive"><?php _e('Đăng ký ở đây', 'sport'); ?></a>
                            </p>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </form>
            <form method="post" id="r2" class="">
                <input type="hidden" name="active_tab"
                       value="<?php echo isset($_GET['tab']) ? esc_attr($_GET['tab']) : 'sport-plugin-tab5'; ?>">

                <?php wp_nonce_field('bongdako_settings_save', 'bongdako_nonce'); ?>
                <h2><?php _e('Nhập mã bản quyền cấp phép của bạn bên dưới:', 'sport'); ?></h2>
                <?php if (isset($_GET['license_status'], $_GET['message']) && $_GET['license_status'] === 'success' && $_GET['message']) : ?>
                    <div class="notice notice-success is-dismissible">
                        <p><?php echo $_GET['message'] ?? '' ?></p>
                    </div>
                <?php endif; ?>
                <?php if (isset($_GET['license_status'], $_GET['message']) && $_GET['license_status'] === 'error' && $_GET['message']) : ?>
                    <div class="notice notice-error is-dismissible">
                        <p><?php echo $_GET['message'] ?? '' ?></p>
                    </div>
                <?php endif; ?>
                <table class="form-table" role="presentation">
                    <tbody>
                    <tr>
                        <th scope="row"><?php _e('Mã bản quyền', 'sport'); ?></th>
                        <td><input required type="text" name="my_plugin_license_key"
                                   placeholder="<?php _e('Nhập mã bản quyền', 'sport'); ?>"
                                   value="<?php echo get_option('my_plugin_license_key'); ?>" class="regular-text">
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <input type="submit" name="bongdako_submit_key" id="submit" class="button button-primary"
                                   value="<?php _e('Kích hoạt', 'sport'); ?>">
                            <p><a href="#" id="changeActive2"><?php _e('Đăng ký mã mới', 'sport'); ?></a></p>
                        </td>

                    </tr>
                    </tbody>
                </table>
            </form>
        <?php endif; ?>

    </div>
</div>
<script src="<?= $assets_root_tab1 ?>js.js?v=<?= ASSETS_VERSION ?>"></script>