using FasdDesktopUi.Basics;
using FasdDesktopUi.Basics.Models;
using FasdDesktopUi.Basics.UserControls;
using FasdDesktopUi.Pages.DetailsPage.Models;
using FasdDesktopUi.Pages.DetailsPage.UserControls;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace FasdDesktopUi.Pages.DetailsPage.Commands
{
    public class InformationCommand : BaseCommand
    {
        public override bool CanExecute(object parameter = null)
        {
            return parameter is ValueTuple<object, List<List<string>>, string>;
        }

        public override void Execute(object parameter)
        {
            if (!(parameter is ValueTuple<object, List<object>, string> tempTuple))
                return;

            (object Title, List<object> DetailedData, string DayIndex) commandProperties = tempTuple;

            var detailsPage = cSupportCaseDataProvider.detailsPage;
            if (detailsPage == null)
                return;

            if (detailsPage.FindName("DataCanvasUserControl") is DataCanvas dataCanvas)
            {
                var detailedData = new cDetailedDataModel();

                if (int.TryParse(commandProperties.DayIndex, out int dayIndex))
                    detailedData.Heading = commandProperties.Title is string ? $"Details - {commandProperties.Title} vom {DateTime.Today.AddDays(-dayIndex):d}" : "Detailed Data";
                else
                    detailedData.Heading = commandProperties.Title is string ? $"Details - {commandProperties.Title}" : "Detailed Data";

                detailedData.FullDetailedData = commandProperties.DetailedData;

                dataCanvas.DataCanvasData = new cDataCanvasDataModel() { DetailedData = detailedData };

                dataCanvas.DetailedDataUc.Visibility = Visibility.Visible;
                dataCanvas.QuickActionStatusUc.Visibility = Visibility.Collapsed;
                detailsPage.DataHistoryCollectionUserControl.ToggleHorizontalCollapseHistory(false);
            }
        }
    }
}
