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

// Fetch and sanitize options from the database
$error_notification = get_option('integrazo_wczo_error_notification', 'no') === 'yes' ? 'yes' : 'no';
$error_notification_email = sanitize_text_field(get_option('integrazo_wczo_error_notification_email', ''));
$error_notification_subject = sanitize_text_field(get_option('integrazo_wczo_error_notification_subject', ''));
?>

<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
    <?php wp_nonce_field('integrazo_wczo_save_notifications_settings', 'integrazo_wczo_save_notifications_settings_nonce'); ?>

    <table class="form-table">
        <!-- Enable Error Notification -->
        <tr>
            <th scope="row">
                <label for="integrazo_wczo_error_notification"><?php esc_html_e('Enable Error Notifications', 'integrazo-wc-zoho-integration'); ?></label>
                <div class="integrazo-wczo-helpicon-help-icon-wrapper">
                    <span class="integrazo-wczo-helpicon-help-icon">?</span>
                    <div class="integrazo-wczo-helpicon-help-tooltip">
                        <p><?php esc_html_e('Receive email alerts when a data sync fails due to an error. Set recipient emails and customize the subject line.', 'integrazo-wc-zoho-integration'); ?></p>
                    </div>
                </div>
            </th>
            <td>
                <input type="checkbox" id="integrazo_wczo_error_notification" name="integrazo_wczo_error_notification" value="yes" <?php checked($error_notification, 'yes'); ?> />
                <span><?php esc_html_e('Send me email alerts for errors', 'integrazo-wc-zoho-integration'); ?></span>
            </td>
        </tr>

        <!-- Notification Email Address -->
        <tr>
            <th scope="row">
                <label for="integrazo_wczo_error_notification_email"><?php esc_html_e('Notification Email(s)', 'integrazo-wc-zoho-integration'); ?></label>
            </th>
            <td>
                <input type="text" id="integrazo_wczo_error_notification_email" name="integrazo_wczo_error_notification_email" value="<?php echo esc_attr($error_notification_email); ?>" class="regular-text" />
                <p class="description"><?php esc_html_e('Enter email addresses separated by commas.', 'integrazo-wc-zoho-integration'); ?></p>
            </td>
        </tr>

        <!-- Notification Email Subject -->
        <tr>
            <th scope="row">
                <label for="integrazo_wczo_error_notification_subject"><?php esc_html_e('Email Subject', 'integrazo-wc-zoho-integration'); ?></label>
            </th>
            <td>
                <input type="text" id="integrazo_wczo_error_notification_subject" name="integrazo_wczo_error_notification_subject" value="<?php echo esc_attr($error_notification_subject); ?>" class="regular-text" />
                <p class="description"><?php esc_html_e('Enter the subject line for error notification emails.', 'integrazo-wc-zoho-integration'); ?></p>
            </td>
        </tr>
    </table>

    <input type="hidden" name="action" value="integrazo_wczo_save_notifications_settings">
    <?php submit_button(__('Save Settings', 'integrazo-wc-zoho-integration')); ?>
</form>