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;
    [SerializeField] private Button customizeButton;

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