@using Microsoft.AspNetCore.Components
@using RpgRoller.Components.Pages.HomeControls

<CampaignManagementPanel
    Campaigns="Workspace.State.Campaigns"
    SelectedCampaignId="Workspace.State.SelectedCampaignId"
    SelectedCampaign="Workspace.State.SelectedCampaign"
    Rulesets="Workspace.State.Rulesets"
    IsMutating="Workspace.State.IsMutating"
    OwnerLabel="Workspace.State.OwnerLabel"
    CanEditCharacter="Workspace.Campaigns.CanEditCharacter"
    CanDeleteCharacter="Workspace.Campaigns.CanDeleteCharacter"
    CanDeleteCampaign="Workspace.State.CanDeleteSelectedCampaign"
    CampaignSelectionChanged="OnCampaignSelectionChangedAsync"
    CampaignCreated="Workspace.Campaigns.OnCampaignCreatedAsync"
    DeleteCampaignRequested="Workspace.Campaigns.DeleteSelectedCampaignAsync"
    CreateCharacterRequested="Workspace.Campaigns.OpenCreateCharacterModal"
    EditCharacterRequested="Workspace.Campaigns.OpenEditCharacterModal"
    DeleteCharacterRequested="Workspace.Campaigns.DeleteCharacterAsync"/>

<CharacterManagementModals Workspace="Workspace"/>

@code {
    [Parameter, EditorRequired] public WorkspacePageContext Workspace { get; set; } = null!;

    private async Task OnCampaignSelectionChangedAsync(ChangeEventArgs args)
    {
        await Workspace.Campaigns.OnCampaignSelectionChangedAsync(args);
        await Workspace.RequestRefreshAsync();
    }
}
