<?php

if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}

class ISTKR_404View
{
    public static function istkr_render_view()
    {
        require_once realpath(__DIR__) . '/../components/header.tpl.php';
?>
        <div class="container istkr-404-redirects">
            <div class="row">
                <div class="col-md-9">
                    <div class="top-section">
                        <h5><?php _e('Here is a list of all the 404 errors that were detected on your website', 'istkr') ?></h5>
                        <button id="istkr_404_clear_log" class="btn btn-sm btn-outline-danger">Clear all</button>
                    </div>

                    <div class="table-wrapper">
                        <table id="istkr-404-redirects-table" class="display">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Path</th>
                                    <th>Referrer</th>
                                    <th>User Agent</ht>
                                    <th>Hits</th>
                                    <th>IP</th>
                                    <th>Country</th>
                                    <th>First seen</th>
                                    <th>Last seen</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>

                <div class="col-md-3 sidebar">
                    <div class="notifications">
                        <h5><?php _e('Notifications', 'istkr') ?></h5>
                        <?php if (istkr()->is_premium()) {
                            $notificator = new ISTKR_Notificator(new ISTKR_404Controller());
                        ?>

                            <form id="istkr_404_notifications_form" data-notifications-enabled="<?php echo $notificator->istkr_is_notification_enabled() ? 'true' : 'false' ?>">
                                <p><?php _e('You will receive email notifications at this address to the selected interval every time a 404 (Not Found) request is detected', 'istkr'); ?></p>

                                <label for="email"><?php _e('Your Email:', 'istkr') ?></label>
                                <input type="email" id="email" value="<?php echo $notificator->istkr_get_notification_email(); ?>" style="width:100%; margin-top: 10px">

                                <label for="recurrence"><?php _e('Periodicity:', 'istkr') ?></label>
                                <select name="recurrence" id="recurrence" style="width: 100%; margin-top: 10px">
                                    <?php echo $notificator->istkr_get_notification_recurrence(); ?>
                                </select>
                                <?php require_once realpath(__DIR__) . '/../components/send-test-email-checkbox.php'; ?>

                                <input type="submit" value="Loading..." class="btn btn-secondary btn-sm" disabled>
                            </form>
                    </div>
                <?php

                        } else { ?>
                    <p><?php _e('Unlock the power of receiving 404 error notifications by upgrading to our Pro plan', 'istkr'); ?></p>
                    <a class="istkr-pro-features" href="<?php echo istkr()->get_upgrade_url(); ?>">
                        <span><?php _e('Upgrade', 'istkr'); ?></span>
                        <img src="<?php echo  plugin_dir_url(__DIR__) . '../assets/img/corona.png' ?>">
                    </a>
                <?php  } ?>
                </div>
            </div>

            <div class="modal mt-5 user-agent-modal" tabindex="-1">
                <div class="modal-dialog modal-md">
                    <div class="modal-content">
                        <div class="modal-body"></div>
                    </div>
                </div>
            </div>
        </div>
<?php
    }
}
