using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class selectCategoriesPanelController : MonoBehaviour
{

    [SerializeField] Button OpenDialogButton; 
    [SerializeField] GameObject SelectCategoriesDialog;
    [SerializeField] Text SelectCategoriesText;

    private int selectedQuestionCount;

    private SelectCategoryScript selectCategoryScript;

    public int SelectedQuestionCount { get => selectedQuestionCount; set => selectedQuestionCount = value; }

    // Start is called before the first frame update
    void Start()
    {
        OpenDialogButton.onClick.AddListener(ShowDialog);
        selectCategoryScript = SelectCategoriesDialog.GetComponent<SelectCategoryScript>();
        SelectCategoriesText.text = string.Format(LocalizationManager.Instance.GetText("SELECT_CATEGORIES_TEXT_ALL"), 
            LocalizationManager.Instance.GetText("ALL"));
    }

    // Update is called once per frame
    void Update()
    {
        if (SelectCategoriesText.text.Contains("{")) {
            SelectCategoriesText.text = string.Format(LocalizationManager.Instance.GetText("SELECT_CATEGORIES_TEXT_ALL"), 
                LocalizationManager.Instance.GetText("ALL"));
        }
    }

    public void UpdateCategoryText(int questionCount) {
        SelectCategoriesText.text = string.Format(LocalizationManager.Instance.GetText("SELECT_CATEGORIES_TEXT"), 
            selectCategoryScript.GetCategoriesSelectedCount(), 
            questionCount);
            SelectedQuestionCount = questionCount;
    }

    internal void ShowDialog() {
        SelectCategoriesDialog.SetActive(true);
    }

    public List<CategoryPanel.Category> GetSelectedCategories() {
        List<CategoryPanel.Category> selectedCategories = selectCategoryScript.GetSelectedCategories();
        return selectedCategories;
    }
}
