using RootMotion.FinalIK;
using UnityEngine;

namespace NBF
{
    public class PlayerArm : MonoBehaviour
    {
        public bool IsLeft;
        public LimbIK IK;
        public Transform RodContainer;
        public Transform LeftRigMagnet;
        public FingerRig FingerRig;
        public PlayerShoulder Shoulder;//PlayerShoulder

        [HideInInspector] public float interactionTargetWeight;


        public void SetReelHandle(ReelAsset asset)
        {
            IK.solver.target = asset.handle;
            IK.enabled = true;

            // var fingers = FingerRig.fingers;
            // foreach (var finger in fingers)
            // {
            //     finger.target = asset.handleEnd;
            // }
            
            // // 启用整体控制
            // FingerRig.weight = 1f;
            //
            // // 绑定大拇指和食指的目标
            // FingerRig.fingers[0].target = asset.handleEnd;  // Thumb
            // FingerRig.fingers[1].target = asset.handleEnd;  // Index
            //
            // FingerRig.fingers[0].weight = 1f;
            // FingerRig.fingers[1].weight = 1f;

            // 其余手指握拳（不绑定 target）
            for (int i = 2; i < 5; i++)
            {
                FingerRig.fingers[i].target = null;
                FingerRig.fingers[i].weight = 1f;
            }
        }

        public void MoveTowardsInteraction()
        {
            if (!IK)
            {
                return;
            }

            IK.solver.SetIKPositionWeight(Mathf.MoveTowards(IK.solver.IKPositionWeight,
                interactionTargetWeight, Time.deltaTime * 2f));
        }
    }
}