@extends('layouts/base_view')
@section('title')
{!! $variables['header_routes'] !!}
@endsection
@section('content')
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <div class="row align-items-center">
                            <div class="col">
                                <h3 class="card-title mb-0">{{ $variables['judul'] }}</h3>
                            </div>
                            <div class="col-auto">
                                <a href="{{ route('periods.edit', $data->id) }}" class="btn btn-sm btn-warning button-cek-permission" data-permission="periods.edit">
                                    <i class="fas fa-edit"></i> Ubah
                                </a>
                                <a href="{{ route('periods.index') }}" class="btn btn-sm btn-warning ml-2">
                                    <i class="fas fa-arrow-left"></i> Kembali ke Daftar
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <!-- Single Card with All Information -->
                            <div class="col-12">
                                <div class="card card-outline card-warning">
                                    <div class="card-body">
                                        <div class="row">
                                            <!-- Code -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Kode</label>
                                                    <div class="mt-1">
                                                        <span class="badge badge-info">{{ $data->code }}</span>
                                                    </div>
                                                </div>
                                            </div>

                                            <!-- Name -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Nama</label>
                                                    <div class="mt-1">{{ $data->name }}</div>
                                                </div>
                                            </div>

                                            <!-- Status -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Status</label>
                                                    <div class="mt-1">
                                                        <span class="badge {{ $data->status_badge }}">{{ $data->status }}</span>
                                                    </div>
                                                </div>
                                            </div>

                                            <!-- Created By -->
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Dibuat Oleh</label>
                                                    <div class="mt-1">
                                                        <small class="text-muted">
                                                            {{ $data->creator->fullname ?? 'System' }}<br>
                                                            {{ $data->created_at->format('d M Y, H:i') }}
                                                        </small>
                                                    </div>
                                                </div>
                                            </div>

                                            <!-- Updated By -->
                                            @if($data->modificator)
                                            <div class="col-lg-3 col-md-4 col-sm-6 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Diubah Oleh</label>
                                                    <div class="mt-1">
                                                        <small class="text-muted">
                                                            {{ $data->modificator->fullname }}<br>
                                                            {{ $data->updated_at->format('d M Y, H:i') }}
                                                        </small>
                                                    </div>
                                                </div>
                                            </div>
                                            @endif

                                            <!-- Description (Full Width) -->
                                            @if($data->description)
                                            <div class="col-12 mb-3">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Deskripsi</label>
                                                    <div class="mt-1">{{ $data->description }}</div>
                                                </div>
                                            </div>
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        @if($data->rawMaterials()->where('delete_flag', false)->count() > 0)
                        <div class="row mt-3">
                            <div class="col-12">
                                <div class="card card-outline card-secondary">
                                    <div class="card-header">
                                        <h5 class="card-title mb-0">Item yang Menggunakan Periode Ini</h5>
                                    </div>
                                    <div class="card-body">
                                        <div class="table-responsive">
                                            <table class="table table-sm table-bordered">
                                                <thead class="bg-light">
                                                    <tr>
                                                        <th>Kode</th>
                                                        <th>Nama</th>
                                                        <th>Kategori</th>
                                                        <th>UOM</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    @foreach($data->rawMaterials()->where('delete_flag', false)->get() as $material)
                                                    <tr>
                                                        <td>{{ $material->code }}</td>
                                                        <td>{{ $material->name }}</td>
                                                        <td>{{ $material->category }}</td>
                                                        <td>{{ $material->uom }}</td>
                                                    </tr>
                                                    @endforeach
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
@endsection