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

namespace InABox.Core
{
    public class DFLayoutHeader : DFLayoutControl, IDFLayoutTextControl
    {
        [TextBoxEditor]
        [EditorSequence(-1)]
        public string Header { get; set; }

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

        [EditorSequence("Style", 0)]
        public DFLayoutTextStyle Style { get; set; }

        protected override void Init()
        {
            base.Init();
            Header = "";
            Collapsed = false;
            Style = new DFLayoutTextStyle { IsBold = true };
        }

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

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

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

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

            SetProperty("Header", Header);
            SetProperty("Collapsed", Collapsed);
            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);
        }
    }
}
