using System;
using Newlon.Components.Level;

namespace Newlon.Components.GUI.Seedpackets;

public class HotbarPregameHandler : SeedpacketHandler, ISeedpacketPress
{
    public HotbarPregameHandler(Seedpacket owner) : base(owner)
    {
        RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
        
    }

    public event Action Clicked;
    public void Pressed()
    {
        if (Clicked != null) Clicked();
        _owner.QueueFree();
        AudioSequencer.Play("tap", Seedpacket.UntapStream);
    }

    public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
    {
        if (state == RuntimeLevelData.LevelStates.Game)
        {
            _owner.SetHandler(new HotbarHandler(_owner));
        }
        else if (state != RuntimeLevelData.LevelStates.ChooseYourSeeds)
        {
            _owner.disablePacket = true;
        }
    }
}