using Exam_Gromov.Classes;
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 Exam_Gromov
{
    /// <summary>
    /// Логика взаимодействия для List_Page.xaml
    /// </summary>
    public partial class List_Page : Page
    {

        List<books> ListBooks = BD.BaseModel.books.ToList();
        List<books> ListBook = new List<books>();
        
        int i = -1;

        public List_Page()
        {
            InitializeComponent();
            ListBook = ListBooks;
            Table_Inf.ItemsSource = ListBook;
        }

        private void MediaElement_Initialized(object sender, EventArgs e)
        {
            i++;
            if (i < ListBook.Count)
            {
                MediaElement ServiceImages = (MediaElement)sender;
                books ObjectService = ListBook[i];
                Uri uri = new Uri(ObjectService.cover, UriKind.RelativeOrAbsolute);
                ServiceImages.Source = uri;
                ServiceImages.Stretch = Stretch.Fill;
            }
        }

        private void StackPanel_Initialized(object sender, EventArgs e)
        {

        }

        private void TextBlock_Initialized(object sender, EventArgs e)
        {
            if (i < ListBook.Count)
            {
                TextBlock Title = (TextBlock)sender;
                books ObjectService = ListBook[i];
                Title.Text = "Название: " + ObjectService.title;
            }
        }

        private void TextBlock_Initialized_1(object sender, EventArgs e)
        {
            if (i < ListBook.Count)
            {
                TextBlock Title = (TextBlock)sender;
                books ObjectService = ListBook[i];
                Title.Text = "Автор: " + ObjectService.writer;
            }
        }

        private void TextBlock_Initialized_2(object sender, EventArgs e)
        {
            if (i < ListBook.Count)
            {
                TextBlock Price = (TextBlock)sender;
                books ObjectService = ListBook[i];
                Price.Text = "Цена: " + ObjectService.price.ToString() + " руб.";
            }
        }

        private void TextBlock_Initialized_3(object sender, EventArgs e)
        {
            if (i < ListBook.Count)
            {
                TextBlock Price = (TextBlock)sender;
                books ObjectService = ListBook[i];
                Price.Text = "Наличие в магазине: " + ObjectService.quantity.ToString();
            }
        }

        private void TextBlock_Initialized_4(object sender, EventArgs e)
        {
            if (i < ListBook.Count)
            {
                TextBlock Kolichestvo = (TextBlock)sender;
                books ObjectService = ListBook[i];
                if (ObjectService.quantityStock > 5)
                {
                    Kolichestvo.Text = "Наличие на складе: много";
                }
                else
                {
                    Kolichestvo.Text = "Наличие на складе: мало";
                }
            }
        }


        private void Button_Initialized(object sender, EventArgs e)
        {
            Button Vibor = (Button)sender;
            if (Vibor != null)
            {
                Vibor.Uid = Convert.ToString(i);
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            books ServiseObject = ListBook[i];

            int n = 0;
            n = n + 1;
            kolvo.Text = n.ToString();
        }
    }
}
