using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Zenject;
using UltraFace;
using TMPro;

public class SettingsUI : MonoBehaviour
{
    [Inject] private Visualizer _visualizer;
    [Inject] private DetectionSetup _detectionSetup;

    [SerializeField] private TMP_Text _faceCounterText;
    [SerializeField] private TMP_Text _minFaceHeight;
    [SerializeField] private TMP_Text _maxFaceHeight;
    [SerializeField] private Button _acceptButton;

    private void Start()
    {
        _acceptButton.onClick.AddListener(() => OnAcceptButtonClick());
    }

    private void OnAcceptButtonClick()
    {
        _detectionSetup.SetMinFaceHeight(float.Parse(_maxFaceHeight.text));
        Debug.LogWarning($"минимальная дистанция - {_maxFaceHeight.text}");
        _visualizer.Init();
        
        Destroy(gameObject);
    }

    private void Update()
    {
        var faceCounter = _visualizer.faceCounter;
        var minFaceHeight = _visualizer.minFaceHeight;
        var maxFaceHeight = _visualizer.maxFaceHeight;

        _faceCounterText.text = faceCounter.ToString();
        _faceCounterText.color = faceCounter != 0 ? Color.green : Color.red;

        _minFaceHeight.text = minFaceHeight.ToString();
        _maxFaceHeight.text = maxFaceHeight.ToString();
    }


    private void OnDestroy()
    {
        _acceptButton.onClick.RemoveAllListeners();    
    }
}
