<?php
/**
 * Plugin Name: BW Gallery
 * Plugin URI: https://bowdenworks.com
 * Description: Create beautiful galleries with WordPress media library integration, featuring tabbed organization and lightbox functionality.
 * Version: 1.0.0
 * Requires at least: 3.6
 * Requires PHP: 7.4
 * Author: Bowden Works
 * Author URI: https://bowdenworks.com
 * License: GPL v2 or later
 * Text Domain: bw-gallery
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

// Check PHP version
if (version_compare(PHP_VERSION, '7.4', '<')) {
    add_action('admin_notices', function() {
        ?>
        <div class="notice notice-error">
            <p><?php esc_html_e('BW Gallery requires PHP 7.4 or higher. Your current PHP version is ' . PHP_VERSION, 'bw-gallery'); ?></p>
        </div>
        <?php
    });
    return;
}

// Define plugin constants
define('BWG_VERSION', '1.0.0');
define('BWG_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('BWG_PLUGIN_URL', plugin_dir_url(__FILE__));
define('BWG_PLUGIN_BASENAME', plugin_basename(__FILE__));

// Include required files
require_once BWG_PLUGIN_DIR . 'includes/class-bw-gallery.php';
require_once BWG_PLUGIN_DIR . 'includes/class-bw-gallery-db.php';
require_once BWG_PLUGIN_DIR . 'includes/class-bw-gallery-admin.php';
require_once BWG_PLUGIN_DIR . 'includes/class-bw-gallery-shortcode.php';
require_once BWG_PLUGIN_DIR . 'includes/class-bw-gallery-taxonomy.php';
require_once BWG_PLUGIN_DIR . 'includes/class-bw-gallery-helper.php';

// Activation hook
register_activation_hook(__FILE__, 'bwg_activate');
function bwg_activate() {
    $db = new BW_Gallery_DB();
    $db->create_tables();
    
    // Add default options
    add_option('bwg_settings', array(
        'thumbnail_size' => 'medium',
        'lightbox_enabled' => true,
        'columns' => 3,
        'gap' => 10
    ));
    
    // Initialize taxonomy
    BW_Gallery_Taxonomy::activate();
    
    flush_rewrite_rules();
}

// Deactivation hook
register_deactivation_hook(__FILE__, 'bwg_deactivate');
function bwg_deactivate() {
    flush_rewrite_rules();
}

// Initialize plugin
add_action('plugins_loaded', 'bwg_init');
function bwg_init() {
    $bw_gallery = new BW_Gallery();
    $bw_gallery->init();
}