using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace InABox.Core
{

    public enum DFLayoutHeaderAlignment
    {
        Left,
        Right
    }
    
    public class DFLayoutHeader : DFLayoutControl, IDFLayoutTextControl
    {
        [TextBoxEditor]
        [EditorSequence(-1)]
        public string Header { get; set; } = "";

        [CheckBoxEditor]
        [EditorSequence(0)]
        public bool Collapsed { get; set; } = false;

        [EnumLookupEditor(typeof(DFLayoutHeaderAlignment))]
        [EditorSequence(1)]
        public DFLayoutHeaderAlignment Alignment { get; set; } = DFLayoutHeaderAlignment.Left;

        [EditorSequence("Style", 0)]
        public DFLayoutTextStyle Style => InitializeField(ref _style, nameof(Style));
        private DFLayoutTextStyle _style;

        protected override void Init()
        {
            base.Init();
            Style.IsBold = true;
        }

        protected override string GetDescription()
        {
            return $"Header: {Header}";
        }

        protected override void LoadProperties()
        {
            base.LoadProperties();

            Header = GetProperty("Header", "");
            Collapsed = GetProperty("Collapsed", false);
            Alignment = GetProperty("Alignment", DFLayoutHeaderAlignment.Left);
            Style.LoadProperties(this);
        }

        protected override void SaveProperties()
        {
            base.SaveProperties();

            SetProperty("Header", Header);
            SetProperty("Collapsed", Collapsed);
            SetProperty("Alignment", Alignment);
            Style.SaveProperties(this);
        }

        public T GetStyleProperty<T>(string name, T defaultValue)
        {
            if (name == "IsBold") defaultValue = CoreUtils.ChangeType<T>(true) ?? defaultValue;
            return GetProperty($"Style.{name}", defaultValue);
        }

        public void SetStyleProperty(string name, object? value)
        {
            SetProperty($"Style.{name}", value);
        }
    }
}
