using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.Utils.Drawing.Helpers;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using PXP.Crawler.API.Model;

namespace PXP.Crawler.Forms.Edit
{
    public partial class EditXtraForm : DevExpress.XtraEditors.XtraForm
    {
        #region Variables

        private Padding tabAdjust = new Padding(-5, -3, 10, 6);
        internal PopupMenu popupMenu;
        internal string filePath = "";
        private string tabText = "";

        #endregion

        #region Constructor

        public EditXtraForm()
        {
            InitializeComponent();


            if (!DesignMode)
            {
                pagesXtraTabControl.Dock = DockStyle.None;
            }
        }

        #endregion

        #region Properties

        public PopupMenu PopupMenu
        {
            get { return popupMenu; }
            set
            {
                popupMenu = value;
            }
        }

        public virtual bool CanSave
        {
            get { return false; }
        }

        public virtual bool CanDelete
        {
            get { return false; }
        }

        #endregion

        #region Methods

        public virtual void DoSave(string filePath)
        {
            this.filePath = filePath;
        }

        #endregion

        #region Overrides

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            pagesXtraTabControl.Location = new Point(tabAdjust.Left, tabAdjust.Top);
            pagesXtraTabControl.Size = new Size(ClientRectangle.Width + tabAdjust.Right,
                ClientRectangle.Height + tabAdjust.Bottom);
        }

        #endregion

        private void pagesXtraTabControl_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            if (tabText.Length == 0)
                tabText = Text;

            if (e.Page != null)
            {
                Text = tabText;
                if (e.Page.Tag is PXP.Crawler.API.Model.ProjectItem)
                {
                    var pr = (PXP.Crawler.API.Model.ProjectItem)e.Page.Tag;
                    switch (pr.Type)
                    {
                            case ProjectItem.ProjectItemType.Program:
                                Text += " (Program: " + pr.Name +  ")";
                            break;
                    }
                }
            }
            else
            {
                Text = tabText;
            }
        }

    }
}