@{
    ViewData["Title"] = "Equipment & Maintenance";
}

<div class="d-flex align-items-center gap-2 mb-3">
    <a asp-controller="Help" asp-action="Index" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i></a>
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb mb-0">
            <li class="breadcrumb-item"><a asp-controller="Help" asp-action="Index">Help</a></li>
            <li class="breadcrumb-item active">Equipment &amp; Maintenance</li>
        </ol>
    </nav>
</div>

<div class="row g-4">
    <div class="col-lg-9">

        <section id="overview" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-info-circle text-primary me-2"></i>Overview
            </h2>
            <p>
                The Equipment module lets you keep a full register of every piece of machinery in your shop &mdash;
                curing ovens, sandblasters, coating booths, compressors, conveyors, and anything else you
                rely on to do the work. Each equipment record includes its current operating status and a
                complete maintenance log.
            </p>
            <p>
                Keeping this information up to date pays off in two ways. First, your team always knows
                which machines are available and which are down for service &mdash; preventing jobs from being
                scheduled on equipment that is not ready. Second, the maintenance history gives you a
                paper trail for warranty claims, insurance, and resale.
            </p>
            <p>
                Find Equipment under <strong>Equipment</strong> in the left sidebar.
            </p>
        </section>

        <section id="adding-equipment" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-plus-circle text-primary me-2"></i>Adding Equipment
            </h2>
            <p>To add a piece of equipment to the system:</p>
            <ol class="mb-3">
                <li class="mb-2">Go to <strong>Equipment</strong> and click <strong>New Equipment</strong>.</li>
                <li class="mb-2">
                    Fill in the equipment details:
                    <ul class="mt-1">
                        <li><strong>Name</strong> &mdash; a short, descriptive name (e.g., "Main Curing Oven" or "Blast Cabinet #2").</li>
                        <li><strong>Model / Serial Number</strong> &mdash; from the manufacturer's plate on the machine. Useful for warranty and service calls.</li>
                        <li><strong>Manufacturer</strong> &mdash; who made the equipment.</li>
                        <li><strong>Purchase Date</strong> &mdash; when your shop acquired it.</li>
                        <li><strong>Last Service Date</strong> &mdash; the date it was last professionally serviced or inspected.</li>
                        <li><strong>Next Service Due</strong> &mdash; when the next scheduled service is due. This triggers alerts on the Dashboard.</li>
                        <li><strong>Location</strong> &mdash; where in the shop the equipment is located (e.g., "Bay 1", "Back Room").</li>
                        <li><strong>Notes</strong> &mdash; any important operational notes, quirks, or warnings for the team.</li>
                    </ul>
                </li>
                <li class="mb-2">Set the initial <strong>Status</strong> (see below).</li>
                <li class="mb-2">Click <strong>Save Equipment</strong>.</li>
            </ol>
        </section>

        <section id="equipment-status" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-toggles text-primary me-2"></i>Equipment Status
            </h2>
            <p>
                Every piece of equipment has a status that reflects its current condition. Update the status
                whenever the equipment's situation changes &mdash; this keeps the Dashboard accurate and lets
                supervisors quickly see what is available.
            </p>

            <div class="table-responsive">
                <table class="table table-bordered align-middle">
                    <thead class="table-light">
                        <tr>
                            <th style="width:28%">Status</th>
                            <th>What it means</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><span class="badge bg-success fs-6 py-1 px-2"><i class="bi bi-check-circle me-1"></i>Operational</span></td>
                            <td>
                                The equipment is fully functional and available for use. This is the normal
                                day-to-day status for working machines.
                            </td>
                        </tr>
                        <tr>
                            <td><span class="badge bg-warning text-dark fs-6 py-1 px-2"><i class="bi bi-exclamation-triangle me-1"></i>Needs Maintenance</span></td>
                            <td>
                                The equipment is still operational but a maintenance task is overdue or a minor
                                issue has been flagged. The machine can still be used with caution, but maintenance
                                should be scheduled promptly to avoid a breakdown.
                            </td>
                        </tr>
                        <tr>
                            <td><span class="badge bg-info text-dark fs-6 py-1 px-2"><i class="bi bi-wrench me-1"></i>Under Maintenance</span></td>
                            <td>
                                The equipment is currently being serviced or repaired and is <strong>not available</strong>
                                for production. Do not schedule jobs that require this equipment until its status
                                returns to Operational.
                            </td>
                        </tr>
                        <tr>
                            <td><span class="badge bg-danger fs-6 py-1 px-2"><i class="bi bi-x-circle me-1"></i>Out of Service</span></td>
                            <td>
                                The equipment has broken down or failed and cannot be used. A maintenance record
                                should be created immediately with a priority of High or Critical.
                            </td>
                        </tr>
                        <tr>
                            <td><span class="badge bg-secondary fs-6 py-1 px-2"><i class="bi bi-archive me-1"></i>Retired</span></td>
                            <td>
                                The equipment has been decommissioned and is no longer in service. It remains in
                                the system for historical records but is excluded from active listings and the
                                Dashboard.
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <p class="mt-3">
                To update an equipment's status, open its Details page and click <strong>Edit</strong>, then
                change the Status field. You can also log a maintenance record (see below), which can update
                the status as part of the workflow.
            </p>
        </section>

        <section id="maintenance-records" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-clipboard-check text-primary me-2"></i>Maintenance Records
            </h2>
            <p>
                Every service, repair, inspection, or maintenance task performed on a piece of equipment should
                be logged as a maintenance record. Over time this builds a complete service history that is
                invaluable for troubleshooting recurring problems, planning replacements, and demonstrating
                due diligence.
            </p>
            <p>To log a maintenance record:</p>
            <ol class="mb-3">
                <li class="mb-2">Open the equipment's Details page.</li>
                <li class="mb-2">Click <strong>Add Maintenance Record</strong>.</li>
                <li class="mb-2">
                    Fill in the details:
                    <ul class="mt-1">
                        <li><strong>Task Description</strong> &mdash; what was done or needs to be done (e.g., "Replace heating element", "Annual burner service", "Belt tension check").</li>
                        <li><strong>Type</strong> &mdash; choose <strong>Scheduled</strong> for planned preventive maintenance, or <strong>Corrective</strong> for repairs to fix a problem.</li>
                        <li><strong>Scheduled Date</strong> &mdash; when the task is planned for (or when it was done).</li>
                        <li><strong>Completion Date</strong> &mdash; leave blank if the task has not been done yet.</li>
                        <li><strong>Cost</strong> &mdash; what the service cost (parts, labor, contractor fees).</li>
                        <li><strong>Priority</strong> &mdash; how urgent this task is (see below).</li>
                        <li><strong>Assigned To</strong> &mdash; the shop worker responsible for this task.</li>
                        <li><strong>Notes</strong> &mdash; parts used, observations, instructions for next time.</li>
                    </ul>
                </li>
                <li class="mb-2">Click <strong>Save</strong>.</li>
            </ol>
            <p>
                Open maintenance records (those without a completion date) appear on the Dashboard as upcoming
                tasks. When the work is done, open the record and fill in the <strong>Completion Date</strong>
                and any final notes to mark it as done.
            </p>

            <h3 class="h6 fw-semibold mt-3 mb-2">Recurring Maintenance</h3>
            <p>
                For maintenance that happens on a regular schedule (e.g., monthly filter cleaning, quarterly
                burner service), set the <strong>Recurrence</strong> field when creating the record &mdash; choose
                from Daily, Weekly, Monthly, Quarterly, or Annually. When you complete the record, the system
                automatically creates the next maintenance record at the appropriate interval. This ensures
                preventive maintenance tasks never fall through the cracks.
            </p>
        </section>

        <section id="maintenance-priority" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-flag text-primary me-2"></i>Maintenance Priority
            </h2>
            <p>
                When creating a maintenance record, set the priority to reflect how urgently the task needs
                to be completed. Priority affects how records are sorted on the Dashboard and in the
                maintenance list.
            </p>

            <div class="row g-3">
                <div class="col-md-6">
                    <div class="card border-secondary border-opacity-25 h-100">
                        <div class="card-body py-2 px-3">
                            <h6 class="mb-1"><span class="badge bg-secondary me-1">Low</span></h6>
                            <p class="small mb-0 text-muted">
                                Routine preventive tasks that can be scheduled at the next convenient opportunity.
                                Example: lubricate conveyor chain, clean filters.
                            </p>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="card border-primary border-opacity-25 h-100">
                        <div class="card-body py-2 px-3">
                            <h6 class="mb-1"><span class="badge bg-primary me-1">Normal</span></h6>
                            <p class="small mb-0 text-muted">
                                Standard scheduled maintenance that should be completed within the planned
                                service window. Example: annual burner inspection, thermocouple calibration.
                            </p>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="card border-warning border-opacity-25 h-100">
                        <div class="card-body py-2 px-3">
                            <h6 class="mb-1"><span class="badge bg-warning text-dark me-1">High</span></h6>
                            <p class="small mb-0 text-muted">
                                A developing problem that will cause a breakdown if not addressed soon. Production
                                should be monitored. Example: unusual vibration in the blaster motor, oven
                                not reaching set temperature.
                            </p>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="card border-danger border-opacity-25 h-100">
                        <div class="card-body py-2 px-3">
                            <h6 class="mb-1"><span class="badge bg-danger me-1">Critical</span></h6>
                            <p class="small mb-0 text-muted">
                                Equipment is down or unsafe to operate. All work on this machine must stop
                                immediately. Example: oven element failure, electrical fault, safety switch
                                bypassed.
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="oven-scheduler" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-calendar-week text-primary me-2"></i>Oven Scheduler
            </h2>
            <p>
                The <strong>Oven Scheduler</strong> (<a href="/OvenScheduler">/OvenScheduler</a>) lets you
                group jobs into oven batches to maximize curing oven utilization. It uses your configured
                Named Ovens (set up in <strong>Settings &rsaquo; Company Settings &rsaquo; Named Ovens</strong>)
                to show available capacity in square feet as you add jobs to a batch.
            </p>
            <p>To use the Oven Scheduler:</p>
            <ol class="mb-3">
                <li class="mb-2">Go to the Oven Scheduler from the sidebar.</li>
                <li class="mb-2">Select the oven you are loading.</li>
                <li class="mb-2">Add jobs to the batch &mdash; the remaining capacity updates as you add items.</li>
                <li class="mb-2">Progress batches through Loading → In Progress → Completed as work is done.</li>
            </ol>
            <p>
                To configure your ovens for the scheduler, see
                <a asp-controller="Help" asp-action="Settings" fragment="named-ovens">Settings &rsaquo; Named Ovens</a>.
            </p>
        </section>

        <section id="assigning-maintenance" class="mb-5">
            <h2 class="h4 fw-bold border-bottom pb-2 mb-3">
                <i class="bi bi-person-gear text-primary me-2"></i>Assigning Maintenance Tasks
            </h2>
            <p>
                Each maintenance record can be assigned to one shop worker &mdash; typically someone in the
                <strong>Maintenance</strong> role, or a <strong>Supervisor</strong> who will coordinate
                with an outside service technician.
            </p>
            <p>
                To assign a task, select the worker from the <strong>Assigned To</strong> dropdown when
                creating or editing the maintenance record. Only active workers are listed.
            </p>
            <p>
                Assigned tasks appear on the Dashboard grouped by worker, so supervisors can see their
                team's maintenance workload at a glance. When a task is completed, the assigned worker
                (or a manager) should update the completion date and any notes so the record reflects
                exactly what was done and when.
            </p>
            <div class="alert alert-permanent alert-info d-flex gap-2 mb-0" role="alert">
                <i class="bi bi-lightbulb-fill flex-shrink-0 mt-1"></i>
                <div>
                    For work done by an outside contractor (e.g., a refrigeration technician servicing
                    your blast cabinet compressor), you can either create a temporary worker record for
                    the contractor or simply note their name and company in the <strong>Notes</strong>
                    field of the maintenance record.
                </div>
            </div>
        </section>

    </div>

    <div class="col-lg-3 d-none d-lg-block">
        @{ await Html.RenderPartialAsync("_HelpNav"); }
        <div class="card border-0 shadow-sm sticky-top" style="top:80px">
            <div class="card-header bg-transparent fw-semibold small text-muted text-uppercase" style="letter-spacing:.05em; font-size:.7rem;">On this page</div>
            <div class="card-body p-0">
                <nav class="nav flex-column">
                    <a class="nav-link py-1 px-3 small text-body" href="#overview">Overview</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#adding-equipment">Adding Equipment</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#equipment-status">Equipment Status</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#maintenance-records">Maintenance Records</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#maintenance-priority">Maintenance Priority</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#oven-scheduler">Oven Scheduler</a>
                    <a class="nav-link py-1 px-3 small text-body" href="#assigning-maintenance">Assigning Maintenance</a>
                </nav>
            </div>
        </div>
    </div>
</div>
