<?php

/**
* Admin Menu
*/
class Esi_Management_Entity {

    /**
    * The ID of this plugin.
    *
    * @since    1.0.0
    * @access   private
    * @var      string    $plugin_name    The ID of this plugin.
    */
    private $plugin_name;

    /**
    * The version of this plugin.
    *
    * @since    1.0.0
    * @access   private
    * @var      string    $version    The current version of this plugin.
    */
    private $version;

    /**
    * Initialize the class and set its properties.
    *
    * @since    1.0.0
    * @param      string    $plugin_name       The name of this plugin.
    * @param      string    $version    The version of this plugin.
    */
    public function __construct( $plugin_name, $version ) {

        $this->plugin_name = $plugin_name;
        $this->version = $version;
        // add_action( 'admin_menu_entity', array( $this, 'admin_menu' ) );

    }

    // /**
    // * Add menu items
    // *
    // * @return void
    // */
    // public function admin_menu() {
    //
    //     /** Top Menu **/
    //     add_submenu_page( 'esi-management', __( 'entity', 'esi' ), __( 'entity', 'esi' ), 'manage_entity', 'esi-management-entity', array( $this, 'plugin_page' ) );
    // }

    /**
    * Handles the plugin page
    *
    * @return void
    */
    public function plugin_page() {
        $action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
        $id     = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;

        switch ($action) {
			case 'view':
			case 'edit':
			case 'new':
			$template = dirname( __FILE__ ) . '/partials/esi-management-entity-form.php';
			break;

            case 'delete':
            esi_delete_entity($id);
			$template = dirname( __FILE__ ) . '/partials/esi-management-entity-list.php';
			break;

			default:
			$template = dirname( __FILE__ ) . '/partials/esi-management-entity-list.php';
			break;
		}

        if ( file_exists( $template ) ) {
            include $template;
        }
    }
}
