<?php

namespace Flyerimage\Core\Init;

/**
 * The admin class
 */
class Admin
{

    /**
     * Initialize the menu class
     */
    function __construct()
    {
        add_action('admin_menu', [$this, 'admin_menu']);
    }

    /**
     * Register admin menu
     * 
     * @return void
     */
    public function admin_menu()
    {
        $parent_slug = 'flyer-image';
        $capability  = 'manage_options';

        $hook = add_menu_page(
            __('Flyer Image List', 'flyerimage'),
            __('Flyerimage', 'flyerimage'),
            $capability,
            $parent_slug,
            [$this, 'plugin_page'],
            'dashicons-megaphone'
        );
        /*add_submenu_page(
            $parent_slug,
            __('Flyer Reports', 'flyerimage'),
            __('Flyer Reports', 'flyerimage'),
            $capability,
            $parent_slug."-reports",
            [$this, 'plugin_page']
        );*/

        // enqueue the admin assets (scripts + styles)
        add_action('admin_head-' . $hook, [$this, 'enqueue_admin_assets']);
    }

    /**
     * enqueue admin assets those are register into Flyerimage\Assets
     * 
     * @return void
     */
    public function enqueue_admin_assets()
    {
        wp_enqueue_style('flyer-image-admin-style');
        wp_enqueue_script('flyer-image-admin-script');
    }

    /**
     * Plugin page
     * 
     * @return void
     */
    public function plugin_page()
    {
        include_once FLYER_IMAGE_PATH.'/webapp/index.php';
    }
}
