@using Microsoft.EntityFrameworkCore
@attribute [Authorize]
@page "/events/printout"
@inject IConfiguration Configuration
@inject  AppDbContext Context

<PageTitle>TSA Events @Configuration["ChapterSettings:CompetitionYear"]</PageTitle>

<MudText Typo="Typo.h3">TSA Events @Configuration["ChapterSettings:CompetitionYear"]</MudText>
<MudText Typo="Typo.h5" Class="mb-4">Yearly theme: Unity Through Community</MudText>

@if (_events == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <MudContainer>
        @foreach (var evt in _events)
        {
            <MudContainer Class="mt-3 mb-1 nobrk">
                <MudGrid>
                    <MudItem xs="4">
                        <MudStack>
                            <MudItem>
                                <MudText Class="d-flex py-1" Typo="Typo.h5">@evt.Name</MudText>
                            </MudItem>
                            @if (evt.RegionalEvent)
                            {
                                <MudItem>
                                    <MudText Class="d-flex" Typo="Typo.caption"><i>Regional Event</i></MudText>
                                </MudItem>
                            }
                        </MudStack>
                    </MudItem>
                    <MudItem xs="2">

                        <MudText>
                            @if (evt.EventFormat is EventFormat.Team)
                            {
                                <strong>@evt.EventFormat</strong>
                                <br/>
                                <p>Size: <strong>@evt.TeamSize</strong></p>
                            }
                            else
                            {
                                <strong>@evt.EventFormat</strong>
                            }
                        </MudText>

                    </MudItem>
                    <MudItem xs="3">
                        Eligibility: @evt.Eligibility
                    </MudItem>
                    <MudItem xs="1">
                        <strong> Effort</strong>: @evt.LevelOfEffort
                    </MudItem>
                    <MudItem xs="2">
                        <strong>Activity</strong>: @evt.SemifinalistActivity
                    </MudItem>
                
                    <MudItem xs="12">
                        <MudText Class="d-flex py-1" Style="white-space:pre-wrap;">@evt.Description</MudText>
                    </MudItem>
                    @if (!string.IsNullOrEmpty(evt.Theme))
                    {
                        <MudItem xs="3">
                            <MudText Class="d-flex py-1">
                                <i>Theme for 2025-26:</i>
                            </MudText>
                        </MudItem>
                        <MudItem xs="8">
                            <MudText Class="d-flex py-1" Style="white-space:pre-wrap;">@evt.Theme</MudText>
                        </MudItem>
                    }

                    @if (!string.IsNullOrEmpty(evt.Documentation))
                    {
                        <MudItem xs="3">
                            <MudText Class="d-flex py-1">
                                <i>Materials:</i>
                            </MudText>
                        </MudItem>
                        <MudItem xs="8">
                            <MudText Class="d-flex py-1" Style="white-space:pre-wrap;">@evt.Documentation</MudText>
                        </MudItem>
                    }
                
                </MudGrid>
            </MudContainer>
            <MudDivider />
        }
    </MudContainer>

    <MudContainer>
        @foreach (var evt in _events)
        {
            <MudContainer Class="mt-3 mb-1 nobrk">
                <MudGrid>
                    <MudItem xs="4">
                        <MudStack>
                            <MudItem>
                                <MudText Class="d-flex py-1" Typo="Typo.h5">@evt.Name</MudText>
                            </MudItem>
                            @if (evt.RegionalEvent)
                            {
                                <MudItem>
                                    <MudText Class="d-flex" Typo="Typo.caption"><i>Regional Event</i></MudText>
                                </MudItem>
                            }
                        </MudStack>
                    </MudItem>
                    <MudItem xs="2">

                        <MudText>
                            @if (evt.EventFormat is EventFormat.Team)
                            {
                                <strong>@evt.EventFormat</strong>
                                <br />
                                <p>Size: <strong>@evt.TeamSize</strong></p>
                            }
                            else
                            {
                                <strong>@evt.EventFormat</strong>
                            }
                        </MudText>

                    </MudItem>
                    <MudItem xs="3">
                        Eligibility: @evt.Eligibility
                    </MudItem>
                    <MudItem xs="1">
                        <strong> Effort</strong>: @evt.LevelOfEffort
                    </MudItem>
                    <MudItem xs="2">
                        <strong>Activity</strong>: @evt.SemifinalistActivity
                    </MudItem>

                    <MudItem xs="12">
                        <MudText Class="d-flex py-1" Style="white-space:pre-wrap;">@evt.Description</MudText>
                    </MudItem>
                    @if (!string.IsNullOrEmpty(evt.Theme))
                    {
                        <MudItem xs="3">
                            <MudText Class="d-flex py-1">
                                <i>Theme for 2025-26:</i>
                            </MudText>
                        </MudItem>
                        <MudItem xs="8">
                            <MudText Class="d-flex py-1" Style="white-space:pre-wrap;">@evt.Theme</MudText>
                        </MudItem>
                    }

                    @if (!string.IsNullOrEmpty(evt.Documentation))
                    {
                        <MudItem xs="3">
                            <MudText Class="d-flex py-1">
                                <i>Materials:</i>
                            </MudText>
                        </MudItem>
                        <MudItem xs="8">
                            <MudText Class="d-flex py-1" Style="white-space:pre-wrap;">@evt.Documentation</MudText>
                        </MudItem>
                    }

                </MudGrid>
            </MudContainer>
            <MudDivider />
        }
    </MudContainer>
}
@code {
    private EventDefinition[]? _events;

    protected override async Task OnInitializedAsync()
    {
        _events = await Context.Events.OrderBy(e => e.Name).ToArrayAsync();
    }
}
