using Modèle;
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 Persistance;
using Business;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    /// 



    public partial class MainWindow : Window
    {
        public Manager Mgr => (Application.Current as App).LeManager;
        public MainWindow()
        {
            InitializeComponent();

            Mgr.LoadRequins();

            DataContext = Mgr;


            chargerUC();
            List<Zone> zones = new List<Zone> { Zone.ATLANTIQUE, Zone.ARCTIQUE };
            //uc1.requin = new Requin("Bob le bricoleur", "Heterodontus Mexicanus", "*Ronflements*", "Images/Dormeur-Mexicain.jpg", "Videos/Vid-dormeur-Mexicain.mp4", "Images/rep_Heterodontus_mexicanus.png", Conservation.DD, zones, "Hé laissez moi je fais dodo!");
            // uc2.requin = new Requin("Requin Dormeur Mexdzdqzdicain", "Heterodontus Mexicanus", "*Ronflements*", "Images/Dormeur-Mexicain.jpg", "Videos/Vid-dormeur-Mexicain.mp4", "Images/rep_Heterodontus_mexicanus.png", Conservation.DD, zones, "Hé laissez moi je fais dodo!");
        }


        // Requin requin { get; set; }



        private void Region_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (Region.SelectedIndex == 0)
            {
                chargerUC();
            }
            
            else if (Region.SelectedIndex == 1)
            {
                chargerUC();
                changerListBox(Zone.ARCTIQUE);
            }
            else if (Region.SelectedIndex == 2)
            {
                chargerUC();
                changerListBox(Zone.ATLANTIQUE);
            }
            else if (Region.SelectedIndex == 3)
            {
                chargerUC();
                changerListBox(Zone.INDIEN);
            }
            else if (Region.SelectedIndex == 4)
            {
                chargerUC();
                changerListBox(Zone.PACIFIQUE);
            }
        }

        public void ContentControlSwapDes(Requin req)
        {
            contentControl.Content = new userControlDescription { requin = req };
        }



        public void ContentControlSwapAcc()
        {

            contentControl.Content = new userControlAcceuil();
        }


        public void ContentControlSwapEdit(Requin req)
        {
            contentControl.Content = new UserControlEdit { requin = req };
        }

        private void TextBox_IsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (Rechercher.Text == "Rechercher")
            {
                Rechercher.Text = "";
            }
        }

        public string Recherche
        {
            set
            {
                Rechercher.Text = value;
            }
        }



        public void chargerUC()
        {
            viderListBox();
            foreach(Requin req in Mgr.Requins)
            {
                laListe.Items.Add(new UserControlRequin { requin = req });
            }
        }

        public void changerListBox(Zone zone)
        {
            int test = 0;
            int i = 0;
            foreach (Requin req in Mgr.Requins)
            {
                foreach (Zone z in req.Repartition)
                {
                    if (z == zone)
                    {
                        test++;
                    }
                }
                if (test == 0)
                {
                    laListe.Items.RemoveAt(i);
                }
                else
                {
                    i++;
                }
                test = 0;
            }
        }

        public void viderListBox()
        {
            if (laListe != null)
            {
                while (laListe.Items.Count > 0)
                {
                    laListe.Items.RemoveAt(0);
                }
            }
        }
    }
}
