// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Standard Library
using System;
using System.Collections.Generic;
// Unity
using UnityEditor;
using UnityEngine;
// GameKit
using AWS.GameKit.Runtime.Utils;
namespace AWS.GameKit.Editor.Windows.Settings
{
    /// 
    /// The base class for all pages displayed in the AWS GameKit Settings window.
    /// 
    [Serializable]
    public abstract class Page
    {
        /// 
        /// The name to display for this page in the navigation tree, the page title, and elsewhere.
        /// 
        public abstract string DisplayName { get; }
        /// 
        /// Change the currently selected tab to the named tab.
        /// 
        /// 
        /// If the named tab does not exist, then an Error will be logged and the page's currently selected tab will not change.
        ///
        /// When overriding this method, do not call base.SelectTab(tabName).
        /// 
        /// The name of the tab to select.
        public virtual void SelectTab(string tabName)
        {
            Logging.LogError($"There is no tab named \"{tabName}\" on the page \"{GetType().Name}\". The page does not have any tabs.");
        }
        /// 
        /// This method is called each time the page is switched to from another page.
        ///
        /// This method does nothing by default. It is not necessary to call `base.OnNavigatedTo()` when overriding this method.
        /// 
        public virtual void OnNavigatedTo()
        {
            // empty call
        }
        /// 
        /// This method is called each time the page is switched out with another page.
        ///
        /// This method does nothing by default. It is not necessary to call `base.OnNavigatedFrom()` when overriding this method.
        /// 
        public virtual void OnNavigatedFrom()
        {
            // empty call
        }
        /// 
        /// Draw the page's title and content.
        /// 
        public void OnGUI()
        {
            DrawTitle();
            GUILayout.Space(SettingsGUIStyles.Page.SpaceAfterTitle);
            DrawContent();
        }
        /// 
        /// Get the title of this page.
        ///
        /// By default the title is "{Environment} > {Region} > {GetTitleSuffix()}".
        /// 
        protected virtual IList GetTitle()
        {
            List titleParts = new List() { "Environment", "Region" };
            titleParts.AddRange(GetTitleSuffix());
            return titleParts;
        }
        /// 
        /// Get the portion of this page's title that comes after the "{Environment} > {Region}" prefix.
        ///
        /// By default returns this page's DisplayName.
        /// 
        protected virtual IList GetTitleSuffix()
        {
            return new List() { DisplayName };
        }
        /// 
        /// Draw the page's content, which is everything below the title.
        /// 
        protected abstract void DrawContent();
        protected virtual void DrawTitle()
        {
            GUIStyle titleStyle = SettingsGUIStyles.Page.Title;
            EditorGUILayout.LabelField(DisplayName, titleStyle);
        }
    }
}