using C4IT.Logging;

using FasdDesktopUi.Basics.Models;
using FasdDesktopUi.Basics.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

using static C4IT.Logging.cLogManager;

namespace FasdDesktopUi.Basics.UiActions
{
    public class cShowRecommendationAction : cUiActionBase
    {
        public string Title { get; set; }
        public string Recommendation { get; set; }

        public cShowRecommendationAction(string Title, string Recommendation)
        {
            this.Title = Title;
            this.Recommendation = Recommendation;
        }

        public async override Task<bool> RunUiActionAsync(object sender, UIElement UiLocation, bool isDetailedLayout, cSupportCaseDataProvider dataProvider)
        {

            try
            {
                if (!(UiLocation is Decorator decorator))
                    return false;

                cRecommendationDataModel recommendationDataModel = Recommendation != null ? new cRecommendationDataModel() { Category = Title, Recommendation = Recommendation } : null;

                if (decorator.Child is DataCanvas existingDataCanvas)
                {
                    var tempDataCanvasData = new cDataCanvasDataModel() { QuickActionStatusMonitorData = null, DetailedData = null, RecommendationData = recommendationDataModel };
                    existingDataCanvas.DataCanvasData = tempDataCanvasData;
                    existingDataCanvas.IsDetailedLayout = isDetailedLayout;
                    existingDataCanvas.Visibility = Visibility.Visible;
                }
                else
                {
                    DataCanvas dataCanvas = new DataCanvas() { DataCanvasData = new cDataCanvasDataModel() { DetailedData = null, RecommendationData = recommendationDataModel }, IsDetailedLayout = isDetailedLayout };
                    decorator.Child = dataCanvas;
                }

                decorator.Visibility = Visibility.Visible;

                return true;
            }
            catch (Exception E)
            {
                LogException(E);
            }

            await Task.CompletedTask;

            return false;
        }
    }
}
