@extends('layouts.admin-simple')

@section('title', 'Consumption Details')

@section('breadcrumb')
    <li class="breadcrumb-item">Warehouse</li>
    <li class="breadcrumb-item">Indirect Goods</li>
    <li class="breadcrumb-item"><a href="{{ route('warehouse.indirect-goods.consumption.index') }}">Consumption</a></li>
    <li class="breadcrumb-item active">{{ $consumption->consumption_number }}</li>
@endsection

@section('page-title')
    <div class="d-flex justify-content-between align-items-center w-100">
        <div class="page-title-left">
            <h3 class="mb-1">{{ $consumption->consumption_number }}</h3>
            <p class="text-muted mb-0" style="font-size: 13px;">Consumption record details</p>
        </div>
        <a href="{{ route('warehouse.indirect-goods.consumption.index') }}" class="btn btn-sm btn-outline-secondary">
            <i class="material-icons mr-1" style="font-size: 16px;">arrow_back</i> Back to List
        </a>
    </div>
@endsection

@section('content')
    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show">
            {{ session('success') }}
            <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
        </div>
    @endif

    <div class="row">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h6 class="card-title mb-0"><i class="material-icons mr-2">info</i>Consumption Details</h6>
                </div>
                <div class="card-body">
                    <table class="table table-borderless">
                        <tr>
                            <th width="200" class="text-muted">Consumption Number</th>
                            <td class="font-weight-bold">{{ $consumption->consumption_number }}</td>
                        </tr>
                        <tr>
                            <th class="text-muted">Date</th>
                            <td>{{ $consumption->consumption_date ? $consumption->consumption_date->format('d M Y') : '-' }}</td>
                        </tr>
                        <tr>
                            <th class="text-muted">Project</th>
                            <td>{{ $consumption->project ? $consumption->project->project_name : '-' }}</td>
                        </tr>
                        <tr>
                            <th class="text-muted">Indirect Good</th>
                            <td>
                                @if($consumption->indirectGood)
                                    <a href="{{ route('warehouse.indirect-goods.catalog.show', $consumption->indirectGood->id) }}">
                                        {{ $consumption->indirectGood->ig_code }} - {{ $consumption->indirectGood->ig_description }}
                                    </a>
                                @else
                                    -
                                @endif
                            </td>
                        </tr>
                        <tr>
                            <th class="text-muted">Invoice Number</th>
                            <td>{{ $consumption->invoice_number ?: '-' }}</td>
                        </tr>
                        <tr>
                            <th class="text-muted">Quantity Consumed</th>
                            <td class="font-weight-bold text-danger">{{ number_format($consumption->quantity_consumed, 2) }}</td>
                        </tr>
                        <tr>
                            <th class="text-muted">Consumption Type</th>
                            <td>
                                @php
                                    $typeBadges = [
                                        'consumed' => 'success',
                                        'written_off' => 'warning',
                                        'damaged' => 'danger',
                                        'expired' => 'secondary',
                                    ];
                                @endphp
                                <span class="badge badge-{{ $typeBadges[$consumption->consumption_type] ?? 'secondary' }}">
                                    {{ ucfirst(str_replace('_', ' ', $consumption->consumption_type)) }}
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <th class="text-muted">Reason</th>
                            <td>{{ $consumption->reason ?: '-' }}</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="card">
                <div class="card-header">
                    <h6 class="card-title mb-0"><i class="material-icons mr-2">person</i>Record Info</h6>
                </div>
                <div class="card-body">
                    <table class="table table-borderless table-sm">
                        <tr>
                            <th class="text-muted">Recorded By</th>
                            <td>{{ $consumption->recorder ? $consumption->recorder->name : '-' }}</td>
                        </tr>
                        <tr>
                            <th class="text-muted">Approved By</th>
                            <td>{{ $consumption->approver ? $consumption->approver->name : '-' }}</td>
                        </tr>
                        <tr>
                            <th class="text-muted">Created At</th>
                            <td>{{ $consumption->created_at->format('d M Y H:i') }}</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
