<?php
// Exit if accessed directly to ensure security.
if (!defined('ABSPATH')) {
    exit;
}

?>
<div id="iafwzc-content-errorlog" class="iafwzc-tab-content" style="display:none;">

    <span class="iafwzc-span-header"><?php esc_html_e('Logs', 'integrate-any-form-with-zoho-crm'); ?></span>

    <div class="iafwzc-help-icon-wrapper">
        <span class="iafwzc-help-icon">?</span>
        <div class="iafwzc-help-tooltip">
            <p>View and manage errors that occurred while posting data to Zoho CRM or Zoho Bigin. Use this page to identify issues, retry failed submissions, and maintain data accuracy.</p>
        </div>
    </div>
    <?php
    $iafwzc_message = get_transient('iafwzc_error_log_success');

    // If there is a message, display it as an admin notice.
    if ($iafwzc_message) {
        echo '<div class="notice notice-success is-dismissible">
                <p>' . esc_html($iafwzc_message) . '</p>
              </div>';

        // Delete the transient after displaying the message.
        delete_transient('iafwzc_error_log_success');
    }
    // Retrieve the transient.
    $iafwzc_message = get_transient('iafwzc_error_log_fail');

    // If there is a message, display it as an admin notice.
    if ($iafwzc_message) {
        echo '<div class="notice notice-error is-dismissible">
                  <p>' . esc_html($iafwzc_message) . '</p>
                </div>';

        // Delete the transient after displaying the message.
        delete_transient('iafwzc_error_log_fail');
    }
    ?>
    <form id="error-log-form" method="post" action="">
        <?php
        // Add a nonce field for security
        wp_nonce_field('iafwzc_error_log_form_action', 'iafwzc_error_log_form_action_nonce');
        ?>
        <input type="hidden" name="page" value="integrate-any-form-with-zoho-crm">
        <input type="hidden" name="tab" value="errorlog">
        <?php

        // Display the error log table
        $iafwzc_error_log_table = new IAFWZC_Error_Log_Extend();
        $iafwzc_error_log_table->prepare_items(); // Prepare error log table items
        $iafwzc_error_log_table->display();       // Display error log table
        ?>
    </form>

</div>

<div id="iafwzc-error-overlay" class="iafwzc-error-overlay">
    <div class="iafwzc-error-modal">
        <span class="iafwzc-error-close" onclick="iafwzc_closeErrorOverlay()">&times;</span>
        <div id="iafwzc-error-content"></div>
    </div>
</div>