using Intrepid.Core.UI;
using Intrepid.Core.UI.Dialog;
using Intrepid.GameManagers;
using Intrepid.Gameplay.Themes;
using Intrepid.Utilities;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.UI;

namespace Intrepid.Gameplay.Entities.Player.PDA.UI.Applications.ThemeChanger
{
    public class ThemeSelectionAreaUI : MonoBehaviour
    {
        [GroupInjections, SerializeField] private DialogMinimalUI dialog;
        [GroupInjections, SerializeField] private NewsTickerUI title;
        [GroupInjections, SerializeField] private NewsTickerUI description;
        [GroupInjections, SerializeField] private Image[] palettes;
        [GroupDebug, SerializeField, ReadOnly] private Theme theme;
        
        public DialogMinimalUI Dialog => dialog;
        public NewsTickerUI Title => title;
        public NewsTickerUI Description => description;

        public Theme Theme
        {
            get => theme;
            [GroupDebug, Button(ButtonStyle.FoldoutButton)]
            set
            {
                theme = value;
                dialog.Theme = theme.PDAThemes.DialogTheme;
                title.TextMesh.color = theme.PDAThemes.AppTheme.Text;
                description.TextMesh.color = theme.PDAThemes.AppTheme.Text;
                for (var i = 0; i < theme.Summary.Length; i++)
                {
                    palettes[i].color = theme.Summary[i];
                }
                if (Proxy.Instance is null) return;
                title.Text = Proxy.Instance.I18N.Localise(theme.LocalizationName);
                description.Text = Proxy.Instance.I18N.Localise(theme.LocalizationDescription);
            }
        }

        public void Operational(bool forceReset = false)
        {
            title.Operational(Proxy.Instance.I18N.Localise(Theme.LocalizationName), forceReset);
            description.Operational(Proxy.Instance.I18N.Localise(Theme.LocalizationDescription), forceReset);
        }
        
        public void NotOperational()
        {
            title.Text = Proxy.Instance.I18N.Localise(Theme.LocalizationName);
            description.Text = Proxy.Instance.I18N.Localise(Theme.LocalizationDescription);

            title.TextMesh.text = title.Text;
            description.TextMesh.text = description.Text;
        }
    }
}