using System;
using FastReport.Utils;

namespace FastReport.Design.PageDesigners.Code
{
    internal class FRXPageSettings
    {
        #region Fields

        private static bool FUseSpaces;
        private static bool enable;
        private static int FTabSize;

        #endregion

        #region Properties

        public static bool UseSpaces
        {
            get { return FUseSpaces; }
            set { FUseSpaces = value; }
        }

        public static bool Enable
        {
            get { return enable; }
            set { enable = value; }
        }

        public static int TabSize
        {
            get { return FTabSize; }
            set { FTabSize = value; }
        }

        #endregion

        #region Public Methods

        public static void SaveState()
        {
            XmlItem xi = Config.Root.FindItem("Designer").FindItem("FRXPage");
            xi.SetProp("UseSpaces", UseSpaces ? "1" : "0");
            xi.SetProp("Enable", Enable ? "1" : "0");
            xi.SetProp("TabSize", TabSize.ToString());
        }

        static FRXPageSettings()
        {
            XmlItem xi = Config.Root.FindItem("Designer").FindItem("FRXPage");

            UseSpaces = xi.GetProp("UseSpaces") != "0";
            Enable = xi.GetProp("Enable") == "1";

            string tabSize = xi.GetProp("TabSize");
            if (String.IsNullOrEmpty(tabSize))
                tabSize = "2";
            TabSize = int.Parse(tabSize);
        }

        #endregion
    }
}
