using System;

namespace Monkey.UI.Windows
{

    public abstract class Window
    {

        private const int _windowBorderPadding = 10;

        private int identifier;
        private string title;
        private UnityEngine.Rect dimensions;

        public Window(int identifier, string title, UnityEngine.Rect dimensions)
        {
            if (String.IsNullOrEmpty(title))
                throw new ArgumentNullException(nameof(title));

            this.identifier = identifier;
            this.title = title;
            this.dimensions = dimensions;
        }

        public void CenterWindowOnScreen()
        {
            this.dimensions = new UnityEngine.Rect(
                ((UnityEngine.Screen.width / 2) - (this.dimensions.width / 2f)),
                ((UnityEngine.Screen.height / 2) - (this.dimensions.height / 2f)),
                this.dimensions.width,
                this.dimensions.height);
        }

        public void PositionWindowAtBottomRight()
        {
            this.dimensions = new UnityEngine.Rect(
                (UnityEngine.Screen.width - this.dimensions.width - _windowBorderPadding),
                (UnityEngine.Screen.height - this.dimensions.height - _windowBorderPadding),
                this.dimensions.width,
                this.dimensions.height);
        }

        public void Draw()
        {
            this.dimensions = UnityEngine.GUI.Window(this.identifier, this.dimensions, this.DrawContent, this.title);
        }

        protected abstract void DrawContent(int identifier);

    }

}
