<?php

/**
 * WordPress Actions Registration
 *
 * This file registers all WordPress actions for the Licenzo Application plugin.
 * Each action is mapped to a handler class for clean separation of concerns.
 *
 * @package Licenzo\Hooks
 */

use Licenzo\Framework\Foundation\Application;

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

/**
 * Register WordPress actions
 *
 * @param Application $app
 * @return void
 */
return function (Application $app) {

    // Admin Menu Registration
    add_action('admin_menu', function () use ($app) {
        $handler = $app->make(\Licenzo\Hooks\Handler\Admin\MenuHandler::class);
        $handler->handle();
    });

    // Admin Asset Loading
    add_action('admin_enqueue_scripts', function ($hook) use ($app) {
        $handler = $app->make(\Licenzo\Hooks\Handler\Admin\AssetHandler::class);
        $handler->handle($hook);
    });

    // Admin Notices
    add_action('admin_notices', function () use ($app) {
        $handler = $app->make(\Licenzo\Hooks\Handler\Admin\NoticeHandler::class);
        $handler->handle();
    });

    // Hide Admin Notices on Our Pages
    add_action('admin_enqueue_scripts', function () use ($app) {
        $handler = $app->make(\Licenzo\Hooks\Handler\Admin\NoticeHandler::class);
        $handler->handleHideNotices();
    });
    // Commerce Provider Integration
    $commerceProvider = \Licenzo\Helper\Settings::getGeneralSettings()['commerce_provider'] ?? 'woocommerce';

    if ($commerceProvider === 'woocommerce') {
        add_action('woocommerce_loaded', function () {
            \Licenzo\Modules\WooCommerce\WooCommerce::bootstrap();
        });
    }

    if ($commerceProvider === 'edd') {
        add_action('plugins_loaded', function () {
            if (function_exists('EDD')) {
                \Licenzo\Modules\EDD\EDD::bootstrap();
            }
        }, 20);
    }

    /**
     * Customer Portal Shortcode
     *
     * @usage : [licenzo_customer_portal/]
     */
    add_shortcode('licenzo_customer_portal', function () use ($app) {
        $handler = $app->make(\Licenzo\Hooks\Handler\Frontend\LicenzoCustomerPortalHandler::class);
        return $handler->handle();
    });

    add_filter('wp_plugin_check_ignore_directories', function ($directories) {
        $directories[] = 'dev';
        $directories[] = 'packages';

        return $directories;
    }, 10, 1);


    \Licenzo\Modules\ModuleRegistry::register();
};
