using InABox.Core;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace InABox.DynamicGrid
{
    public abstract class DynamicFormControl : ContentControl
    {
        public DynamicFormDesignGrid FormDesignGrid { get; set; }

        protected abstract FrameworkElement Create();

        public abstract void SetControl(DFLayoutControl control);
    }

    public abstract class DynamicFormControl<TControl> : DynamicFormControl
        where TControl : DFLayoutControl
    {
        private TControl control;
        public TControl Control
        {
            get => control;
            set
            {
                control = value;
                Content = Create();
                AfterSetControl(control);
            }
        }

        protected virtual void AfterSetControl(TControl control)
        {
        }

        public override void SetControl(DFLayoutControl control) => Control = (TControl)control;
    }
}
