﻿using Ashram.Bhajans.Database.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

namespace Ashram.Bhajans.Views
{
    /// <summary>
    /// @author Mayank Grover 
    /// </summary>

    public class ViewDynamicItemCategory: View
    {
        private static Color selectedButtonColor;
        public Toggle ToggleButtonCategory;
        public Text CategoryName;

        public Action OnClickCategory;

        public Font PunjabiFont;

        protected override void OnAwake()
        {
            base.OnAwake();
            selectedButtonColor = GetComponent<Image>().color;
        }

        protected override void OnStart()
        {
            base.OnStart();
            ToggleButtonCategory.group = transform.parent.GetComponent<ToggleGroup>();
        }

        protected override void RegisterClickHandlers()
        {
            base.RegisterClickHandlers();

            ToggleButtonCategory.onValueChanged.AddListener((value) => {
                if (value && OnClickCategory != null) OnClickCategory();

                ToggleButtonCategory.GetComponent<Image>().color = 
                    value ? selectedButtonColor : Color.white;
            });
        }

        public void UpdateFontToPunjabi()
        {
            CategoryName.font = PunjabiFont;
        }

        public void UpdateView(TableCategories data)
        {
            CategoryName.text = data.Name;
        }
    }
}
