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

public class FilterInstruments : MonoBehaviour
{
    private GameObject AllInstruments;
    private Transform[] children;

    void Start()
    {
        AllInstruments = GameObject.Find("AllInstruments");
        children = AllInstruments.GetComponentsInChildren<Transform>();
    }

    public void ShowBasses()
    {
        ShowByType("Bass");
    }

    public void ShowGuitars()
    {
        ShowByType("Guitar");
    }

    public void PriceLessThan300()
    {
        ShowByPrice(300);
    }

    public void PriceLessThan500()
    {
        ShowByPrice(500);
    }

    public void Reset()
    {
        ShowByType("");
    }

    private void ShowByType(string typeOfInstrument)
    {
        foreach (var child in children)
        {
            if (child.name.Contains(typeOfInstrument) || child.name.Contains("All"))
            {
                child.gameObject.SetActive(true);
            }
            else
            {
                child.gameObject.SetActive(false);
            }
        }
    }

    private void ShowByPrice(int price)
    {
        foreach (var child in children)
        {
            InstrumentInfo info = child.gameObject.GetComponent("InstrumentInfo") as InstrumentInfo;
            if(info)
            {
                if (info.price < price)
                {
                    child.gameObject.SetActive(true);
                }
                else
                {
                    child.gameObject.SetActive(false);
                }
            }
        }
    }
}
