using Godot;
using System;

public partial class PopupDialog : PopupPanel
{
	private int minWidth = 600;
	
	public override void _Ready()
	{
		this.Hide();

		((Label)FindChild("Title")).Text = this.Title;
		((Button)FindChild("CloseButton")).Pressed += OnClosePressed;

		UpdatePanelWidth();
    }

	[Export]
	public int MinWidth
    {
		get => minWidth;

        set
		{
			minWidth = value;

			UpdatePanelWidth();
        }
    }

	private void OnClosePressed()
	{
		this.Hide();
	}
	
	private void UpdatePanelWidth()
	{
		var container = (PanelContainer)FindChild("PanelContainer");
		var minSize = container.CustomMinimumSize;
		minSize.X = minWidth;

		container.CustomMinimumSize = minSize;
    }
}
