@page "/domains"

@using Moonlight.App.Repositories.Domains
@using Moonlight.App.Database.Entities
@using Microsoft.EntityFrameworkCore

@inject DomainRepository DomainRepository

<LazyLoader Load="Load">
    @if (Domains.Any())
    {
        foreach (var domain in Domains)
        {
            <div class="row px-5 mb-5">
                <a href="/domain/@(domain.Id)" class="card card-body">
                    <div class="row">
                        <div class="col">
                            <div class="d-flex align-items-center">
                                <div class="symbol symbol-50px me-3">
                                    <i class="bx bx-md bx-purchase-tag"></i>
                                </div>
                                <div class="d-flex justify-content-start flex-column">
                                    <span class="text-gray-800 text-hover-primary mb-1 fs-5">
                                        @(domain.Name)
                                    </span>
                                    <span class="text-gray-400 fw-semibold d-block fs-6">
                                        <span class="text-gray-700">@(domain.SharedDomain.Name)</span>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
        }
    }
    else
    {
        <div class="alert bg-info d-flex flex-column flex-sm-row w-100 p-5">
            <div class="d-flex flex-column pe-0 pe-sm-10">
                <h4 class="fw-semibold">
                    <TL>You have no domains</TL>
                </h4>
                <span>
                    <TL>We were not able to find any domains associated with your account</TL>
                </span>
            </div>
        </div>
    }
</LazyLoader>

@code {

    [CascadingParameter]
    public User? User { get; set; }

    private Domain[] Domains { get; set; }

    private Task Load(LazyLoader loader)
    {
        Domains = DomainRepository
            .Get()
            .Include(x => x.SharedDomain)
            .Include(x => x.Owner)
            .Where(x => x.Owner == User)
            .ToArray();

        return Task.CompletedTask;
    }

}