using System;
using UnityEngine;
using UnityEngine.UI;

namespace Darkmatter.Features.History
{
    public class HistoryButtonsView : MonoBehaviour
    {
        [SerializeField] private Button undoButton;
        [SerializeField] private Button redoButton;
        [SerializeField] private Button clearButton;

        public event System.Action OnUndoClicked;
        public event System.Action OnRedoClicked;
        public event System.Action OnClearClicked;

        void Start()
        {
            undoButton.onClick.AddListener(() => OnUndoClicked?.Invoke());
            redoButton.onClick.AddListener(() => OnRedoClicked?.Invoke());
            clearButton.onClick.AddListener(() => OnClearClicked?.Invoke());
        }

        public void SetUndoInteractable(bool value) => undoButton.interactable = value;
        public void SetRedoInteractable(bool value) => redoButton.interactable = value;
        public void SetClearInteractable(bool value) => clearButton.interactable = value;

        private void OnDestroy()
        {
            undoButton.onClick.RemoveListener(() => OnUndoClicked?.Invoke());
            redoButton.onClick.RemoveListener(() => OnRedoClicked?.Invoke());
            clearButton.onClick.RemoveListener(() => OnClearClicked?.Invoke());
        }
    }
}