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;
using ArcGIS.Core.Data;
using ArcGIS.Desktop.Core;
using OliviaAddInPro.Helper;
using OliviaAddInPro.View;
using OliviaAddInPro.Model;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Internal.Framework.Controls;

namespace OliviaAddInPro
{
    /// <summary>
    /// Interaction logic for PaneLimpiezaSub2View.xaml
    /// </summary>
    public partial class PaneLimpiezaSub2View : UserControl
    {
        public PaneLimpiezaSub2View()
        {
            InitializeComponent();
        }

        private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            e.Handled = !PanelGlobal.IsValid(((TextBox)sender).Text + e.Text,0,9999);
        }

        private void button_caparestr_Click(object sender, RoutedEventArgs e)
        {
            string texto = "";
            ArcGIS.Core.Geometry.Geometry geom = HelperGdb.OpenGeom(HelperGdb.TiposOpenFileDlg.OpenFtrClassPolygon, out texto, "", true);
            if (DataContext is PaneLimpiezaSub2ViewModel mod)
            {
                mod.GeomRestr = geom;
            }
            if (geom != null)
                label_caparestr.Content = texto;
            else
                label_caparestr.Content =Resource1.String_selec_capa;
        }

        private void button_capaniv_Click(object sender, RoutedEventArgs e)
        {
            string texto = "";
            ArcGIS.Core.Geometry.Geometry geom = HelperGdb.OpenGeom(HelperGdb.TiposOpenFileDlg.OpenFtrClassPolygon, out texto, "", true);
            if (DataContext is PaneLimpiezaSub2ViewModel mod)
            {
                mod.GeomNiv = geom;
            }
            if (geom != null)
                label_capaniv.Content = texto;
            else
                label_capaniv.Content = Resource1.String_selec_capa;         
        }

        private void button_capazon_Click(object sender, RoutedEventArgs e)
        {
            string texto = "";
            ArcGIS.Core.Geometry.Geometry geom = HelperGdb.OpenGeom(HelperGdb.TiposOpenFileDlg.OpenFtrClassPolygon, out texto, "", true);
            if (DataContext is PaneLimpiezaSub2ViewModel mod)
            {
                mod.GeomZon = geom;
            }

            if (geom != null)
                label_capazon.Content = texto;
            else
                label_capazon.Content = Resource1.String_selec_capa;
        }

        private void button_capainst_Click(object sender, RoutedEventArgs e)
        {
            string texto = "";

            ArcGIS.Core.Geometry.Geometry geomsal = HelperGdb.OpenGeom(HelperGdb.TiposOpenFileDlg.OpenFtrClassPoint, out texto);

            if ((DataContext is PaneLimpiezaSub2ViewModel mod) && (geomsal != null))                
            {
                if (geomsal is MapPoint map)
                    mod.CoordsInstal = map.Coordinate2D;
                else if (geomsal is Multipoint multip)
                {
                    if(multip.Copy2DCoordinatesToList().Count>0)
                        mod.CoordsInstal = multip.Copy2DCoordinatesToList().First();
                }

            }
            if (geomsal != null)
                label_capainst.Content = texto;
            else
                label_capainst.Content = Resource1.String_selec_capa;
        }
    }
}
