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

namespace NoTrackedObject_Test.Pages
{
    #line hidden
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
#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 NoTrackedObject_Test;

#line default
#line hidden
#nullable disable
#nullable restore
#line 9 "C:\Users\an\Downloads\RichTextEditor_Test\_Imports.razor"
using NoTrackedObject_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\Pages\ButtonContextMenu.razor"
using Syncfusion.Blazor.SplitButtons;

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

#line default
#line hidden
#nullable disable
#nullable restore
#line 4 "C:\Users\an\Downloads\RichTextEditor_Test\Pages\ButtonContextMenu.razor"
using NoTrackedObject_Test.Data;

#line default
#line hidden
#nullable disable
    public partial class ButtonContextMenu : Microsoft.AspNetCore.Components.ComponentBase, IDisposable
    {
        #pragma warning disable 1998
        protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
        {
        }
        #pragma warning restore 1998
#nullable restore
#line 35 "C:\Users\an\Downloads\RichTextEditor_Test\Pages\ButtonContextMenu.razor"
       
    private IEnumerable<MenuItem> items;
    private SfDropDownButton dropDownButton;
    private string itemsSerialized = "";

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

    [Parameter]
    public string CustomContent { get; set; } = "...";

    [Parameter]
    public EventCallback<MouseEventArgs> OnClick { get; set; }

    [Parameter]
    public bool Primary { get; set; }

    [Parameter]
    public IEnumerable<MenuItem> Items
    {
        get
        {
            return items;
        }

        set
        {
            items = value;

            ReloadItems();
        }
    }

    [Parameter]
    public RenderFragment ChildContent { get; set; }

    [Parameter]
    public EventCallback<bool> OnOpenContextMenu { get; set; }

    [Parameter]
    public object Context { get; set; }

    private List<DropDownMenuItem> DropDownMenuItems;
    [Inject]
    private NavigationManager Navigation { get; set; }

    protected override void OnInitialized()
    {
        ReloadItems();
    }

    private void ReloadItems()
    {
        if (this.Items != null)
        {
            var newitemsSerialized = Newtonsoft.Json.JsonConvert.SerializeObject(this.Items);
            if (newitemsSerialized == this.itemsSerialized)
            {
                return;
            }
            else
            {
                this.itemsSerialized = newitemsSerialized;

                this.DropDownMenuItems = Items.Where(x => !x.Disabled && !x.Hidden).Select(x => new DropDownMenuItem()
                {
                    Disabled = x.Disabled,
                    Text = x.Text,
                    Separator = x.Separator,
                    Id = x.Id
                }).ToList();
            }
        }
        else
        {
            if (this.itemsSerialized != null)
            {
                this.itemsSerialized = null;
            }
        }
    }

    private async Task OnMenuOpen()
    {
        if (OnOpenContextMenu.HasDelegate)
        {
            await OnOpenContextMenu.InvokeAsync(true);
        }

        ReloadItems();
    }

    private async Task DropSelect(MenuEventArgs args)
    {
        MenuItem rencoreMenuItem = Items.FirstOrDefault(x => x != null && !string.IsNullOrEmpty(x.Id) && x.Id.Equals(args.Item.Id, StringComparison.InvariantCultureIgnoreCase));

        if (rencoreMenuItem != null)
        {
            if (rencoreMenuItem != null && !string.IsNullOrEmpty(rencoreMenuItem.Url))
            {
                Navigation.NavigateTo(rencoreMenuItem.Url);
            }
        }
    }

    public void Dispose()
    {
        try
        {
            if (dropDownButton != null)
            {
                dropDownButton.Dispose();
            }
        }
        catch (ObjectDisposedException ex)
        {
            // ignore
        }
    }

#line default
#line hidden
#nullable disable
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private IJSRuntime JSRuntime { get; set; }
    }
}
#pragma warning restore 1591
