﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ExCSS;
using System.Windows.Forms;
using System.Drawing;

using CSSForms.Library.DOM;

namespace CSSForms.Library
{
    public class StyleManager
    {
        private string _cssText, _filename;
        private StyleSheet _styleSheet;
        
        public static StyleManager FromCSSText(string text)
        {
            StyleManager manager = new StyleManager();
            manager._cssText = text;
            manager.Load();
            return manager;
        }

        public static StyleManager FromFile(string filepath)
        {
            StyleManager manager = new StyleManager();
            manager._cssText = File.ReadAllText(filepath);
            manager._filename = filepath;
            manager.Load();
            return manager;
        }

        private void Load()
        {
            Parser parser = new Parser();
            _styleSheet = parser.Parse(_cssText);
        }

        public DOMForm RegisterForm(Form form)
        {
            DOMForm dom = new DOMForm();
            dom.LoadFromWindowsForm(_cssText, form);
            return dom;
        }
    }
}
