using System;
using System.Drawing;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Spark3D.View2D.Widgets
{
    public class Widget
    {
        public Widget(int width, int height, int x, int y)
        {
            this.Size = new Size(width, height);
            this.Location = new Point(x, y);
            this.Text = String.Empty;
            this.Area = new Rectangle(x + Theme.BorderWidth, y + Theme.BorderWidth, width - (Theme.BorderWidth * 2), height - (Theme.BorderWidth * 2));
            this.Border = new Rectangle(x, y, width, height);
            this.Padding = Theme.DefaultPadding;
            this.Opacity = Theme.DefaultOpacity;
            this.ContainedWidgets = new List<Widget>();
            this.ForeColor = Theme.ForeColor;
            this.BackColor = Theme.BackColor;
            this.TextColor = Theme.TextColor;
            this.BorderColor = Theme.BorderColor;
            this.Font = Theme.Font;
        }

        public virtual Size Size
        {
            get;
            set;
        }
        public virtual Point Location
        {
            get;
            set;
        }
        public virtual String Text
        {
            get;
            set;
        }
        public virtual Rectangle Area
        {
            get;
            set;
        }
        public virtual Rectangle Border
        {
            get;
            set;
        }
        public virtual int Padding
        {
            get;
            set;
        }
        public virtual int Opacity
        {
            get;
            set;
        }
        public virtual List<Widget> ContainedWidgets
        {
            get;
            private set;
        }
        public virtual Color ForeColor
        {
            get;
            set;
        }
        public virtual Color BackColor
        {
            get;
            set;
        }
        public virtual Color TextColor
        {
            get;
            set;
        }
        public virtual Color BorderColor
        {
            get;
            set;
        }
        public virtual Font Font
        {
            get;
            set;
        }
        public virtual void AddWidget(Widget w)
        {
            w.Padding += this.Padding;
            w.Location = new Point(w.Location.X, w.Location.Y + 25);
            this.ContainedWidgets.Add(w);
        }
        public virtual void Draw(ref Graphics g)
        {
            g.FillRectangle(new SolidBrush(Color.FromArgb(this.Opacity, this.BorderColor)), this.Border);
            g.FillRectangle(new SolidBrush(Color.FromArgb(this.Opacity, this.BackColor)), this.Area);
            foreach (Widget w in ContainedWidgets)
            {
                w.Draw(ref g);
            }
            PointF LocationWithPadding = new PointF((float)this.Padding*2, (float)this.Padding*2);
            g.DrawString(this.Text, Theme.TitleFont, new SolidBrush(this.ForeColor), LocationWithPadding);
        }
    }
}
