using System;

namespace InABox.Core
{
    public abstract class DFLayoutControl : DFLayoutObject, ISequenceable
    {
        protected override void Init()
        {
            base.Init();
            Row = 1;
            RowSpan = 1;
            Column = 1;
            ColumnSpan = 1;
            HorizontalAlignment = DFLayoutAlignment.Stretch;
            VerticalAlignment = DFLayoutAlignment.Stretch;
        }

        [IntegerEditor]
        [EditorSequence(1)]
        public int Row { get; set; }

        [IntegerEditor]
        [EditorSequence(2)]
        public int RowSpan { get; set; }


        [EnumLookupEditor(typeof(DFLayoutAlignment))]
        [EditorSequence(3)]
        public DFLayoutAlignment VerticalAlignment { get; set; }

        [IntegerEditor]
        [EditorSequence(4)]
        public int Column { get; set; }

        [IntegerEditor]
        [EditorSequence(5)]
        public int ColumnSpan { get; set; }

        [EnumLookupEditor(typeof(DFLayoutAlignment))]
        [EditorSequence(6)]
        public DFLayoutAlignment HorizontalAlignment { get; set; }

        [TextBoxEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
        [DoNotSerialize]
        public string Description => GetDescription();


        [NullEditor]
        public long Sequence { get; set; }

        protected virtual string GetDescription()
        {
            return GetType().Name;
        }

        protected override void LoadProperties()
        {
            Row = GetProperty("Row", 0);
            RowSpan = GetProperty("RowSpan", 1);
            VerticalAlignment = GetProperty("VerticalAlignment", DFLayoutAlignment.Middle);
            Column = GetProperty("Column", 0);
            ColumnSpan = GetProperty("ColumnSpan", 1);
            HorizontalAlignment = GetProperty("HorizontalAlignment", DFLayoutAlignment.Middle);
            Sequence = GetProperty("Sequence", DateTime.Now.Ticks);
        }

        protected override void SaveProperties()
        {
            SetProperty("Row", Row);
            SetProperty("RowSpan", RowSpan);
            SetProperty("VerticalAlignment", VerticalAlignment);
            SetProperty("Column", Column);
            SetProperty("ColumnSpan", ColumnSpan);
            SetProperty("HorizontalAlignment", HorizontalAlignment);
            SetProperty("Sequence", Sequence);
        }
    }
}