using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace NotepadEnhanced.Refactexing
{
    public partial class AddRefactexForm : Form
    {
        public Stack<Refactex> ToBeAdded { get; private set; }

        public AddRefactexForm()
        {
            InitializeComponent();
            ToBeAdded = new Stack<Refactex>();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            Refactex refactex = new Refactex(txtName.Text, txtDescrip.Text, txtPattern.Text,
                txtReplacement.Text, regexOptionsPicker.GetCheckedOptions());

            ToBeAdded.Push(refactex);
            ResetControls();
        }

        private void ResetControls()
        {
            foreach (var textBox in this.Controls.OfType<TextBox>())
                textBox.Clear();

            regexOptionsPicker.UncheckAll();
        }

        private void MandatoryStringInput_TextChanged(object sender, EventArgs e)
        {
            btnAdd.Enabled = txtName.TextLength > 0 && txtPattern.TextLength > 0;
        }
    }
}
