using Avalonia.Controls;
using AvaloniaApplicationTest.Models;
using AvaloniaApplicationTest.Views;
using ReactiveUI;
using System.Linq;
using System.Net;

namespace AvaloniaApplicationTest.ViewModels
{
    public class MainWindowViewModel : ViewModelBase
    {
        public static UpKrupinaContext myConnection = new UpKrupinaContext();

        UserControl us = new TourPage();

        public UserControl US
        {
            get => us;
            set => this.RaiseAndSetIfChanged(ref us, value);
        }


        public ShowTourPageViewModel PageTours { get => pageTours; set => pageTours = value; }
        ShowTourPageViewModel pageTours = new ShowTourPageViewModel();

        public ShowHotelsPageViewModel PageHotels { get => pageHotels; set => pageHotels = value; }
        ShowHotelsPageViewModel pageHotels = new ShowHotelsPageViewModel();

        public AddPageViewModel PageAdd { get => pageAdd; set => pageAdd = value; }
        AddPageViewModel pageAdd = new AddPageViewModel();

        public void ToHotels()
        {
            US = new ShowHotelsPage();
        }

        public void ToTours()
        {
            US = new TourPage();
        }

        public void ToAdd()
        {
            PageAdd = new AddPageViewModel();
            US = new AddPage();
        }
        public void ToChange(int ID)
        {
            PageAdd = new AddPageViewModel(ID);
            US = new AddPage();
        }

        public void DeleteHotel(int ID)
        {
            Hotel hotel = myConnection.Hotels.FirstOrDefault(x=> x.Id == ID);
            if (hotel != null)
            {
                myConnection.Hotels.Remove(hotel);
                myConnection.SaveChanges();
            }
            US = new ShowHotelsPage();
        }
    }
}