using System;

namespace InABox.Core
{
    public abstract class DFLayoutControl : DFLayoutObject, ISequenceable
    {
        [IntegerEditor]
        [EditorSequence(1)]
        public int Row { get; set; } = 1;

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


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

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

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

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

        [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(nameof(Row), 1);
            RowSpan = GetProperty(nameof(RowSpan), 1);
            VerticalAlignment = GetProperty(nameof(VerticalAlignment), DFLayoutAlignment.Middle);
            Column = GetProperty(nameof(Column), 1);
            ColumnSpan = GetProperty(nameof(ColumnSpan), 1);
            HorizontalAlignment = GetProperty(nameof(HorizontalAlignment), DFLayoutAlignment.Middle);
            Sequence = GetProperty(nameof(Sequence), DateTime.Now.Ticks);
        }

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