using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEditor;
using UnityEngine;

using Random = UnityEngine.Random;
public class EnemyHappyWalkState : EnemyBaseState
{
    private path currentPath = new();
    private int pointIndex = 0;
    private bool returning = false;
    private float _timer;
    private Material faceMat;
    public override void EnterState(EnemyStateManager manager)
    {
        manager.anim.SetTrigger("Happy");
        // _timer = Time.time + manager.happyTime;
        // currentPath = manager.pathList[Random.Range(0, manager.pathList.Length)];
        // manager.agent.SetDestination(currentPath.points[pointIndex].position);
        // manager.agent.speed = manager.HappyWalkSpeed;
        manager.health.enabled = false;
        manager.agent.enabled = false;
        faceMat = Array.Find(manager.rend.materials, x=>x.name=="Face (Instance)");
        faceMat.SetTexture("_Texture", manager.happyFaces[1]);
        manager.healthbar.SetActive(false);
    }

    public override void UpdateState(EnemyStateManager manager)
    {
        // if(Time.time < _timer) return;
        // else if(!manager.agent.enabled){
        //     manager.agent.enabled = true;
        //     manager.anim.SetTrigger("HappyWalk");
        //     faceMat.SetTexture("_Texture", manager.happyFaces[1]);
        // } 

        // if(manager.agent.remainingDistance < manager.newPointThreshold){
        //     if(!returning){
        //         if(pointIndex == currentPath.points.Length-1){
        //             returning = true;
        //             manager.agent.SetDestination(currentPath.points[0].position);
        //             return;
        //         }
        //         pointIndex++;
        //         manager.agent.SetDestination(currentPath.points[pointIndex].position);
        //     }
        //     else{
        //         returning = false;
        //         pointIndex = 0;
        //         currentPath = manager.pathList[Random.Range(0, manager.pathList.Length)];
        //         manager.agent.SetDestination(currentPath.points[pointIndex].position);
        //     }
        // }
    }
}
