using System;
using System.Linq;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

namespace MyGame.Scenes.marketing.Scripts
{
    public class MarketView : MonoBehaviour
    {
        [SerializeField] private Transform signBoardTarget;
        [SerializeField] private Transform decoration1Target;
        [SerializeField] private Transform cartTarget;
        [SerializeField] private Transform stockTarget;
        [SerializeField] private Transform decoration2Target;
        [SerializeField] private Transform category6Target;
        
        public void SetHighlight(ShopCustomizeCategory category, bool active)
        {
            var stateName = active ? "Customize_Selection" : "Stay";
            foreach (var animator in GetTarget(category).GetComponentsInChildren<Animator>())
            {
                animator.Play(stateName);
            } 
        }
        
        public void SetItem(ShopCustomizeData customizeData)
        {
            var target = GetTarget(customizeData.Category);
            target.DestroyAllChildrens();
            Instantiate(customizeData.GetPrefab(), target);
        }

        public void SetAllItem()
        {
            var settings = GameDataManager.GameData.ShopCustomizeSettings;
            var customizeDataList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopCustomizeData>(Const.ShopCustomizeDataSheet);
            foreach (var category in (ShopCustomizeCategory[])Enum.GetValues(typeof(ShopCustomizeCategory)))
            {
                SetItem(customizeDataList.First(data => data.id == settings.GetSetting(category)));
            }
        }
        
        public Transform GetTarget(ShopCustomizeCategory category)
        {
            switch (category)
            {
                case ShopCustomizeCategory.Category1:
                    return signBoardTarget;
                case ShopCustomizeCategory.Category2:
                    return decoration1Target;
                case ShopCustomizeCategory.Category3:
                    return cartTarget;
                case ShopCustomizeCategory.Category4:
                    return stockTarget;
                case ShopCustomizeCategory.Category5:
                    return decoration2Target;
                // case ShopCustomizeCategory.Category6:
                //     return category6Target;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
    }
}