using Intrepid.Gameplay.Codex.Visual;
using Intrepid.Utilities;
using UnityEngine;

namespace Intrepid.Gameplay.Codex.UI.Components
{
    public class CodexPanelComponentUI : CodexComponentUI
    {
        [GroupConfigurations, SerializeField] private PictorialSurfaceType backgroundType = PictorialSurfaceType.Base;
        [GroupConfigurations, SerializeField] private PictorialSignalType borderType = PictorialSignalType.Primary;
        
        [GroupInjections, SerializeField] private CodexColorEffectTargetUI background;
        [GroupInjections, SerializeField] private CodexColorEffectTargetUI border;

        public PictorialSurfaceType BackgroundType => backgroundType;
        public PictorialSignalType BorderType => borderType;

        public void SetSurface(PictorialSurfaceType surface)
        {
            backgroundType = surface;
            var ctx = CodexVisualService.Instance.CurrentContext;
            background?.Apply(ctx.Protocol.GetSurfaceColor(backgroundType));
        }
        
        public void SetBorder(PictorialSignalType signal)
        {
            borderType = signal;
            var ctx = CodexVisualService.Instance.CurrentContext;
            border?.Apply(ctx.Protocol.GetSignalColor(borderType));
        }

        public override void ApplyCodexVisuals(CodexVisualContext ctx)
        {
            background?.Apply(ctx.Protocol.GetSurfaceColor(backgroundType));
            border?.Apply(ctx.Protocol.GetSignalColor(borderType));
        }
        
        public override void BeforeClose()
        {
            base.BeforeClose();
            background?.Stop();
            border?.Stop();
        }
    }
}