using System;
using System.Globalization;
using TMPro;
using UnityEngine;

namespace Cryville.EEW.Unity.UI {
	[RequireComponent(typeof(TMP_Text))]
	class TimeView : MonoBehaviour {
		TMP_Text _textView;

		void Awake() {
			_textView = GetComponent<TMP_Text>();
		}

		void Update() {
			var time = DateTime.Now;
			var timeZone = TimeZoneInfo.Local;
			if (SharedSettings.Instance.OverrideTimeZone is TimeZoneInfo tTimeZone)
				time = TimeZoneInfo.ConvertTime(time, timeZone, tTimeZone);
			else
				tTimeZone = timeZone;
			_textView.text = SharedSettings.Instance.DoDisplayTimeZone ? string.Format(CultureInfo.CurrentCulture, "{0:G} ({1})", time, tTimeZone.ToTimeZoneString()) : time.ToString(CultureInfo.CurrentCulture);
		}
	}
}
