using System;
using System.Windows.Forms;

namespace MuseumWinForms
{
    public partial class InputDialog : Form
    {
        public string InputText { get; private set; }

        public InputDialog(string prompt, string title, string defaultValue = "")
        {
            InitializeComponent();
            this.Text = title;
            lblPrompt.Text = prompt;
            txtInput.Text = defaultValue;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            InputText = txtInput.Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void InitializeComponent()
        {
            this.lblPrompt = new Label();
            this.txtInput = new TextBox();
            this.btnOK = new Button();
            this.btnCancel = new Button();
            this.SuspendLayout();

            // lblPrompt
            this.lblPrompt.AutoSize = true;
            this.lblPrompt.Location = new System.Drawing.Point(12, 15);
            this.lblPrompt.Size = new System.Drawing.Size(100, 20);
            this.lblPrompt.Text = "Prompt";

            // txtInput
            this.txtInput.Location = new System.Drawing.Point(12, 40);
            this.txtInput.Size = new System.Drawing.Size(260, 22);

            // btnOK
            this.btnOK.Location = new System.Drawing.Point(110, 75);
            this.btnOK.Size = new System.Drawing.Size(75, 30);
            this.btnOK.Text = "OK";
            this.btnOK.UseVisualStyleBackColor = true;
            this.btnOK.Click += new EventHandler(btnOK_Click);

            // btnCancel
            this.btnCancel.Location = new System.Drawing.Point(195, 75);
            this.btnCancel.Size = new System.Drawing.Size(75, 30);
            this.btnCancel.Text = "Отмена";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(btnCancel_Click);

            // Form
            this.ClientSize = new System.Drawing.Size(284, 121);
            this.Controls.Add(this.lblPrompt);
            this.Controls.Add(this.txtInput);
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.btnCancel);
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.StartPosition = FormStartPosition.CenterParent;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private Label lblPrompt;
        private TextBox txtInput;
        private Button btnOK;
        private Button btnCancel;
    }

    public static class InputBox
    {
        public static string Show(string prompt, string title, string defaultValue = "")
        {
            using (var dialog = new InputDialog(prompt, title, defaultValue))
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                    return dialog.InputText;
                return "";
            }
        }
    }
}