using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

using CommonHelpers.WASM;
using AFXUI;

using BookRegistry.Client.Shared;
using BookRegistry.Client.Pages;
using BookRegistry.Client.DB;

namespace BookRegistry.Client.Components {

//**************************************************************************************************
/// <summary>
/// BookList-fragment component (in HomePage)
/// </summary>
public partial class BookList: AComponent {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//protected ElementReference?;
#nullable disable
//protected ;
#nullable restore
//==================================================================================================
[Parameter] public List<SelectBooks_Item>? Items { get; set; }
//--------------------------------------------------------------------------------------------------

[CascadingParameter] HomePage? ParentPageN { get; set; }

/// <exception cref="InvalidOperationException" />
HomePage ParentPage =>
   ParentPageN ?? throw new InvalidOperationException(
      "\"ParentPage\" cascading property is null (\"BookList\"-component)." );

//==================================================================================================

string? BookItemTRClass(SelectBooks_Item item) =>
   item.deleted ? "booklist_DeletedBookItemTR" :
      item.corrected ? "booklist_CorrectedBookItemTR" :
      null;
string BookNameTDClass(SelectBooks_Item item) =>
   item.deleted ? "booklist_DeletedBookNameTD" :
      item.corrected ? "booklist_CorrectedBookNameTD" :
      "booklist_BookNameTD";

//==================================================================================================
/*
protected override void On_Load() =>
go(()=>{
});
*/
//==================================================================================================

void BookItem_OnClick(SelectBooks_Item book) =>
GO(()=>{
   ParentPage.SwitchToBookInfoSubpage( book );
});

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // BookList
//**************************************************************************************************

} // BookRegistry.Client.Components
