using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
[Serializable]
public struct path{
    public Transform[] points;

}
public class EnemyStateManager : MonoBehaviour
{
    public float playerInFrontDetectionThreshold = 0;
    public float playerBehindDetectionThreshold = 0;
    public float enemyShootDistanceThreshold = 0;
    public float enemyLoosePlayerThreshold = 0;
    public float happyTime = 0;
    public Texture[] happyFaces = {};
    public GameObject projectile = null;
    public float HappyWalkSpeed = 1.5f;
    public Health health;
    public GameObject healthbar;
    public float shootPeriod = 0;
    public Transform shootPos = null;
    public float newPointThreshold = 0; //how close the agent has to get to his destination to go to next point in path
    public float dotProductThreshold = 0; //if dot -1 the enemy is looking in the opposite direction of the player, if dot 1 the enemy is looking directly at the player
    public path[] pathList;
    public Transform player;
    public Transform playerHead;
    public Transform head;
    public NavMeshAgent agent;
    public Animator anim;
    public Renderer rend;
    public Transform pointToEnterIsland;
    public EnemyRoamingState roamingState = new EnemyRoamingState();
    private EnemyBaseState currentState = null;
    public EnemyFollowPlayerState followState = new EnemyFollowPlayerState();
    public EnemyHappyWalkState happyWalkState = new EnemyHappyWalkState();
    public EnemyEnterIslandState enterIslandState = new EnemyEnterIslandState();
    void Start()
    {
        currentState = enterIslandState;
        currentState.EnterState(this);
        GetComponent<Health>().death.AddListener(delegate{SwitchState(happyWalkState);});
        player = GameObject.FindGameObjectWithTag("Player").transform;
        playerHead = Camera.main.transform;
        head = transform.Find("HeadLevel");
        agent = GetComponent<NavMeshAgent>();
        anim = GetComponentInChildren<Animator>();
        rend = GetComponentInChildren<Renderer>();
        
    }

    void Update()
    {
        currentState.UpdateState(this);
    }

    public void SwitchState(EnemyBaseState state){
        currentState = state;
        state.EnterState(this);
    }
}
