using System;
using System.Collections.Generic;
using System.Linq;
using UniRx;
using UnityEngine;
using UnityEngine.Analytics;
using UnityEngine.UI;

public class HeaderManager : MonoBehaviour
{
    [SerializeField] private Button settingButton;
    [SerializeField] private Button missionButton;
    [SerializeField] private Button informationButton;
    [SerializeField] private GameObject missionIndicator;

    private void Start()
    {
        var isOpenMission = false;
        settingButton.OnClickAsObservable().ThrottleFirst(TimeSpan.FromSeconds(1f)).Subscribe(_ =>
        {
            TransitionManager.Instance.LoadSceneAdditive(GameScenes.SettingsDialog);
        });
        missionButton.OnClickAsObservable().ThrottleFirst(TimeSpan.FromSeconds(1f)).Subscribe(_ =>
        {
            isOpenMission = true;
            MissionManager.ShowDialog(() =>
                {
                    isOpenMission = false;
                    missionIndicator.SetActive(GameDataObserver.Instance.UpdateMissionAchieved.Value);
                },
                active => missionIndicator.SetActive(active));
        });
        informationButton.OnClickAsObservable().ThrottleFirst(TimeSpan.FromSeconds(1f)).Subscribe(_ =>
        {
            TransitionManager.Instance.LoadSceneAdditive(GameScenes.Information);
        });
        // mission報酬通知
        GameDataObserver.Instance.UpdateMissionAchieved
            .Where(_ => !isOpenMission).Subscribe(x =>
            {
                Debug.Log($"mission achieved:{x}");
                missionIndicator.SetActive(x);
            }).AddTo(this);
    }
}
