using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PDF_Master.CustomControl
{
    /// <summary>
    /// BatchStatus.xaml 的交互逻辑
    /// </summary>
    public partial class BatchStatus : UserControl
    {
        public BatchStatus()
        {
            InitializeComponent();
        }

        public int MaxStatusValue
        {
            get { return (int)GetValue(MaxStatusValueProperty); }
            set
            {
                SetValue(MaxStatusValueProperty, value);

            }
        }

        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MaxStatusValueProperty =
            DependencyProperty.Register("MaxStatusValue", typeof(int), typeof(BatchStatus), new PropertyMetadata(10));

        public string StatusValue
        {
            get { return (string)GetValue(StatusValueProperty); }
            set
            {
                SetValue(StatusValueProperty, value);
            }
        }

        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty StatusValueProperty =
            DependencyProperty.Register("StatusValue", typeof(string), typeof(BatchStatus), new PropertyMetadata("wait",
            new PropertyChangedCallback(OnPropertyChanged), // 第3个值回调位置
            new CoerceValueCallback(OnCoerceValueCallback) // 第2个强制回调位置
        )
        , new ValidateValueCallback(OnValidateValueCallBack));

        static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {

            (d as BatchStatus).CalculateProgress(e.NewValue.ToString());
            
        }


        static object OnCoerceValueCallback(DependencyObject d, object obj)
        {
            
            return obj;
        }


        static bool OnValidateValueCallBack(object obj)
        {
           
            return true;
        }

        void CalculateProgress(string value)
        {
            if (value == "wait")
            {
                this.wait.Visibility = Visibility.Visible;
                this.complete.Visibility = Visibility.Hidden;
                this.error.Visibility = Visibility.Hidden;
                this.progress.Visibility = Visibility.Hidden;
            }
            if (value == "complete")
            {
                this.complete.Visibility = Visibility.Visible;
                this.wait.Visibility = Visibility.Hidden;
                this.error.Visibility = Visibility.Hidden;
                this.progress.Visibility = Visibility.Hidden;
            }
            if (value == "error")
            {
                this.error.Visibility = Visibility.Visible;
                this.wait.Visibility = Visibility.Hidden;
                this.complete.Visibility = Visibility.Hidden;
                this.progress.Visibility = Visibility.Hidden;
            }
            if (int.TryParse(value, out _))
            {
                this.progress.Visibility = Visibility.Visible;
                this.wait.Visibility = Visibility.Hidden;
                this.complete.Visibility = Visibility.Hidden;
                this.error.Visibility = Visibility.Hidden;
                double step = (double.Parse(value) / (double)MaxStatusValue) * Math.PI;
                progressBar.StrokeDashArray = new DoubleCollection() { step, 10000 };
            }

        }
      

       
    }
}