using PCUT.ViewModels;
using System.Linq;
using Windows.UI.Xaml.Controls;

// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace PCUT.Pages
{
    public sealed partial class SvgNestSettingDialog : ContentDialog
    {
        public SvgNestSettings NestSettings { get; set; }

        public SvgNestSettingDialog()
        {
            this.InitializeComponent();
            NestSettings = SvgNestSettings.Instance;
        }

        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            NestSettings.SaveSettings();
            NestSettings.ApplySettings();
        }

        private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            NestSettings.LoadSettings();
            NestSettings.ApplySettings();
        }

        private void TextBox_ValidateInt(TextBox sender, TextBoxBeforeTextChangingEventArgs args)
        {
            args.Cancel = args.NewText.Any(ch => !char.IsDigit(ch));
        }

        private void TextBox_ValidateDouble(TextBox sender, TextBoxBeforeTextChangingEventArgs args)
        {
            args.Cancel = args.NewText.Any(ch => !char.IsDigit(ch) && ch != '.');
        }
    }
}
