<?php
/**
 * Plugin Page Details Class
 *
 * This class is used to store and manage plugin page details including menu items,
 * page titles, slugs, URLs, and navigation settings.
 *
 * @package miniorange-sms-order-notification-otp-verification/objects
 */

namespace WCSMSOTP\Objects;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

if ( ! class_exists( 'PluginPageDetails' ) ) {
	/**
	 * Plugin Page Details Class
	 *
	 * This class is used to store and manage plugin page details including menu items,
	 * page titles, slugs, URLs, and navigation settings.
	 */
	class PluginPageDetails {

		/**
		 * The page title
		 *
		 * @var string
		 */
		public $page_title;

		/**
		 * The menu slug
		 *
		 * @var string
		 */
		public $menu_slug;

		/**
		 * The menu title
		 *
		 * @var string
		 */
		public $menu_title;

		/**
		 * Tab Name
		 *
		 * @var string
		 */
		public $tab_name;

		/**
		 * URL of the NavBar
		 *
		 * @var string
		 */
		public $url;

		/**
		 * The php page having the view
		 *
		 * @var string
		 */
		public $view;

		/**
		 * The ID attribute of the Tab
		 *
		 * @var string
		 */
		public $id;

		/**
		 * The Attribute which decides if this page should be shown
		 * in the Navbar
		 *
		 * @var bool
		 */
		public $show_in_nav;

		/**
		 * The inline css to be applied to the navbar
		 *
		 * @var string
		 */
		public $css;

		/**
		 * The icon of the navbar.
		 *
		 * @var string
		 */
		public $icon;

		/**
		 * Constructor.
		 *
		 * @param string $icon Icon for the menu item.
		 * @param string $page_title Page title.
		 * @param string $menu_slug Menu slug.
		 * @param string $menu_title Menu title.
		 * @param string $tab_name Tab name.
		 * @param string $request_uri Request URI.
		 * @param string $view View page file path.
		 * @param string $id ID of the page.
		 * @param string $css CSS to be applied to the navbar.
		 * @param bool   $show_in_nav Whether to show in navbar.
		 */
		public function __construct( $icon, $page_title, $menu_slug, $menu_title, $tab_name, $request_uri, $view, $id, $css = '', $show_in_nav = true ) {
			if ( ! is_string( $icon ) || ! is_string( $page_title ) || ! is_string( $menu_slug ) || ! is_string( $menu_title ) || ! is_string( $tab_name ) || ! is_string( $request_uri ) || ! is_string( $view ) || ! is_string( $id ) ) {
				return;
			}
			if ( ! is_string( $css ) ) {
				$css = '';
			}
			if ( ! is_bool( $show_in_nav ) ) {
				$show_in_nav = true;
			}

			$this->icon        = sanitize_text_field( $icon );
			$this->page_title  = sanitize_text_field( $page_title );
			$this->menu_slug   = sanitize_key( $menu_slug );
			$this->menu_title  = sanitize_text_field( $menu_title );
			$this->tab_name    = sanitize_text_field( $tab_name );
			$this->view        = sanitize_text_field( $view );
			$this->id          = sanitize_html_class( $id );
			$this->css         = wp_kses_post( $css );
			$this->show_in_nav = $show_in_nav;

			// Sanitize and escape the request URI before using it in add_query_arg.
			$sanitized_uri = esc_url_raw( $request_uri );
			$this->url     = add_query_arg( array( 'page' => $this->menu_slug ), $sanitized_uri );
		}
	}
}
