<?php
/**
 * Plugin Name:       Panelra – Custom Admin Dashboard Builder
 * Description:       Customize your WordPress admin dashboard: colors, fonts, menu layout, admin bar, notices, maintenance mode and more.
 * Version:           2.0.4
 * Requires at least: 6.0
 * Tested up to:      7.1
 * Requires PHP:      7.4
 * Author:            Davelabs
 * Author URI:        https://profiles.wordpress.org/davelabs
 * License:           GPL-2.0+
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       panelra-dashboard-builder
 * Domain Path:       /languages
 *
 * @package Panelra
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Prevent duplicate loading if Pro is active alongside Free.
if ( defined( 'PNLRDB_VERSION' ) ) {
	return;
}

define( 'PNLRDB_VERSION',    '2.0.4' );
define( 'PNLRDB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'PNLRDB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'PNLRDB_BASENAME',   plugin_basename( __FILE__ ) );
define( 'PNLRDB_SLUG',       'panelra-dashboard-builder' );



/**
 * Set default option values on first activation.
 */
function pnlrdb_activate() {
	$defaults = array(
		'pnlrdb_menu_width'           => 220,
		'pnlrdb_dashboard_colors'     => array( 'sidebar_bg' => '#0d003a' ),
		'pnlrdb_active_theme_preset'  => 'default',
		'pnlrdb_menu_names'           => array(),
		'pnlrdb_hide_notices'         => 0,
		'pnlrdb_dashboard_font'       => 'Roboto, Arial, sans-serif',
		'pnlrdb_dashboard_font_size'  => 15,
		'pnlrdb_dashboard_font_color' => '#1e293b',
	);

	foreach ( $defaults as $key => $value ) {
		if ( false === get_option( $key ) ) {
			update_option( $key, $value );
		}
	}

	$legacy_pairs = array(
		'menu_width' => 'pnlrdb_menu_width',
		'dashboard_colors' => 'pnlrdb_dashboard_colors',
		'menu_names' => 'pnlrdb_menu_names',
		'hide_notices' => 'pnlrdb_hide_notices',
		'dashboard_font' => 'pnlrdb_dashboard_font',
		'dashboard_font_size' => 'pnlrdb_dashboard_font_size',
		'dashboard_font_color' => 'pnlrdb_dashboard_font_color',
		'button_text_color' => 'pnlrdb_button_text_color',
		'active_theme_preset' => 'pnlrdb_active_theme_preset',
		'dark_mode_global' => 'pnlrdb_dark_mode_global',
		'hidden_dashboard_widgets' => 'pnlrdb_hidden_dashboard_widgets',
		'role_menu_visibility' => 'pnlrdb_role_menu_visibility',
		'hide_admin_bar_roles' => 'pnlrdb_hide_admin_bar_roles',
		'maintenance_enabled' => 'pnlrdb_maintenance_enabled',
		'maintenance_title' => 'pnlrdb_maintenance_title',
		'maintenance_message' => 'pnlrdb_maintenance_message',
		'logs' => 'pnlrdb_logs',
	);

	foreach ( $legacy_pairs as $legacy_suffix => $new_key ) {
		$legacy_key = 'admin' . 'pilot773_' . $legacy_suffix;
		if ( false !== get_option( $legacy_key ) && false === get_option( $new_key ) ) {
			update_option( $new_key, get_option( $legacy_key ) );
		}
	}


	// Enable the Dashboard Builder on first activation so new users immediately see the Panelra template chooser.
	if ( false === get_option( 'pnlrdb_dashboard_layout' ) ) {
		update_option(
			'pnlrdb_dashboard_layout',
			array(
				'enabled'              => true,
				'hide_wp'              => true,
				'hide_screen_opts'     => true,
				'hide_help'            => true,
				'hide_notices'         => true,
				'hide_title'           => true,
				'defaults_initialized' => true,
				'sections'             => array(),
			)
		);
	}
}
register_activation_hook( __FILE__, 'pnlrdb_activate' );

/**
 * Deactivation hook — intentionally empty.
 * Data cleanup is handled by uninstall.php on deletion.
 */
function pnlrdb_deactivate() {}
register_deactivation_hook( __FILE__, 'pnlrdb_deactivate' );

/**
 * Bootstrap the plugin after all plugins have loaded.
 */
function pnlrdb_init() {
	require_once PNLRDB_PLUGIN_DIR . 'includes/class-pnlrdb-loader.php';
	$loader = new Pnlrdb_Loader();
	$loader->run();
}
add_action( 'plugins_loaded', 'pnlrdb_init' );