// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖 

using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using FairyGUI;
using NBC;

namespace NBF
{
    public partial class InteractiveTag : GLabel
    {
        private InteractiveObject _interactiveObject;
        private InteractiveData _interactiveData;

        private void OnInited()
        {
        }

        public void SetData(InteractiveObject interactiveObject)
        {
            _interactiveObject = interactiveObject;

            List.RemoveChildrenToPool();
            var interactiveType = GameDef.InteractiveDataList.Find(t => t.Type == interactiveObject.Type);
            if (interactiveType != null)
            {
                _interactiveData = interactiveType;
                if (!string.IsNullOrEmpty(interactiveType.Use1))
                {
                    var item1 = List.AddItemFromPool().asLabel;
                    item1.title = "E - " + interactiveType.Use1Title;
                }

                if (!string.IsNullOrEmpty(interactiveType.Use2))
                {
                    var item2 = List.AddItemFromPool().asLabel;
                    item2.title = "Y - " + interactiveType.Use2Title;
                }

                var iconUrl = UIPackage.GetItemURL("Common", interactiveType.Icon);
                icon = iconUrl;

                title = interactiveType.Name;
            }
        }


        public void Use1()
        {
            if (string.IsNullOrEmpty(_interactiveData.Use1)) return;
            Debug.Log(_interactiveData.Use1);

            if (_interactiveObject.Type == UIDef.InteractiveType.Boat)
            {
                //上船
                Debug.Log("上船===");
                // var boat = _interactiveObject.gameObject.GetComponent<Boat>();
                // Fishing.Inst.Player.SelfPlayer.EnterBoat(boat);
                // Fishing.Inst.Player
            }
            else if (_interactiveObject.Type == UIDef.InteractiveType.FishingShop)
            {
                FishingShopPanel.Show();
            }
        }

        public void Use2()
        {
            if (string.IsNullOrEmpty(_interactiveData.Use2)) return;
            Debug.Log(_interactiveData.Use2);
        }
    }
}