@page
@model QuantEngine.Web.Pages.Admin.Collection.IndexModel
@{
    ViewData["Title"] = "데이터 수집";
}

<div class="page-header d-print-none">
    <div class="row align-items-center">
        <div class="col">
            <h2 class="page-title">데이터 수집</h2>
        </div>
        <div class="col-auto">
            <a href="/Admin/Collection/Start" class="btn btn-primary">수집 시작</a>
        </div>
    </div>
</div>

<div class="page-body">
    @if (!string.IsNullOrEmpty(Model.Message))
    {
        <div class="alert alert-info alert-dismissible fade show" role="alert">
            @Model.Message
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    }

    <div class="row row-deck row-cards">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">수집 현황</h3>
                </div>
                <div class="table-responsive">
                    <table class="table card-table table-vcenter">
                        <thead>
                            <tr>
                                <th>실행 ID</th>
                                <th>시작 시간</th>
                                <th>종료 시간</th>
                                <th>상태</th>
                                <th>스냅샷 수</th>
                                <th>오류 수</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (Model.Runs?.Any() == true)
                            {
                                @foreach (var run in Model.Runs)
                                {
                                    <tr>
                                        <td>@run.RunId</td>
                                        <td>@run.StartedAt</td>
                                        <td>@(run.FinishedAt ?? "-")</td>
                                        <td>
                                            @if (string.Equals(run.Status, "completed", StringComparison.OrdinalIgnoreCase))
                                            {
                                                <span class="badge bg-success">완료</span>
                                            }
                                            else if (string.Equals(run.Status, "running", StringComparison.OrdinalIgnoreCase))
                                            {
                                                <span class="badge bg-warning">진행 중</span>
                                            }
                                            else if (string.Equals(run.Status, "failed", StringComparison.OrdinalIgnoreCase))
                                            {
                                                <span class="badge bg-danger">실패</span>
                                            }
                                            else
                                            {
                                                <span class="badge bg-secondary">@run.Status</span>
                                            }
                                        </td>
                                        <td>@(run.TotalSnapshots?.ToString() ?? "-")</td>
                                        <td>@(run.TotalErrors?.ToString() ?? "-")</td>
                                    </tr>
                                }
                            }
                            else
                            {
                                <tr>
                                    <td colspan="5" class="text-center text-muted">데이터가 없습니다</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
