using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using C1.Silverlight;

namespace C1_Demo
{
    public partial class DemoTabControl
    {
        public DemoTabControl()
        {
            InitializeComponent();
        }

        public C1TabItemCloseOptions DEMO_TabItemClose
        {
            get { return tabControl.TabItemClose; }
            set { tabControl.TabItemClose = value; }
        }
        public C1TabItemShape DEMO_TabItemShape
        {
            get { return tabControl.TabItemShape; }
            set { tabControl.TabItemShape = value; }
        }
        public Visibility DEMO_TabStripMenuVisibility
        {
            get { return tabControl.TabStripMenuVisibility; }
            set { tabControl.TabStripMenuVisibility = value; }
        }
        public int DEMO_TabStripOverlap
        {
            get { return tabControl.TabStripOverlap; }
            set { tabControl.TabStripOverlap = value; }
        }
        public C1TabPanelOverlapDirection DEMO_TabStripOverlapDirection
        {
            get { return tabControl.TabStripOverlapDirection; }
            set { tabControl.TabStripOverlapDirection = value; }
        }
        public Dock DEMO_TabStripPlacement
        {
            get { return tabControl.TabStripPlacement; }
            set { tabControl.TabStripPlacement = value; }
        }
        public Brush DEMO_Background
        {
            get { return tabControl.Background; }
            set { tabControl.Background = value; }
        }
        public Brush DEMO_Foreground
        {
            get { return tabControl.Foreground; }
            set { tabControl.Foreground = value; }
        }


        private bool _closing = false;
        private void tabs_TabClosing(object sender, CancelSourceEventArgs e)
        {
            if (!_closing)
            {
                _closing = true;
                C1TabItem tabItem = (C1TabItem)e.Source;
                e.Cancel = true;
                C1.Silverlight.C1MessageBox.Show("Do you really want to close this tab?", "Close Tabs?", C1MessageBoxButton.YesNo, C1MessageBoxIcon.Question,
                    (result) =>
                    {
                        if (result == MessageBoxResult.Yes)
                        {
                            tabControl.Items.Remove(tabItem);
                        }
                        _closing = false;
                    });
            }
        }

        private void C1TabItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // create new item
            var item = new C1TabItem()
            {
                Header = string.Format("Item {0}", tabControl.Items.Count)
            };

            tabControl.Items.Insert(tabControl.Items.Count - 1, item);
            tabControl.SelectedItem = item;
        }
    }
}
