<?php
/**
 * Core notification settings.
 *
 * Advanced templates, previews, samples, reminder timing, and sequences are
 * rendered by the existing NexDirectory Pro add-on through the extension hook
 * at the end of this file.
 *
 * @package NexDirectoryFree
 */

if (!defined('ABSPATH')) {
    exit;
}

$nexdirectory_pro_notifications_enabled = function_exists('nexdirectory_is_pro_feature_enabled')
    && nexdirectory_is_pro_feature_enabled('notification_automation');
$nexdirectory_upgrade_url = method_exists($this, 'get_free_pro_comparison_url')
    ? $this->get_free_pro_comparison_url('notification-automation')
    : admin_url('admin.php?page=nexdirectory-free-vs-pro');
?>
<section class="nexdirectory-settings-panel" id="nexdirectory-tab-notifications-alerts" data-tab="notifications" data-subtab="alerts">
    <h2><?php esc_html_e('Admin & User Alerts', 'nexdirectory'); ?></h2>
    <p class="nexdirectory-settings-subheading"><?php esc_html_e('Choose which essential in-app and transactional alerts are sent by Nex Directory Free.', 'nexdirectory'); ?></p>

    <div class="nexdirectory-settings-grid">
        <div class="nexdirectory-settings-field nexdirectory-full">
            <input type="hidden" id="nexdirectory_enable_pending_admin_notifications" name="nexdirectory_enable_pending_admin_notifications" value="<?php echo esc_attr(((string) $pending_badge_toggle_value === '1' || (string) $pending_email_toggle_value === '1') ? '1' : '0'); ?>">
            <div class="nexdirectory-settings-toggle-list">
                <div class="nexdirectory-settings-toggle-item">
                    <input type="hidden" name="nexdirectory_notify_admin_pending_badge" value="0">
                    <label><input type="checkbox" name="nexdirectory_notify_admin_pending_badge" value="1" <?php checked((string) $pending_badge_toggle_value, '1'); ?>> <?php esc_html_e('Admin dashboard badge for moderation', 'nexdirectory'); ?></label>
                    <p class="description"><?php esc_html_e('Shows the current pending-submission count in the WordPress admin menu.', 'nexdirectory'); ?></p>
                </div>
                <div class="nexdirectory-settings-toggle-item">
                    <input type="hidden" name="nexdirectory_notify_admin_pending_email" value="0">
                    <label><input type="checkbox" name="nexdirectory_notify_admin_pending_email" value="1" <?php checked((string) $pending_email_toggle_value, '1'); ?>> <?php esc_html_e('Email admin about a pending submission', 'nexdirectory'); ?></label>
                    <p class="description"><?php esc_html_e('Sent to the site administration email when a listing enters moderation.', 'nexdirectory'); ?></p>
                </div>
                <div class="nexdirectory-settings-toggle-item">
                    <input type="hidden" name="nexdirectory_notify_admin_claim_email" value="0">
                    <label><input type="checkbox" name="nexdirectory_notify_admin_claim_email" value="1" <?php checked((string) get_option('nexdirectory_notify_admin_claim_email', '1'), '1'); ?>> <?php esc_html_e('Email admin about a claim request', 'nexdirectory'); ?></label>
                    <p class="description"><?php esc_html_e('Sent when a user asks to claim an existing listing.', 'nexdirectory'); ?></p>
                </div>
                <div class="nexdirectory-settings-toggle-item">
                    <input type="hidden" name="nexdirectory_notify_author_confirmation" value="0">
                    <label><input type="checkbox" name="nexdirectory_notify_author_confirmation" value="1" <?php checked((string) get_option('nexdirectory_notify_author_confirmation', '1'), '1'); ?>> <?php esc_html_e('Submission confirmation to listing owner', 'nexdirectory'); ?></label>
                </div>
                <div class="nexdirectory-settings-toggle-item">
                    <input type="hidden" name="nexdirectory_notify_author_update" value="0">
                    <label><input type="checkbox" name="nexdirectory_notify_author_update" value="1" <?php checked((string) get_option('nexdirectory_notify_author_update', '1'), '1'); ?>> <?php esc_html_e('Approval and update email to listing owner', 'nexdirectory'); ?></label>
                </div>
                <div class="nexdirectory-settings-toggle-item">
                    <input type="hidden" name="nexdirectory_notify_author_cancellation" value="0">
                    <label><input type="checkbox" name="nexdirectory_notify_author_cancellation" value="1" <?php checked((string) get_option('nexdirectory_notify_author_cancellation', '1'), '1'); ?>> <?php esc_html_e('Rejection and cancellation email to listing owner', 'nexdirectory'); ?></label>
                </div>
                <div class="nexdirectory-settings-toggle-item">
                    <input type="hidden" name="nexdirectory_notify_extension_potential_owner" value="0">
                    <label><input type="checkbox" name="nexdirectory_notify_extension_potential_owner" value="1" <?php checked((string) get_option('nexdirectory_notify_extension_potential_owner', '0'), '1'); ?>> <?php esc_html_e('Notify a potential owner after a Chrome import', 'nexdirectory'); ?></label>
                </div>
            </div>
        </div>
    </div>
</section>

<?php
/**
 * Renders Pro-owned notification automation inside the established settings
 * journey. Pro registers and sanitizes its own options; Free never deletes them.
 *
 * @param object              $this                    Free core instance.
 * @param array<string,mixed> $email_template_defaults Core fallback templates.
 */
do_action('nexdirectory_render_extension_notification_settings', $this, $email_template_defaults);
?>

<?php if (!$nexdirectory_pro_notifications_enabled) : ?>
    <section class="nexdirectory-settings-panel" id="nexdirectory-tab-notifications-pro" data-tab="notifications" data-subtab="email">
        <div class="nexdirectory-settings-field nexdirectory-full" style="max-width:860px;">
            <span class="nexdirectory-settings-kicker"><?php esc_html_e('NexDirectory Pro', 'nexdirectory'); ?></span>
            <h2><?php esc_html_e('Notification automation', 'nexdirectory'); ?></h2>
            <p class="nexdirectory-settings-subheading"><?php esc_html_e('Create branded email templates, preview the finished message, send a sample, and choose one or more reminder times.', 'nexdirectory'); ?></p>
            <p>
                <a class="button button-primary" href="<?php echo esc_url($nexdirectory_upgrade_url); ?>">
                    <?php esc_html_e('Compare Free & Pro notifications', 'nexdirectory'); ?>
                </a>
            </p>
        </div>
    </section>
<?php endif; ?>
