<?php
/**
 * Plugin Name: Easy Restaurant Manager
 * Description: A comprehensive Easy Restaurant Manager system 
 * Version: 1.1.0
 * Author: WPulse
 * Author URI: https://www.akmelias.com/
 * Text Domain: easy-restaurant-manager
 * License: GPLv2 or later
 */

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

if (!defined('EASY_RESTAURANT_MANAGER_VERSION')) {
    define('EASY_RESTAURANT_MANAGER_VERSION', '1.1.0');
}

if (!defined('EASY_RESTAURANT_MANAGER_PLUGIN_DIR')) {
    define('EASY_RESTAURANT_MANAGER_PLUGIN_DIR', plugin_dir_path(__FILE__));
}

if (!defined('EASY_RESTAURANT_MANAGER_PLUGIN_URL')) {
    define('EASY_RESTAURANT_MANAGER_PLUGIN_URL', plugin_dir_url(__FILE__));
}

// Load API routes
use EasyRestaurantManager\Http\Router\API_Router;
use EasyRestaurantManager\Http\Router\Route;
// Autoloader
require_once EASY_RESTAURANT_MANAGER_PLUGIN_DIR . 'vendor/autoload.php';

// Register API routes on REST API initialization
add_action('rest_api_init', function () {
    Route::register();
    API_Router::register_routes();
});

// Initialize the plugin
function EASY_RESTAURANT_MANAGER_init() {
    (new EasyRestaurantManager\Hooks\Handler\CustomPageHandler())->register();
    \EasyRestaurantManager\Core\Plugin::instance();
}

// Hook into WordPress init
add_action('plugins_loaded', 'EASY_RESTAURANT_MANAGER_init');

// Activation hook
register_activation_hook(__FILE__, function() {
    require_once EASY_RESTAURANT_MANAGER_PLUGIN_DIR . 'app/Database/Migrations/Installer.php';
    require_once EASY_RESTAURANT_MANAGER_PLUGIN_DIR . 'app/Hooks/Handler/CustomPageHandler.php';
    $installer = new \EasyRestaurantManager\Database\Migrations\Installer();
    $installer->install();
    (new EasyRestaurantManager\Hooks\Handler\CustomPageHandler())->register();
    flush_rewrite_rules();
});

// Deactivation hook
register_deactivation_hook(__FILE__, function() {
    // Clean up if needed
    flush_rewrite_rules();
});

function easy_restaurant_manager_menus_block_assets() {
    wp_register_script(
        'easy_restaurant_manager-menu-block',
        plugins_url('assets/js/menu-block.js', __FILE__),
        ['wp-blocks', 'wp-editor', 'wp-components', 'wp-element']
    );
    add_action('enqueue_block_editor_assets', function () {
        wp_enqueue_script(
            'easy_restaurant_manager_media_button',
            EASY_RESTAURANT_MANAGER_PLUGIN_URL. 'assets/js/menu-block.js',
            array('wp-blocks', 'wp-element', 'wp-editor', 'wp-i18n', 'wp-block-editor'),
            EASY_RESTAURANT_MANAGER_VERSION,
            true
        );
        // wp_enqueue_style(
        //     'azonpress_block-cgb-block-editor-css',
        //     AZONPRESS_PLUGIN_URL. 'public/blocksold/dist/blocks.editor.build.css',
        //     array('wp-edit-blocks'),
        //     AZONPRESS_PLUGIN_VERSION
        // );
    });
}

add_action('init', 'easy_restaurant_manager_menus_block_assets');

function registerCustomPostType()
{
    register_post_type('erm_menu', [
        'public' => true,
        'has_archive' => true,
        'rewrite' => ['slug' => 'ehx-listing'],
        'supports' => ['title', 'editor', 'thumbnail'],
    ]);
}

add_action('init', 'registerCustomPostType');


