<?php
if (! defined("\x41\x42\x53\x50\x41\x54\x48")) { exit;  }  function unipixel_page_general_settings() {  $loggingDefaults = array( 'enableLogging_Admin' => false, 'enableLogging_InitiateEvents' => false, 'enableLogging_SendEvents' => false, 'enableGoogleDebugViewClientSide' => false, 'enableGoogleDebugViewServerSide' => false, );  $loggingOptions = get_option('unipixel_logging_options', false); if (false === $loggingOptions) { $loggingOptions = $loggingDefaults; update_option('unipixel_logging_options', $loggingOptions); } $wooEventLabelMap = [ 'AddToCart' => "\x4D\x65\x74\x61", 'add_to_cart' => "\x47\x6F\x6F\x67\x6C\x65", 'InitiateCheckout' => "\x4D\x65\x74\x61", 'begin_checkout' => "\x47\x6F\x6F\x67\x6C\x65", 'Purchase' => "\x4D\x65\x74\x61", 'purchase' => "\x47\x6F\x6F\x67\x6C\x65", 'ViewContent' => "\x4D\x65\x74\x61", 'view_item' => "\x47\x6F\x6F\x67\x6C\x65", ]; ?>
    <div class="UniPixelShell position-relative">
        <div class="d-flex justify-content-between align-items-start">
            <h1 class="mb-0">General Settings</h1>
            <?php unipixel_render_feedback_buttons(); ?>
        </div>

        <!-- Feedback Message Container -->
        <div id="general-settings-feedback-message" class="alert" role="alert" style="display: none;"></div>

        <!-- Loader Element with Spinner -->
        <div id="general-settings-form-loader" class="d-flex justify-content-center align-items-center position-absolute w-100 h-100 d-none" style="top: 0; left: 0; z-index:1000;">
            <div class="spinner-border text-primary" role="status">
                <span class="visually-hidden">Loading...</span>
            </div>
        </div>

        <form id="general-settings-form" class="form-horizontal">

            <?php
 $advancedMatchingEnabled = get_option('unipixel_advanced_matching_enabled', true); ?>

            <hr />
            <h2><i class="fa-solid fa-shield-halved"></i> Advanced Matching</h2>
            <p><small>Sends hashed user data (email, phone, name, address) alongside events to Meta, TikTok and Pinterest to improve Event Match Quality. Data comes from order billing details or logged-in user profiles where available.
                <a href="https://unipixelhq.com/unipixel-docs/advanced-matching-setting-with-unipixel/" target="_blank">Learn more</a></small></p>

            <div class="mb-3 row">
                <div class="col-3 col-sm-3">
                    <label for="advanced_matching_enabled" class="form-check-label">
                        Enable Advanced Matching
                    </label>
                </div>
                <div class="col-9 col-sm-9">
                    <div class="form-check form-switch">
                        <input type="checkbox"
                            id="advanced_matching_enabled"
                            name="advanced_matching_enabled"
                            value="1"
                            class="form-check-input"
                            <?php checked($advancedMatchingEnabled, true); ?>>
                    </div>
                </div>
            </div>

            <?php
 $dbstoreSettings = unipixel_get_dbstore_event_settings(); ?>

            <hr />
            <h2><i class="fa-solid fa-database"></i> Store Records of Events to Database</h2>
            <p><small>Choose which types of events should be persisted to the database for review, insights and debugging. Covers all events from all visitors.</small></p>

            <!-- PageView Events -->
            <div class="mb-3 row">
                <div class="col-3 col-sm-3">
                    <label for="dbstore_pageview_events" class="form-check-label">
                        Store PageView Events
                    </label>
                </div>
                <div class="col-9 col-sm-9">
                    <div class="form-check form-switch">
                        <input type="checkbox"
                            id="dbstore_pageview_events"
                            name="dbstore_pageview_events"
                            value="1"
                            class="form-check-input"
                            <?php checked($dbstoreSettings["\x64\x62\x73\x74\x6F\x72\x65\x5F\x70\x61\x67\x65\x76\x69\x65\x77\x5F\x65\x76\x65\x6E\x74\x73"], true); ?>>
                    </div>
                </div>
            </div>

            <!-- Custom Events -->
            <div class="mb-3 row">
                <div class="col-3 col-sm-3">
                    <label for="dbstore_custom_events" class="form-check-label">
                        Store Site Events
                    </label>
                </div>
                <div class="col-9 col-sm-9">
                    <div class="form-check form-switch">
                        <input type="checkbox"
                            id="dbstore_custom_events"
                            name="dbstore_custom_events"
                            value="1"
                            class="form-check-input"
                            <?php checked($dbstoreSettings["\x64\x62\x73\x74\x6F\x72\x65\x5F\x63\x75\x73\x74\x6F\x6D\x5F\x65\x76\x65\x6E\x74\x73"], true); ?>>
                    </div>
                </div>
            </div>

            <!-- WooCommerce Events -->

            <div><b>Store WooCommerce Events</b></div>
            <p><small>Select which WooCommerce events should be stored in the database. These may include variants like Meta vs Google naming.</small></p>

            <div class="row">
                <?php foreach ($dbstoreSettings["\x64\x62\x73\x74\x6F\x72\x65\x5F\x77\x6F\x6F\x63\x6F\x6D\x6D\x65\x72\x63\x65\x5F\x65\x76\x65\x6E\x74\x73"] as $eventKey => $isEnabled): ?>
                    <div class="col-12 col-md-4 mb-3">
                        <div class="d-flex align-items-center">
                            <div class="form-check form-switch">
                                <input type="checkbox"
                                    id="woo_<?php echo esc_attr($eventKey); ?>"
                                    name="dbstore_woocommerce_events[<?php echo esc_attr($eventKey); ?>]"
                                    value="1"
                                    class="form-check-input"
                                    <?php checked($isEnabled, true); ?>>
                            </div>
                            <label for="woo_<?php echo esc_attr($eventKey); ?>" class="form-check-label ms-2">
                                <?php
 echo esc_html($eventKey); if (!empty($wooEventLabelMap[$eventKey])) { echo "\x20\x3C\x73\x6D\x61\x6C\x6C\x20\x63\x6C\x61\x73\x73\x3D\x22\x74\x65\x78\x74\x2D\x6D\x75\x74\x65\x64\x22\x3E\x28" . esc_html($wooEventLabelMap[$eventKey]) . ')</small>'; } ?>
                            </label>

                        </div>
                    </div>
                <?php endforeach; ?>
            </div>

            <div class="browserConsoleSettings obsolete d-none">

                <hr />
                <h2>Log Event Info to the Browser Console</h2>
                <p><small>Toggle these settings to get information on what's happening behind the scenes. Several processes can be viewed in your Browser's "Console Log"</small></p>
                <!-- Admin Logging Option -->
                <div class="mb-3 row d-none">
                    <div class="col-3 col-sm-3">
                        <label for="enableLogging_Admin" class="form-check-label">
                            Admin Logging <?php echo unipixel_get_help_icon("\x4C\x6F\x67\x67\x69\x6E\x67\x5F\x41\x64\x6D\x69\x6E"); ?>
                        </label>
                    </div>
                    <div class="col-9 col-sm-9">
                        <div class="form-check form-switch">
                            <input type="checkbox"
                                id="enableLogging_Admin"
                                name="enableLogging_Admin"
                                value="1"
                                class="form-check-input"
                                <?php checked($loggingOptions["\x65\x6E\x61\x62\x6C\x65\x4C\x6F\x67\x67\x69\x6E\x67\x5F\x41\x64\x6D\x69\x6E"], true); ?>>
                        </div>
                    </div>
                </div>
                <!-- Initiate Events Logging Option -->
                <div class="mb-3 row">
                    <div class="col-3 col-sm-3">
                        <label for="enableLogging_InitiateEvents" class="form-check-label">
                            See Initiation (Setup) of Site Events <?php echo unipixel_get_help_icon("\x4C\x6F\x67\x67\x69\x6E\x67\x5F\x49\x6E\x69\x74\x69\x61\x74\x65\x45\x76\x65\x6E\x74\x73"); ?>
                        </label>
                    </div>
                    <div class="col-9 col-sm-9">
                        <div class="form-check form-switch">
                            <input type="checkbox"
                                id="enableLogging_InitiateEvents"
                                name="enableLogging_InitiateEvents"
                                value="1"
                                class="form-check-input"
                                <?php checked($loggingOptions["\x65\x6E\x61\x62\x6C\x65\x4C\x6F\x67\x67\x69\x6E\x67\x5F\x49\x6E\x69\x74\x69\x61\x74\x65\x45\x76\x65\x6E\x74\x73"], true); ?>>
                        </div>
                    </div>
                </div>
                <!-- Send Events Logging Option -->
                <div class="mb-3 row">
                    <div class="col-3 col-sm-3">
                        <label for="enableLogging_SendEvents" class="form-check-label">
                            See Details of Events Sent <?php echo unipixel_get_help_icon("\x4C\x6F\x67\x67\x69\x6E\x67\x5F\x53\x65\x6E\x64\x45\x76\x65\x6E\x74\x73"); ?>
                        </label>
                    </div>
                    <div class="col-9 col-sm-9">
                        <div class="form-check form-switch">
                            <input type="checkbox"
                                id="enableLogging_SendEvents"
                                name="enableLogging_SendEvents"
                                value="1"
                                class="form-check-input"
                                <?php checked($loggingOptions["\x65\x6E\x61\x62\x6C\x65\x4C\x6F\x67\x67\x69\x6E\x67\x5F\x53\x65\x6E\x64\x45\x76\x65\x6E\x74\x73"], true); ?>>
                        </div>
                    </div>
                </div>
            </div>

            <hr />
            <h2><i class="fa-brands fa-google"></i> Google's DebugView</h2>
            <p><small>Google allows you to see incoming events in real time if you tag events with a "debug" flag. You can setup your outgoing Google events to do this below.</small></p>
            <!-- DebugView Toggle -->
            <div class="mb-3 row">
                <div class="col-3 col-sm-3">
                    <label for="enableGoogleDebugViewClientSide" class="form-check-label">
                        Enable Google DebugView (Client Side Events) <?php echo unipixel_get_help_icon("\x44\x65\x62\x75\x67\x56\x69\x65\x77\x43\x6C\x69\x65\x6E\x74"); ?> <br />
                        <small>Note for GTM: <?php echo unipixel_get_help_icon("\x47\x6F\x6F\x67\x6C\x65\x5F\x44\x65\x62\x75\x67\x5F\x56\x69\x65\x77\x5F\x43\x6C\x69\x65\x6E\x74\x53\x69\x64\x65\x5F\x47\x74\x6D\x4E\x6F\x74\x65"); ?></small>
                    </label>
                </div>
                <div class="col-9 col-sm-9">
                    <div class="form-check form-switch">
                        <input
                            type="checkbox"
                            id="enableGoogleDebugViewClientSide"
                            name="enableGoogleDebugViewClientSide"
                            value="1"
                            class="form-check-input"
                            <?php checked($loggingOptions["\x65\x6E\x61\x62\x6C\x65\x47\x6F\x6F\x67\x6C\x65\x44\x65\x62\x75\x67\x56\x69\x65\x77\x43\x6C\x69\x65\x6E\x74\x53\x69\x64\x65"], true); ?>>
                    </div>
                </div>
            </div>
            <div class="mb-3 row">
                <div class="col-3 col-sm-3">
                    <label for="enableGoogleDebugViewServerSide" class="form-check-label">
                        Enable Google DebugView (Server Side Events) <?php echo unipixel_get_help_icon("\x44\x65\x62\x75\x67\x56\x69\x65\x77\x53\x65\x72\x76\x65\x72"); ?>
                    </label>
                </div>
                <div class="col-9 col-sm-9">
                    <div class="form-check form-switch">
                        <input
                            type="checkbox"
                            id="enableGoogleDebugViewServerSide"
                            name="enableGoogleDebugViewServerSide"
                            value="1"
                            class="form-check-input"
                            <?php checked($loggingOptions["\x65\x6E\x61\x62\x6C\x65\x47\x6F\x6F\x67\x6C\x65\x44\x65\x62\x75\x67\x56\x69\x65\x77\x53\x65\x72\x76\x65\x72\x53\x69\x64\x65"], true); ?>>
                    </div>
                </div>
            </div>
            <!-- Submit Button -->
            <hr />
            <div class="mb-3 row">
                <div class="col-sm-12">
                    <input type="submit" value="Save Settings" class="btn btn-primary">
                </div>
            </div>
        </form>
    </div>
<?php
} ?>