<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- Public legacy trigger hooks are retained for extension compatibility.

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

// echo plugin_dir_path(dirname(dirname(__FILE__))) .'PopupManager/class-instant-popup-builder-manager.php';
use InstantPopupBuildr\Admin\PopupBuilder\Trigger\Class_instant_popup_builder_trigger;

$pages = get_pages();

$instant_popup_builder_is_trigger = get_option('instant_popup_builder_exit');

$instant_popup_builder_trigger_options = Class_instant_popup_builder_trigger::get_trigger_options();
$instant_popup_builder_has_exit_intent = array_key_exists('exit-intent', $instant_popup_builder_trigger_options);
$instant_popup_builder_has_scroll_trigger = array_key_exists('scroll-trigger', $instant_popup_builder_trigger_options);
$instant_popup_builder_has_woo_trigger = array_key_exists('woocommerce-trigger', $instant_popup_builder_trigger_options);
$instant_popup_builder_has_adblock = array_key_exists('adblock-trigger', $instant_popup_builder_trigger_options);
$instant_popup_builder_has_inactivity = array_key_exists('inactivity-trigger', $instant_popup_builder_trigger_options);
// Advanced triggers presence flags
$instant_popup_builder_has_adv_page_depth = array_key_exists('page-depth', $instant_popup_builder_trigger_options);
$instant_popup_builder_has_adv_visibility = array_key_exists('element-visibility', $instant_popup_builder_trigger_options);
$instant_popup_builder_has_adv_referrer = array_key_exists('referrer-trigger', $instant_popup_builder_trigger_options);
$instant_popup_builder_has_adv_form_abandon = array_key_exists('form-abandonment', $instant_popup_builder_trigger_options);
$instant_popup_builder_has_adv_returning = array_key_exists('returning-visitor', $instant_popup_builder_trigger_options);

?>
<img src="<?php echo esc_url(plugin_dir_url(dirname(dirname(__FILE__))) . '/image/info.svg'); ?>" alt="" style="display:none;" id="info_img">
<div class="ipb-section ipb-trigger-settings">
 <div class="ipb-section-header">
    <h3>Trigger Settings</h3>
</div>
<div class="ipb-section-content" data-section="display">
<div class="display_wrapper">
    <div class="display_inner">
        <div class="rules">
            <h2>Trigger</h2>
            <div class="selection">
                <select name="trigger_option" id="trigger_option">
                    <?php foreach ($instant_popup_builder_trigger_options as $instant_popup_builder_index => $instant_popup_builder_options): ?>
                        <option value="<?php echo  esc_attr($instant_popup_builder_index); ?>"><?php echo esc_html($instant_popup_builder_options); ?></option>
                    <?php endforeach; ?>

                    <?php if (!$instant_popup_builder_has_exit_intent): ?>
                        <option value="exit_intent" style="color: gray;">Exit Intent 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_scroll_trigger): ?>
                        <option value="scroll_trigger" style="color: gray;">Scroll Trigger 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_woo_trigger): ?>
                        <option value="woo_disable" style="color: gray;">WooCommerce Trigger 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_adblock): ?>
                        <option value="trigger_adblock" style="color: gray;">Adblock Trigger 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_inactivity): ?>
                        <option value="inactivity_trigger" style="color: gray;">Inactivity Trigger 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_adv_page_depth): ?>
                        <option value="page_depth_pro" style="color: gray;">Page Depth 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_adv_visibility): ?>
                        <option value="element_visibility_pro" style="color: gray;">Element Visibility 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_adv_referrer): ?>
                        <option value="referrer_pro" style="color: gray;">URL / Referrer 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_adv_form_abandon): ?>
                        <option value="form_abandonment_pro" style="color: gray;">Form Abandonment 🔒</option>
                    <?php endif; ?>
                    <?php if (!$instant_popup_builder_has_adv_returning): ?>
                        <option value="returning_visitor_pro" style="color: gray;">Returning Visitor 🔒</option>
                    <?php endif; ?>

                </select>
            </div>
            <div class="trigger_options">
                <div class="fields"><input type="number" placeholder="Delay" name="trigger_delay[]" id="trigger_delay"></div><i class="fa-solid fa-trash"></i>
            </div>

        </div>
        <p class="ipb-trigger-helper">Delay is optional (seconds). Use 0 for immediate display.</p>
         <?php
         do_action('after_trigger_content'); ?>
         <?php do_action('after_scroll_trigger_option'); ?>
         <?php do_action('after_woocommerce_trigger_option'); ?>

    </div>
</div>
</div>
</div>
