<?php
if (! defined("\x41\x42\x53\x50\x41\x54\x48")) exit;  function unipixel_home_page() { global $wpdb; $platform_table = $wpdb->prefix . "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x70\x6C\x61\x74\x66\x6F\x72\x6D\x5F\x73\x65\x74\x74\x69\x6E\x67\x73"; $log_table = $wpdb->prefix . "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x65\x76\x65\x6E\x74\x5F\x6C\x6F\x67";  $query = $wpdb->prepare(  "SELECT * FROM %i WHERE id = %d", $platform_table, 1 );  $meta_settings = $wpdb->get_row($query, ARRAY_A);  $query = $wpdb->prepare(  "SELECT * FROM %i WHERE id = %d", $platform_table, 2 );  $pinterest_settings = $wpdb->get_row($query, ARRAY_A);  $query = $wpdb->prepare(  "SELECT * FROM %i WHERE id = %d", $platform_table, 3 );  $tiktok_settings = $wpdb->get_row($query, ARRAY_A);  $query = $wpdb->prepare(  "SELECT * FROM %i WHERE id = %d", $platform_table, 4 );  $google_settings = $wpdb->get_row($query, ARRAY_A);  $is_meta_setup = !empty($meta_settings["\x70\x69\x78\x65\x6C\x5F\x69\x64"]) && !empty($meta_settings["\x61\x63\x63\x65\x73\x73\x5F\x74\x6F\x6B\x65\x6E"]); $is_pinterest_setup = !empty($pinterest_settings["\x70\x69\x78\x65\x6C\x5F\x69\x64"]) && !empty($pinterest_settings["\x61\x64\x64\x69\x74\x69\x6F\x6E\x61\x6C\x5F\x69\x64"]) && !empty($pinterest_settings["\x61\x63\x63\x65\x73\x73\x5F\x74\x6F\x6B\x65\x6E"]); $is_tiktok_setup = !empty($tiktok_settings["\x70\x69\x78\x65\x6C\x5F\x69\x64"]) && !empty($tiktok_settings["\x61\x63\x63\x65\x73\x73\x5F\x74\x6F\x6B\x65\x6E"]); $is_google_setup = !empty($google_settings["\x70\x69\x78\x65\x6C\x5F\x69\x64"]) && !empty($google_settings["\x61\x63\x63\x65\x73\x73\x5F\x74\x6F\x6B\x65\x6E"]);  $query = $wpdb->prepare(  "SELECT * FROM %i ORDER BY log_time DESC LIMIT %d", $log_table, 40 );  $logs = $wpdb->get_results($query, ARRAY_A); ?>
    <div class="UniPixelShell position-relative pt-4">

        <div class="row mb-4">
            <div class="col-6">
                <img src="<?php echo esc_url(plugin_dir_url(__FILE__) . 'img/unipixel-logo-landscape-3.svg'); ?>" alt="UniPixel Logo" style="width:330px" class="img-fluid">
            </div>
            <div class="col-6 d-flex justify-content-end align-items-start">
                <?php unipixel_render_feedback_buttons(); ?>
            </div>
        </div>

        <div class="row">

            <!-- META -->
            <div class="col-md-6 col-lg-3 mb-4">
                <?php if ($is_meta_setup) : ?>
                    <div class="card bg-light-green borderless w-100 h-100">
                        <div class="card-body pb-0">
                            <h1>Pixel for Meta (Facebook)</h1>
                            <p>Manage Meta pixel with Conversions API, including site events.</p>
                            <a href="<?php echo esc_url(menu_page_url("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x6D\x65\x74\x61", false)); ?>" class="btn btn-primary">View Pixel Setup</a>
                        </div>
                    </div>
                <?php else : ?>
                    <div class="card bg-light-green borderless w-100 h-100">
                        <div class="card-body pb-0">
                            <h1>Setup a pixel for Meta (Facebook)</h1>
                            <p>Get started by setting up your Meta pixel.</p>
                            <a href="<?php echo esc_url(menu_page_url("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x6D\x65\x74\x61", false)); ?>" class="btn btn-primary">Get Started</a>
                        </div>
                    </div>
                <?php endif; ?>
            </div>

            <!-- TIKTOK -->
            <div class="col-md-6 col-lg-3 mb-4">
                <?php if ($is_tiktok_setup) : ?>
                    <div class="card bg-light-purple borderless w-100 h-100">
                        <div class="card-body pb-0">
                            <h1>TikTok Pixel</h1>
                            <p>Manage TikTok tracking with server-side and client-side events.</p>
                            <a href="<?php echo esc_url(menu_page_url("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x74\x69\x6B\x74\x6F\x6B", false)); ?>" class="btn btn-primary">View Pixel Setup</a>
                        </div>
                    </div>
                <?php else : ?>
                    <div class="card bg-light-purple borderless w-100 h-100">
                        <div class="card-body pb-0">
                            <h1>Setup TikTok Pixel</h1>
                            <p>Add your TikTok Pixel ID to get started.</p>
                            <a href="<?php echo esc_url(menu_page_url("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x74\x69\x6B\x74\x6F\x6B", false)); ?>" class="btn btn-primary">Get Started</a>
                        </div>
                    </div>
                <?php endif; ?>
            </div>

            <!-- GOOGLE -->
            <div class="col-md-6 col-lg-3 mb-4">
                <?php if ($is_google_setup) : ?>
                    <div class="card bg-light-blue borderless w-100 h-100">
                        <div class="card-body pb-0">
                            <h1>Google Analytics</h1>
                            <p>Manage Google Analytics with Measurement Protocol.</p>
                            <a href="<?php echo esc_url(menu_page_url("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x67\x6F\x6F\x67\x6C\x65", false)); ?>" class="btn btn-primary">View Tag Setup</a>
                        </div>
                    </div>
                <?php else : ?>
                    <div class="card bg-light-blue borderless w-100 h-100">
                        <div class="card-body pb-0">
                            <h1>Setup Google Analytics</h1>
                            <p>Get started by adding your Google Measurement ID.</p>
                            <a href="<?php echo esc_url(menu_page_url("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x67\x6F\x6F\x67\x6C\x65", false)); ?>" class="btn btn-primary">Get Started</a>
                        </div>
                    </div>
                <?php endif; ?>
            </div>

            <!-- PINTEREST -->
            <div class="col-md-6 col-lg-3 mb-4">
                <?php if ($is_pinterest_setup) : ?>
                    <div class="card bg-pinterest-pink borderless w-100 h-100">
                        <div class="card-body pb-0">
                            <h1>Pinterest Tag</h1>
                            <p>Manage Pinterest tracking with Conversions API, including site events.</p>
                            <a href="<?php echo esc_url(menu_page_url("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x70\x69\x6E\x74\x65\x72\x65\x73\x74", false)); ?>" class="btn btn-primary">View Tag Setup</a>
                        </div>
                    </div>
                <?php else : ?>
                    <div class="card bg-pinterest-pink borderless w-100 h-100">
                        <div class="card-body pb-0">
                            <h1>Setup Pinterest Tag</h1>
                            <p>Add your Pinterest Tag ID to get started.</p>
                            <a href="<?php echo esc_url(menu_page_url("\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x70\x69\x6E\x74\x65\x72\x65\x73\x74", false)); ?>" class="btn btn-primary">Get Started</a>
                        </div>
                    </div>
                <?php endif; ?>
            </div>

        </div>


        <div class="row mb-4">
            <div class="col-12">
                <div class="card border-primary shadow-sm">
                    <div class="card-body">
                        <h4 class="mb-2"><i class="fa-solid fa-bullseye text-primary"></i> Centralised Event Manager</h4>
                        <p class="text-muted mb-3">
                            Beyond WooCommerce events (which are tracked automatically), manage your <strong>site events</strong> in one place across every enabled platform.
                            Set up a Lead, Newsletter Signup, or any bespoke event once. UniPixel applies the right Standard event names and dedup for each platform you choose.
                        </p>
                        <a href="admin.php?page=unipixel_conversions" class="btn btn-sm btn-outline-primary">
                            <i class="fa-solid fa-arrow-right"></i> Open Event Manager
                        </a>
                    </div>
                </div>
            </div>
        </div>


        <div class="row mt-2">

            <!-- View Stored Event Logs -->
            <div class="col-md-6 col-lg-3 mb-3">
                <div class="card h-100 shadow-sm">
                    <div class="card-body">
                        <h6 class="card-title mb-2">View Stored Event Logs</h6>
                        <p class="small text-muted mb-3">
                            Review all server-stored event logs to verify tracking behavior and troubleshoot platform data consistency.
                        </p>
                        <a href="admin.php?page=unipixel_event_logs" class="btn btn-sm btn-outline-primary">Open Logs</a>
                    </div>
                </div>
            </div>

            <!-- View Live Event Log -->
            <div class="col-md-6 col-lg-3 mb-3">
                <div class="card h-100 shadow-sm">
                    <div class="card-body">
                        <h6 class="card-title mb-2">View Live Event Log</h6>
                        <p class="small text-muted mb-3">
                            Observe live client-side events in real time for debugging and verification. Visit the Test Console
                            for an interactive live view.
                        </p>
                        <a href="admin.php?page=unipixel_console_logger" class="btn btn-sm btn-outline-primary">Open Live Console</a>
                    </div>
                </div>
            </div>

            <!-- General Settings -->
            <div class="col-md-6 col-lg-3 mb-3">
                <div class="card h-100 shadow-sm">
                    <div class="card-body">
                        <h6 class="card-title mb-2">General Settings</h6>
                        <p class="small text-muted mb-3">
                            Adjust event logging preferences, enable or disable database storage, and manage DebugView or console visibility options.
                        </p>
                        <a href="admin.php?page=unipixel_general_settings" class="btn btn-sm btn-outline-primary">Open Settings</a>
                    </div>
                </div>
            </div>

            <!-- Consent Settings -->
            <div class="col-md-6 col-lg-3 mb-3">
                <div class="card h-100 shadow-sm">
                    <div class="card-body">
                        <h6 class="card-title mb-2">Consent Settings</h6>
                        <p class="small text-muted mb-3">
                            <b>Turn on your Cookie Consent banner.</b> Manage how user consent is collected. Ensure compliance while maintaining event accuracy.
                        </p>
                        <a href="admin.php?page=unipixel_consent_settings" class="btn btn-sm btn-outline-primary">Open Consent Settings</a>
                    </div>
                </div>
            </div>

        </div>


    </div>
<?php
} ?>