<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- Legacy callback name is retained for extension compatibility.

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

$pages = get_pages();

// var_dump($pages);

$instant_popup_builder_woocommerce_option =  get_option('instant_popup_woocommerce');

add_action('plugins_loaded', 'callback_function_wc_extention');

function callback_function_wc_extention() {
    if (function_exists('instant_woo_popup_display_option')) {

        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- instant_woo_popup_display_option() returns safe, sanitized HTML

        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- instant_woo_popup_display_option() returns safe, sanitized HTML
        echo instant_woo_popup_display_option();

    }
}
?>
<div class="ipb-section ipb-display-rules">
 <div class="ipb-section-header">
    <h3>Display Rules</h3>
</div>
<div class="ipb-section-content" data-section="display">

<div class="trigger_wrapper">

    <div class="trigger_inner">

        <div class="rules">

            <h2>Display</h2>

            <div class="selection">

                <select name="page" id="page">

                    <option value="everywhere">Everywhere</option>

                    <option value="post">Post</option>

                    <option value="page">Page</option>

                    <option value="tags">Tags</option>

                    <?php if ($instant_popup_builder_woocommerce_option == 'no' || !$instant_popup_builder_woocommerce_option): ?>

                        <option value="woo_disable" style="color: gray;">Woocommerce 🔒</option>

                    <?php endif; ?>

                    <?php  if($instant_popup_builder_woocommerce_option == 'yes'):

                    if (function_exists('callback_function_wc_extention')) {

                        callback_function_wc_extention();

                    }

                    endif; ?>

                </select>

            </div>

            <div class="plus">

                <i class="fa-solid fa-circle-plus"></i>

            </div>

        </div>

        <p class="ipb-display-helper">Select where this popup should appear. Add multiple rules with (+).</p>

        <div class="form_fields">

            <input type="hidden" name="selected_option[]" value="everywhere">
            <input type="hidden" name="is_display[]" value="yes">
            <input type="hidden" name="spec_val[0][]" value="everywhere">

        </div>

        <div id="display_woocommerce">

             <?php

            if ($instant_popup_builder_woocommerce_option == 'yes'){

                if ( function_exists( 'ipb_popup_woocommerce_load_footer_html' ) ) {

                $instant_popup_builder_template_path = ipb_popup_woocommerce_load_footer_html( 'popup_woocommerce_display_html.php' );



                if ( $instant_popup_builder_template_path ) {



                    ob_start();

                    include $instant_popup_builder_template_path;

                    $instant_popup_builder_html = ob_get_clean();

                   // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $instant_popup_builder_html contains trusted template output

                    // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $instant_popup_builder_html contains trusted template output
                    echo $instant_popup_builder_html;

                }

            }

            }

           ?>

        </div>

    </div>

</div>

</div>

</div>
