<?php

// Encolar scripts solo en posts
add_action('wp_enqueue_scripts', 'bpbooster_enqueue_scripts');
function bpbooster_enqueue_scripts() {
    if (is_single() && get_post_type() === 'post') {
        wp_enqueue_style('bpbooster-style', plugin_dir_url(__FILE__) . '../assets/css/popup.css');
        wp_enqueue_script('bpbooster-script', plugin_dir_url(__FILE__) . '../assets/js/popup.js', array('jquery'), null, true);

        $options = get_option('bpbooster_settings');
        wp_localize_script('bpbooster-script', 'bpboosterSettings', array(
            'headline' => $options['headline'] ?? '',
            'subheadline' => $options['subheadline'] ?? '',
            'cta_text' => $options['cta_text'] ?? '',
            'cta_link' => $options['cta_link'] ?? '',
            'phone' => $options['phone'] ?? '',
            'email' => $options['email'] ?? '',
            'post_id' => get_the_ID(),
            'ajax_url' => admin_url('admin-ajax.php')
        ));
    }
}

// Página de ajustes y dashboard
add_action('admin_menu', 'bpbooster_admin_menu');
function bpbooster_admin_menu() {
    add_options_page('Blog Popup Booster', 'Blog Popup Booster', 'manage_options', 'bpbooster', 'bpbooster_settings_page');
    add_menu_page('Popup Click Report', 'Popup Report', 'manage_options', 'bpbooster_dashboard', 'bpbooster_dashboard_page');
}

// Página de ajustes
add_action('admin_init', 'bpbooster_register_settings');
function bpbooster_register_settings() {
    register_setting('bpbooster_options_group', 'bpbooster_settings');
}

function bpbooster_settings_page() {
    require_once plugin_dir_path(__FILE__) . '../admin/admin-page.php';
}

function bpbooster_dashboard_page() {
    require_once plugin_dir_path(__FILE__) . '../admin/admin-dashboard.php';
}
