@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@{
    var userConfig = config.GetUserConfig(User);
    var enableCsvImports = userConfig.EnableCsvImports;
    var hideZero = userConfig.HideZero;
    var userLanguage = userConfig.UserLanguage;
    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">@($"{translator.Translate(userLanguage,"# 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>@translator.Translate(userLanguage,"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')">@translator.Translate(userLanguage,"Import via CSV")</a></li>
                        <li><a class="dropdown-item" href="#" onclick="exportVehicleData('PlanRecord')">@translator.Translate(userLanguage,"Export to CSV")</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="#" onclick="showPlanRecordTemplatesModal()">@translator.Translate(userLanguage, "View Templates")</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>@translator.Translate(userLanguage,"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="@config.GetLogoUrl()" class="lubelogger-logo" />
            </div>
        </div>
        <div class="row swimlane">
            <div class="col-3 d-flex flex-column swimlane" 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">@translator.Translate(userLanguage,"Planned")</span>
                    </div>
                </div>
                @foreach (PlanRecord planRecord in backLogItems)
                {
                    @await Html.PartialAsync("_PlanRecordItem", planRecord)
                }
            </div>
            <div class="col-3 d-flex flex-column swimlane" 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">@translator.Translate(userLanguage,"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">@translator.Translate(userLanguage,"Testing")</span>
                    </div>
                </div>
                @foreach (PlanRecord planRecord in testingItems)
                {
                    @await Html.PartialAsync("_PlanRecordItem", planRecord)
                }
            </div>
            <div class="col-3 d-flex flex-column swimlane" 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">@translator.Translate(userLanguage,"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" onpaste="handleModalPaste(event, 'planRecordFiles')">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" id="planRecordModalContent">
        </div>
    </div>
</div>

<div class="modal fade" data-bs-focus="false" id="planRecordTemplateModal" tabindex="-1" role="dialog" aria-hidden="true" onpaste="handleModalPaste(event, 'planRecordFiles')">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" id="planRecordTemplateModalContent">
        </div>
    </div>
</div>

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

<ul class="table-context-menu dropdown-menu" style="display:none;">
    <li><h6 class="dropdown-header context-menu-move move-header">@translator.Translate(userLanguage, "Move To")</h6></li>
    <li><a class="dropdown-item context-menu-move move-planned" href="#"><div class="d-flex justify-content-between"><span class="me-5">@translator.Translate(userLanguage, "Planned")</span><i class="bi bi-list-task"></i></div></a></li>
    <li><a class="dropdown-item context-menu-move move-doing" href="#"><div class="d-flex justify-content-between"><span class="me-5">@translator.Translate(userLanguage, "Doing")</span><i class="bi bi-tools"></i></div></a></li>
    <li><a class="dropdown-item context-menu-move move-testing" href="#"><div class="d-flex justify-content-between"><span class="me-5">@translator.Translate(userLanguage, "Testing")</span><i class="bi bi-eyeglasses"></i></div></a></li>
    <li><a class="dropdown-item context-menu-move move-done" href="#"><div class="d-flex justify-content-between"><span class="me-5">@translator.Translate(userLanguage, "Done")</span><i class="bi bi-check2-all"></i></div></a></li>
    <li><hr class="context-menu-move move-header dropdown-divider"></li>
    <li><a class="dropdown-item context-menu-move move-header context-menu-duplicate" href="#"><div class="d-flex justify-content-between"><span class="me-5">@translator.Translate(userLanguage, "Duplicate")</span><i class="bi bi-copy"></i></div></a></li>
    <li><a class="dropdown-item context-menu-move move-header context-menu-duplicate-vehicle" href="#"><div class="d-flex justify-content-between"><span class="me-5">@translator.Translate(userLanguage, "Duplicate To Vehicle")</span><i class="bi bi-copy"></i></div></a></li>
    <li><hr class="context-menu-move move-header dropdown-divider"></li>
    <li><a class="dropdown-item context-menu-move move-header context-menu-print-tab-sticker" href="#"><div class="d-flex justify-content-between"><span class="me-5">@translator.Translate(userLanguage, "Print")</span><i class="bi bi-printer"></i></div></a></li>
    <li><hr class="context-menu-move move-header dropdown-divider"></li>
    <li><a class="dropdown-item context-menu-move move-header text-danger context-menu-delete" href="#"><div class="d-flex justify-content-between"><span class="me-5">@translator.Translate(userLanguage, "Delete")</span><i class="bi bi-trash"></i></div></a></li>
</ul>