<?php

/**
 * Admin Menus
 * Registers all admin menus and submenus for Revio Review
 *
 * @since 1.1.0
 * @package RVIOR
 */

// Namespace.
namespace RVIOR\Admin;

// Exit if accessed directly.
defined('ABSPATH') || exit(1);

if ( ! class_exists(__NAMESPACE__ . '\Menus') ) {

    /**
     * Admin Menus
     *
     * @since 1.1.0
     */
    class Menus extends \RVIOR\Base\Controller {


        // Use Utilities trait.
        use \RVIOR\Traits\Utilities;

        /**
         * Registers all admin menus
         *
         * @return void
         */
        public function register_hooks() {

            add_action('admin_menu', [ $this, 'admin_menu' ]);
        }

        /**
         * Returns the permissions for the admin menu
         *
         * @return string
         */
        public function get_permissions() {
            return 'edit_others_posts';
        }

        /**
         * Adds admin menu
         *
         * @return void
         */
        public function admin_menu() {

            if ( $this->client()->has_valid_token() ) {
                // Dashboard template.
                add_menu_page(__('Revio Review', 'revio-reviews'), __('Revio', 'revio-reviews'), $this->get_permissions(), 'revio', function () {
                }, ' ');

                // Reviews template.
                add_submenu_page('revio', __('Revio Review Reviews', 'revio-reviews'), __('Reviews', 'revio-reviews'), $this->get_permissions(), 'revio', function () {

                    $this->render_template('admin/base');
                });

                // Gallery template.
                add_submenu_page('revio', __('Revio Review Gallery', 'revio-reviews'), __('Gallery', 'revio-reviews'), $this->get_permissions(), 'rvior-review-gallery', function () {

                    $this->render_template('admin/base');
                });

                // Integrations template.
                add_submenu_page('revio', __('Revio Review Integrations', 'revio-reviews'), __('WC Settings', 'revio-reviews'), $this->get_permissions(), 'rvior-review-integrations', function () {

                    $this->render_template('admin/base');
                });

                // Settings template.
                add_submenu_page('revio', __('Revio Review Settings', 'revio-reviews'), __('Review Settings', 'revio-reviews'), $this->get_permissions(), 'rvior-review-settings', function () {

                    $this->render_template('admin/base');
                }, 999);

                // Utilities template.
                add_submenu_page('revio', __('Revio Review Utility', 'revio-reviews'), __('Utility', 'revio-reviews'), $this->get_permissions(), 'rvior-review-utility', function () {

                    $this->render_template('admin/base');
                }, 999);

                // Profile template.
                add_submenu_page('revio', __('Revio Review Profile', 'revio-reviews'), __('Profile & Plan', 'revio-reviews'), $this->get_permissions(), 'rvior-review-profile', function () {

                    $this->render_template('admin/base');
                });

                // Documentation template.
                add_submenu_page('revio', __('Revio Review Documentation', 'revio-reviews'), __('Docs & Help', 'revio-reviews'), $this->get_permissions(), 'rvior-review-documentation', function () {

                    $this->render_template('admin/base');
                });
            } else {
                // Loads get started page if the user is NOT logged in RVIOR.
                add_menu_page(__('Get Started With Revio Review', 'revio-reviews'), __('Revio', 'revio-reviews'), $this->get_permissions(), 'revio', function () {
                    echo "<div class='rvior-wrapper' id='rvior-onboarding'></div>";
                }, '', 99);
            }
        }
    }

    // Instantiate.
    Menus::init();
}
