// <auto-generated/>
#pragma warning disable 1591
#pragma warning disable 0414
#pragma warning disable 0649
#pragma warning disable 0169

namespace RichTextEditor_Test.Shared
{
    #line hidden
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Components;
#nullable restore
#line 1 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using System.Net.Http;

#line default
#line hidden
#nullable disable
#nullable restore
#line 2 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using Microsoft.AspNetCore.Authorization;

#line default
#line hidden
#nullable disable
#nullable restore
#line 3 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using Microsoft.AspNetCore.Components.Authorization;

#line default
#line hidden
#nullable disable
#nullable restore
#line 4 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using Microsoft.AspNetCore.Components.Forms;

#line default
#line hidden
#nullable disable
#nullable restore
#line 5 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using Microsoft.AspNetCore.Components.Routing;

#line default
#line hidden
#nullable disable
#nullable restore
#line 6 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using Microsoft.AspNetCore.Components.Web;

#line default
#line hidden
#nullable disable
#nullable restore
#line 7 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using Microsoft.JSInterop;

#line default
#line hidden
#nullable disable
#nullable restore
#line 8 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using RichTextEditor_Test;

#line default
#line hidden
#nullable disable
#nullable restore
#line 9 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using RichTextEditor_Test.Shared;

#line default
#line hidden
#nullable disable
#nullable restore
#line 10 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using Syncfusion.Blazor;

#line default
#line hidden
#nullable disable
#nullable restore
#line 1 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
using Rencore.Cloud.Core.Services.DataModel;

#line default
#line hidden
#nullable disable
#nullable restore
#line 2 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
using Rencore.Cloud.Web.Portal.Helpers;

#line default
#line hidden
#nullable disable
#nullable restore
#line 3 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
using Rencore.Cloud.Core.Enums;

#line default
#line hidden
#nullable disable
#nullable restore
#line 4 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
using Rencore.Cloud.Core.CommonHelpers.Date;

#line default
#line hidden
#nullable disable
#nullable restore
#line 5 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
using Syncfusion.Blazor.Charts;

#line default
#line hidden
#nullable disable
#nullable restore
#line 6 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
using Rencore.Cloud.Core.CommonHelpers.Number;

#line default
#line hidden
#nullable disable
#nullable restore
#line 7 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
using Rencore.Cloud.Core.StreamsConfiguration;

#line default
#line hidden
#nullable disable
#nullable restore
#line 8 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
using Rencore.Containers.Core.Services.Check;

#line default
#line hidden
#nullable disable
    public partial class CustomSparklineComponent : Rencore.Cloud.Web.Portal.BaseClasses.BaseEnvironmentComponent
    {
        #pragma warning disable 1998
        protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
        {
        }
        #pragma warning restore 1998
#nullable restore
#line 48 "C:\Users\an\Downloads\RichTextEditor_Test\Shared\CustomSparklineComponent.razor"
       

    [Parameter]
    public string DataUpId { get; set; } = "EmptyDataUp";

    [Parameter]
    public DashboardReportDateFilter DateFilter { get; set; }

    [Parameter]
    public string CheckId { get; set; }

    [Parameter]
    public string Color { get; set; } = "#667D8B";

    private List<ReportStatsDataPoint> dataPoints = null;

    protected override async Task OnParametersSetAsync()
    {
        await base.OnParametersSetAsync();

        await UpdateUI();
    }

    private DateTime lastStartDate = DateTime.MinValue;
    private DateTime lastEndDate = DateTime.MinValue;
    private string lastCheckId = "";

    private async Task UpdateUI()
    {
        if (MainService == null)
        {
            return; // component not initialized
        }

        DateFilterHelper.GetDates(this.DateFilter, out DateTime startDate, out DateTime endDate, DateRangeType.Last30Days);

        if (CheckId != lastCheckId || startDate != lastStartDate || endDate != lastEndDate)
        {
            lastStartDate = startDate;
            lastEndDate = endDate;
            lastCheckId = CheckId;

            var preparedDataPoints = new List<ReportStatsDataPoint>();
            this.dataPoints = null;

            var checkService = new ChecksService(this.ServiceProvider);
            var stats = await checkService.GetCheckStats(this.EnvironmentId, this.CheckId, startDate);
            if (stats.Any())
            {
                var reportDataPoints = stats.OrderBy(s => s.JobDate).Where(s => s.JobDate >= startDate && s.JobDate <= endDate);
                if (reportDataPoints != null)
                {
                    preparedDataPoints = reportDataPoints.Select(p => new ReportStatsDataPoint()
                    {
                        JobDate = DateHelper.FormatDateTime(p.JobDate, dateNumberFormat, dateTimeZone, true),
                        TotalCount = NumberHelper.GetFormattedNumber(p.TotalCheckItems, dateNumberFormat, returnZeroAsString: true)
                    }).ToList();
                }
            }

            if (preparedDataPoints != null && preparedDataPoints.Count == 1)
            {
                // workaround for spcarkline component
                preparedDataPoints.Add(new ReportStatsDataPoint()
                {
                    JobDate = preparedDataPoints[0].JobDate + "_",
                    TotalCount = preparedDataPoints[0].TotalCount
                });
            }

            this.dataPoints = preparedDataPoints;
        }
    }

    public class ReportStatsDataPoint
    {
        public string JobDate { get; set; }

        public string TotalCount { get; set; }
    }

#line default
#line hidden
#nullable disable
    }
}
#pragma warning restore 1591
