@using CarCareTracker.Helper
@inject IConfigHelper config
@{
    var enableCsvImports = config.GetUserConfig(User).EnableCsvImports;
    var hideZero = config.GetUserConfig(User).HideZero;
    var backLogItems = Model.Where(x => x.Progress == PlanProgress.Backlog).OrderBy(x=>x.Priority);
    var inProgressItems = Model.Where(x => x.Progress == PlanProgress.InProgress).OrderBy(x => x.Priority);
    var testingItems = Model.Where(x => x.Progress == PlanProgress.Testing).OrderBy(x => x.Priority);
    var doneItems = Model.Where(x => x.Progress == PlanProgress.Done).OrderBy(x => x.Priority);
}
@model List<PlanRecord>
<div class="row">
    <div class="d-flex justify-content-between">
        <div class="d-flex align-items-center flex-wrap">
            <span class="ms-2 badge bg-success">@($"# of Plan Records: {Model.Count()}")</span>
        </div>
        <div>
            @if (enableCsvImports)
            {
                <div class="btn-group">
                    <button onclick="showAddPlanRecordModal()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>Add Plan Record</button>
                    <button type="button" class="btn btn-md btn-primary btn-md mt-1 mb-1 dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
                        <span class="visually-hidden">Toggle Dropdown</span>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="#" onclick="showBulkImportModal('PlanRecord')">Import via CSV</a></li>
                        <li><a class="dropdown-item" href="#" onclick="exportVehicleData('PlanRecord')">Export to CSV</a></li>
                    </ul>
                </div>
            }
            else
            {
                <button onclick="showAddPlanRecordModal()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>Add Plan Record</button>
            }
        </div>
    </div>
</div>
<div class="row vehicleDetailTabContainer fixed">
    <div class="col-12">
        <div class="row mt-2 showOnPrint">
            <div class="d-flex">
                <img src="/defaults/lubelogger_logo.png" />
            </div>
        </div>
        <div class="row swimlane">
            <div class="col-3 d-flex flex-column swimlane mid" ondragover="dragOver(event)" ondrop="dropBox(event, 'Backlog')">
                <div class="row">
                    <div class="col-12 d-flex justify-content-center" style="height:5vh;">
                        <span class="display-7">Planned</span>
                    </div>
                </div>
                @foreach (PlanRecord planRecord in backLogItems)
                {
                    @await Html.PartialAsync("_PlanRecordItem", planRecord)
                }
            </div>
            <div class="col-3 d-flex flex-column swimlane mid" ondragover="dragOver(event)" ondrop="dropBox(event, 'InProgress')">
                <div class="row">
                    <div class="col-12 d-flex justify-content-center" style="height:5vh;">
                        <span class="display-7">Doing</span>
                    </div>
                </div>
                @foreach (PlanRecord planRecord in inProgressItems)
                {
                    @await Html.PartialAsync("_PlanRecordItem", planRecord)
                }
            </div>
            <div class="col-3 d-flex flex-column swimlane" ondragover="dragOver(event)" ondrop="dropBox(event, 'Testing')">
                <div class="row">
                    <div class="col-12 d-flex justify-content-center" style="height:5vh;">
                        <span class="display-7">Testing</span>
                    </div>
                </div>
                @foreach (PlanRecord planRecord in testingItems)
                {
                    @await Html.PartialAsync("_PlanRecordItem", planRecord)
                }
            </div>
            <div class="col-3 d-flex flex-column swimlane end" ondragover="dragOver(event)" ondrop="dropBox(event, 'Done')">
                <div class="row">
                    <div class="col-12 d-flex justify-content-center" style="height:5vh;">
                        <span class="display-7">Done</span>
                    </div>
                </div>
                @foreach (PlanRecord planRecord in doneItems)
                {
                    @await Html.PartialAsync("_PlanRecordItem", planRecord)
                }
            </div>
        </div>
    </div>
</div>


<div class="modal fade" data-bs-focus="false" id="planRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" id="planRecordModalContent">
        </div>
    </div>
</div>