using System;
using UnityEngine;
using UnityEngine.UI;

public class ScoreController : MonoBehaviour
{
    [SerializeField]
    Text _currentScoreCounter;
    [SerializeField]
    Text _multiplierCounter;
    [SerializeField]
    Text _totalScoreCounter;
    [SerializeField]
    Text _comboCounter;
    
    static ScoreController _instance;
    public static ScoreController instance
    {
        get
        {
            return _instance;
        }
    }

    float _multiplier = 1.0f;
    int _totalScore = 0;
    int _currentScore = 100;
    int _combo = 0;


    void Start()
    {
        _instance = this;
        currentScore = totalScore = combo = 0;
        multiplier = 1.0f;
        UpdateTotalScore();
    }


    public float multiplier
    {
        get { return _multiplier; }
        set
        {
            _multiplier = value;
            _multiplierCounter.text = _multiplier.ToString(".0#");
        }
    }

    public int currentScore
    {
        get { return _currentScore; }
        set
        {
            _currentScore = value;
            _currentScoreCounter.text = _currentScore.ToString();
        }
    }

    public int totalScore
    {
        get
        {
            return _totalScore;
        }
        set
        {
            _totalScore = value;
             ScoreContainer.totalScore = _totalScore;
            _totalScoreCounter.text = _totalScore.ToString();

        }
    }

    public int combo
    {
        get { return _combo; }
        set
        {
            _combo = value;
            _comboCounter.text = value.ToString();
        }
    }

    public void OnMissedHit()
    {
        OnBadResult();
    }


    public void OnHitNothing()
    {
        OnBadResult();
        AudioClip ad = new AudioClip();
            
    }

    public void OnBadResult()
    {
        UpdateTotalScore();
        multiplier = 1.0f;
        combo = 0;
        currentScore = 0;
    }

    public void OnPerfectHit()
    {
        multiplier += 0.1f;
        currentScore += 100;
        combo += 1;
        WomboComboShower.instance.ShowCombo(combo);
    }

    public void OnNormalHit(float hitPercent)
    {
        multiplier = 1.0f;
        UpdateTotalScore();
        currentScore = Convert.ToInt32( hitPercent * 100);
        combo = 0;
    }

    public void UpdateTotalScore()
    {
        totalScore += (int)(currentScore * multiplier);
    }

    

    




}
