using System;
using UnityEngine;

namespace Wizard.Dialog.Setting;

public class ItemSlider : Item
{
	[SerializeField]
	private SettingBase m_parant;

	[SerializeField]
	private UILabel m_titleLabel;

	[SerializeField]
	private UILabel m_valueLabel;

	[SerializeField]
	private UISlider m_slider;

	[SerializeField]
	private UISprite m_foregroundSprite;

	[SerializeField]
	private UISprite _foregroundEdgeSprite;

	[SerializeField]
	private UISprite m_thumbSprite;

	[SerializeField]
	private GameObject m_separatorLineObj;

	private const string FOREGROUND_ON_SPRITE_NAME = "gauge_blue_bottom";

	private const string FOREGROUND_OFF_SPRITE_NAME = "gauge_gray_bottom";

	private const string FOREGROUND_EDGE_ON_SPRITE_NAME = "gauge_blue_edge";

	private const string FOREGROUND_EDGE_OFF_SPRITE_NAME = "gauge_gray_edge";

	private const string THUMB_ON_SPRITE_NAME = "btn_gauge_on";

	private const string THUMB_OFF_SPRITE_NAME = "btn_gauge_off";

	private bool m_isPlaySe;

	private void Awake()
	{
		m_titleLabel.text = string.Empty;
		m_valueLabel.text = string.Empty;
		m_separatorLineObj.SetActive(value: false);
		AddChangeCallback(delegate
		{
			string text = Mathf.CeilToInt(m_slider.value * 10f).ToString();
			bool flag = m_valueLabel.text != text;
			m_valueLabel.text = text;
			if (m_isPlaySe)
			{
				if (flag)
				{
					GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BAR_SLIDE);
				}
			}
			else
			{
				m_isPlaySe = true;
			}
		});
	}

	public void SetValue(float value)
	{
		m_slider.value = value;
		m_isPlaySe = false;
	}

	public float GetValue()
	{
		return m_slider.value;
	}

	public void SetTitleLabel(string title)
	{
		m_titleLabel.text = title;
	}

	public void SetLooks(bool isOn)
	{
		m_foregroundSprite.spriteName = (isOn ? "gauge_blue_bottom" : "gauge_gray_bottom");
		_foregroundEdgeSprite.spriteName = (isOn ? "gauge_blue_edge" : "gauge_gray_edge");
		m_thumbSprite.spriteName = (isOn ? "btn_gauge_on" : "btn_gauge_off");
	}

	public override void AddChangeCallback(EventDelegate.Callback callback)
	{
		EventDelegate.Add(m_slider.onChange, callback);
	}

	public void AddDragFinishedCallback(UIProgressBar.OnDragFinished callback)
	{
		UISlider slider = m_slider;
		slider.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(slider.onDragFinished, callback);
	}

	public override void SetActive_SeparatorLine(bool isActive)
	{
		m_separatorLineObj.SetActive(isActive);
	}

	public void SetScrollView(UIScrollView view)
	{
		UIDragScrollView componentInChildren = m_slider.gameObject.GetComponentInChildren<UIDragScrollView>();
		componentInChildren.enabled = true;
		componentInChildren._dragEnabled = false;
		componentInChildren.scrollView = view;
	}
}
