using Microsoft.AspNetCore.Components;
namespace AyCode.Blazor.Components.Components.CardViews;
///
/// Generic card view component that displays items in a responsive grid layout.
/// Uses DxGridLayout + DxLayoutBreakpoint for responsive column management
/// and DxPager for optional pagination.
///
/// The type of data item displayed in each card.
public partial class MgCardView : ComponentBase
{
///
/// The collection of items to display as cards.
///
[Parameter, EditorRequired]
public IReadOnlyList Data { get; set; } = [];
///
/// Template for rendering each card's content.
///
[Parameter, EditorRequired]
public RenderFragment CardTemplate { get; set; } = null!;
///
/// Fired when a card is clicked/tapped.
///
[Parameter]
public EventCallback OnCardClick { get; set; }
///
/// Number of columns on extra-small screens (below 576px). Default: 1.
///
[Parameter]
public int ColumnCountXs { get; set; } = 1;
///
/// Number of columns on small screens (576–768px). Default: 2.
///
[Parameter]
public int ColumnCountSm { get; set; } = 2;
///
/// Number of columns on medium+ screens (769px+). Default: 3.
///
[Parameter]
public int ColumnCountLg { get; set; } = 3;
///
/// Whether to show the pager below the cards. Default: false.
///
[Parameter]
public bool ShowPager { get; set; }
///
/// Number of items per page when paging is enabled. Default: 12.
///
[Parameter]
public int PageSize { get; set; } = 12;
///
/// Additional CSS class for the card view container.
///
[Parameter]
public string? CssClass { get; set; }
///
/// Additional CSS class applied to each individual card wrapper.
///
[Parameter]
public string? CardCssClass { get; set; }
///
/// Whether to show the filter panel above the cards. Default: false.
///
[Parameter]
public bool ShowFilterPanel { get; set; }
///
/// Custom content for the filter panel. Rendered above the card grid when ShowFilterPanel is true.
///
[Parameter]
public RenderFragment? FilterPanel { get; set; }
private int _activePageIndex;
private IReadOnlyList PagedItems
{
get
{
if (!ShowPager)
return Data;
return Data
.Skip(_activePageIndex * PageSize)
.Take(PageSize)
.ToList();
}
}
private async Task OnCardClickInternal(TItem item)
{
if (OnCardClick.HasDelegate)
await OnCardClick.InvokeAsync(item);
}
private void OnActivePageIndexChanged(int newPageIndex)
{
_activePageIndex = newPageIndex;
}
}