﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using OKHOSTING.UI.Controls;

namespace OKHOSTING.UI.Console.Controls
{
    public class ActivityIndicator : Terminal.Gui.ProgressBar, IActivityIndicator
    {
        public ActivityIndicator()
        {
            base.Visible = false;
            base.Fraction = 1;
            _IsRunning = false;
        }

        protected bool _IsRunning;
        public bool IsRunning
        {
            get
            {
                return _IsRunning;
            }
            set
            {
                _IsRunning = value;

                if (_IsRunning)
                {
                    base.Pulse();
                }
            }
        }

        #region IControl
        public string Name
        {
            get
            {
                return base.Id.ToString();
            }
            set
            {
                base.Id = value;
            }
        }

        public bool Enabled
        {
            get;
            set;
        }

        public Thickness Margin
        {
            get;
            set;
        }

        public Thickness Padding
        {
            get;
            set;
        }

        public Color BackgroundColor
        {
            get;
            set;
        }

        public Color BorderColor
        {
            get;
            set;
        }

        public Thickness BorderWidth
        {
            get;
            set;
        }

        public HorizontalAlignment HorizontalAlignment
        {
            get;
            set;
        }

        public VerticalAlignment VerticalAlignment
        {
            get;
            set;
        }

        public object Tag
        {
            get;
            set;
        }

        public string CssClass
        {
            get;
            set;
        }

        public IControl Parent
        {
            get;
        }
        public Color Color
        {
            get;
            set;
        }

        double? IControl.Width
        {
            get
            {
                return double.Parse(base.Width.ToString());
            }
            set
            {
                base.Width = (Terminal.Gui.Dim)value;
            }
        }

        double? IControl.Height
        {
            get
            {
                return double.Parse(base.Height.ToString());
            }
            set
            {
                base.Height = (Terminal.Gui.Dim)value;
            }
        }

        public event EventHandler<bool> ValueChanged;

        public object Clone()
        {
            return base.MemberwiseClone();
        }

        public bool Focus()
        {
            return base.CanFocus;
        }
        #endregion
    }
}
