using System;
using MyGame.Scenes.Main.Scripts;
using MyGame.Scripts;
using UniRx;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class FooterManager : MonoBehaviour
{
    [SerializeField] private FooterButton kitchenButton;
    [SerializeField] private FooterButton fieldButton;
    [SerializeField] private FooterButton stockButton;
    [SerializeField] private FooterButton saleButton;
    [SerializeField] private FooterButton productManagementButton;
    [SerializeField] private GameObject stockNotifyIcon;
    [SerializeField] private GameObject kitchenNotifyIcon;
    
    private void Start()
    {
        if (!Enum.TryParse<GameScenes>(SceneManager.GetActiveScene().name, out var currentSceneName))
        {
            return;
        }
        kitchenButton.SetSelected(currentSceneName == GameScenes.Main);
        fieldButton.SetSelected(currentSceneName == GameScenes.CornField);
        stockButton.SetSelected(currentSceneName == GameScenes.shopping);
        saleButton.SetSelected(currentSceneName == GameScenes.marketing);
        productManagementButton.SetSelected(currentSceneName == GameScenes.ProductManagement);
        Observable.Merge(
                kitchenButton.ClickObservable.Select(_ => GameScenes.Main),
                fieldButton.ClickObservable.Select(_ => GameScenes.CornField),
                stockButton.ClickObservable.Select(_ => GameScenes.shopping),
                saleButton.ClickObservable.Select(_ => GameScenes.marketing),
                productManagementButton.ClickObservable.Select(_ => GameScenes.ProductManagement))
            .Take(1)
            .Subscribe(x =>
            {
                TransitionManager.Instance.LoadScene(x);
            }).AddTo(this);
        
        kitchenNotifyIcon.SetActive(AutoCookView.CheckComplete());
        stockNotifyIcon.SetActive(Shopping.CheckEarnedRecipe());
    }
}