@using salesbook.Shared.Core.Dto
@using salesbook.Shared.Core.Interface
@using salesbook.Shared.Core.Interface.IntegryApi
@inject IIntegryApiService IntegryApiService
@inject IAttachedService AttachedService

<div @onclick="OpenAttached" class="activity-card">
    <div class="activity-left-section">
        <div class="activity-body-section">
            <div class="title-section">
                <MudText Class="activity-title" Typo="Typo.body1" HtmlTag="h3">
                    @(Attached.Description.IsNullOrEmpty() ? Attached.FileName : Attached.Description)
                </MudText>
                <div class="activity-hours-section">
                    <span class="activity-hours">@($"{Attached.DateAttached:g}")</span>
                </div>
            </div>
        </div>
    </div>

    <div class="activity-info-section">
        @if (Attached.IsActivity)
        {
            <MudChip T="string" Color="Color.Primary" Variant="Variant.Outlined" Icon="@IconConstants.Chip.Tag" Size="Size.Small">
                @Attached.RefAttached
            </MudChip>
        }
        else
        {
            <MudChip T="string" Color="Color.Warning" Variant="Variant.Outlined" Icon="@IconConstants.Chip.FileTextLine" Size="Size.Small">
                @Attached.RefAttached
            </MudChip>
        }
    </div>
</div>

@code {
    [Parameter] public CRMAttachedResponseDTO Attached { get; set; } = new();

    private async Task OpenAttached()
    {
        var bytes = await IntegryApiService.DownloadFileFromRefUuid(Attached.RefUuid, Attached.FileName);
        await AttachedService.OpenFile(bytes, Attached.FileName);
    }
}