<?php
/**
 * Plugin Name: Let's Code Cookie Banner
 * Description: GDPR-compliant cookie banner following Italian Data Protection Authority (Garante) guidelines.
 * Version: 1.2.8
 * Author: Let's Code
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: lets-code-cookie-banner
 * Domain Path: /languages
 * Requires at least: 5.9
 * Requires PHP: 7.4
 *
 * @package LetsCodeCookieBanner
 */

defined( 'ABSPATH' ) || exit;

define( 'LCCB_VERSION', '1.2.8' );
define( 'LCCB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'LCCB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'LCCB_PLUGIN_FILE', __FILE__ );
define( 'LCCB_COOKIE_NAME', 'lccb_consent' );
define( 'LCCB_COOKIE_DAYS', 365 );

if ( ! defined( 'LCCB_API_URL' ) ) {
	define( 'LCCB_API_URL', 'https://backoffice.let-scode.it/api/v1' );
}

// Base URL used for the client-side autoblocking script src.
// In production this equals LCCB_API_URL. Override in wp-config.php when
// the PHP server and the browser reach the backoffice via different hostnames
// (e.g. Docker local dev: host.docker.internal vs localhost).
if ( ! defined( 'LCCB_AUTOBLOCKING_BASE_URL' ) ) {
	define( 'LCCB_AUTOBLOCKING_BASE_URL', LCCB_API_URL );
}

require_once LCCB_PLUGIN_DIR . 'includes/lccb-freemius.php';
require_once LCCB_PLUGIN_DIR . 'includes/class-lccb-consent-manager.php';
require_once LCCB_PLUGIN_DIR . 'includes/class-lccb-cookie-registry.php';
require_once LCCB_PLUGIN_DIR . 'includes/class-lccb-cookie-scanner.php';
require_once LCCB_PLUGIN_DIR . 'includes/class-lccb-api-client.php';
require_once LCCB_PLUGIN_DIR . 'includes/class-lccb-admin.php';
require_once LCCB_PLUGIN_DIR . 'includes/class-lccb-frontend.php';

register_activation_hook( __FILE__, array( 'LCCB_Consent_Manager', 'activate' ) );
register_activation_hook( __FILE__, array( 'LCCB_API_Client', 'register' ) );

add_action( 'plugins_loaded', 'lccb_init' );

/**
 * Initialises the plugin on the plugins_loaded hook.
 */
function lccb_init() {
	// Self-heal: initialize defaults if the activation hook never fired (e.g. manual file copy).
	if ( false === get_option( 'lccb_settings' ) ) {
		LCCB_Consent_Manager::activate();
	}

	if ( is_admin() ) {
		new LCCB_Admin();
	}
	new LCCB_Frontend();
}
