<?php
/**
 * Plugin Name: Hugeicons
 * Plugin URI: https://hugeicons.com
 * Description: Beautiful icon blocks for the WordPress block editor. Includes Icon, Icon List, Button with Icon, Icon Box, and FAQ blocks with access to 46,000+ premium icons.
 * Version: 2.0.0
 * Author: Hugeicons
 * Author URI: https://hugeicons.com
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: hugeicons
 * Domain Path: /languages
 * Requires at least: 6.0
 * Requires PHP: 7.4
 *
 * @package Hugeicons
 */

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

// Plugin constants.
define( 'HUGEICONS_VERSION', '2.0.0' );
define( 'HUGEICONS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'HUGEICONS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'HUGEICONS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

// API constants.
define( 'HUGEICONS_API_SEARCH_URL', 'https://search.hugeicons.com/search' );
define( 'HUGEICONS_API_ICON_URL', 'https://ico.hugeicons.com' );

/**
 * Autoload plugin classes.
 */
spl_autoload_register( function ( $class ) {
    $prefix = 'Hugeicons\\';
    $base_dir = HUGEICONS_PLUGIN_DIR . 'includes/';

    $len = strlen( $prefix );
    if ( strncmp( $prefix, $class, $len ) !== 0 ) {
        return;
    }

    $relative_class = substr( $class, $len );
    $file = $base_dir . 'class-' . strtolower( str_replace( '_', '-', str_replace( '\\', '/', $relative_class ) ) ) . '.php';

    if ( file_exists( $file ) ) {
        require $file;
    }
} );

/**
 * Initialize the plugin.
 *
 * @return void
 */
function hugeicons_init() {
    // Load text domain for translations.
    load_plugin_textdomain( 'hugeicons', false, dirname( HUGEICONS_PLUGIN_BASENAME ) . '/languages' );

    // Initialize the loader.
    $loader = new Hugeicons\Loader();
    $loader->init();
}
add_action( 'plugins_loaded', 'hugeicons_init' );

/**
 * Plugin activation hook.
 *
 * @return void
 */
function hugeicons_activate() {
    // Flush rewrite rules on activation.
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'hugeicons_activate' );

/**
 * Plugin deactivation hook.
 *
 * @return void
 */
function hugeicons_deactivate() {
    // Flush rewrite rules on deactivation.
    flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'hugeicons_deactivate' );
