using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
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_Office.Views.Dialog.HomePageToolsDialogs
{
    /// <summary>
    /// MainPageInsertDialog.xaml 的交互逻辑
    /// </summary>
    public partial class HomePageInsertDialog : UserControl
    {
        public HomePageInsertDialog()
        {
            InitializeComponent();
        }

        private void PageInsertIndexTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (this.PageInsertIndexTextBox.Text == "" || int.Parse(this.PageInsertIndexTextBox.Text) < 1)
            {
                this.PageInsertIndexTextBox.Text = "1";
            }
            if (this.PageCountText != null)
            {
                if (int.Parse(this.PageInsertIndexTextBox.Text) > int.Parse(this.PageCountText.Text))
                {
                    this.PageInsertIndexTextBox.Text = this.PageCountText.Text;
                }
            }

            ((HomePageInsertDialogViewModel)this.DataContext).PageInsertIndex = this.PageInsertIndexTextBox.Text;

        }
        private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
        }

        private void PageTurningPreview_Loaded(object sender, RoutedEventArgs e)
        {
            InsertPreview.document = ((HomePageInsertDialogViewModel)this.DataContext).document;
            InsertPreview.AwaitRenderBitmap(InsertPreview.document);
            InsertPreview.PageIndex.Text = InsertPreview.document.PageCount.ToString();
        }
    }
}
