@using Postall.Domain.Dtos
@model List<ChannelResponse>
@{
    ViewData["Title"] = "Meus Canais";
}

<div class="container mt-4">
    <div class="row mb-4">
        <div class="col-md-8">
            <h2>Meus Canais</h2>
            <p class="text-muted">Gerencie seus canais do YouTube</p>
        </div>
        <div class="col-md-4 text-right">
            <a href="@Url.Action("Add", "Channels")" class="btn btn-primary">
                <i class="bi bi-plus-circle"></i> Adicionar Canal
            </a>
        </div>
    </div>

    @if (TempData["Message"] != null)
    {
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            @TempData["Message"]
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
    }

    @if (TempData["Error"] != null)
    {
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            @TempData["Error"]
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
    }

    <div class="row">
        @if (Model != null && Model.Any())
        {
            foreach (var channel in Model)
            {
                <div class="col-md-6 mb-4">
                    <div class="card h-100">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-4">
                                    <img src="@channel.ThumbnailUrl" alt="@channel.Title" class="img-fluid rounded">
                                </div>
                                <div class="col-md-8">
                                    <h5 class="card-title">@channel.Title</h5>
                                    <p class="card-text text-muted small">
                                        @(channel.Description?.Length > 100 ? channel.Description.Substring(0, 100) + "..." : channel.Description)
                                    </p>
                                    <div class="d-flex justify-content-between">
                                        <small class="text-muted">
                                            <i class="bi bi-people"></i> @channel.SubscriberCount.ToString("N0") inscritos
                                        </small>
                                        <small class="text-muted">
                                            <i class="bi bi-collection-play"></i> @channel.VideoCount.ToString("N0") vídeos
                                        </small>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="card-footer bg-white d-flex justify-content-between">
                            <a href="@channel.ChannelUrl" target="_blank" class="btn btn-sm btn-outline-primary">
                                <i class="bi bi-youtube"></i> Ver no YouTube
                            </a>
                            <form asp-action="Remove" asp-controller="Channels" method="post"
                                  onsubmit="return confirm('Tem certeza que deseja remover este canal da sua lista?');">
                                <input type="hidden" name="id" value="@channel.Id" />
                                <button type="submit" class="btn btn-sm btn-outline-danger">
                                    <i class="bi bi-trash"></i> Remover
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            }
        }
        else
        {
            <div class="col-12">
                <div class="alert alert-info">
                    <i class="bi bi-info-circle"></i> Você ainda não possui canais. Clique em "Adicionar Canal" para começar.
                </div>
            </div>
        }
    </div>
</div>