@extends('Dashboard.layouts.main')

@section('title', 'Detail Layanan')

@section('content')
<div class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="page-title-box">
                    <div class="page-title-right">
                        <ol class="breadcrumb m-0">
                            <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                            <li class="breadcrumb-item"><a href="{{ route('services.index') }}">Layanan</a></li>
                            <li class="breadcrumb-item active">Detail</li>
                        </ol>
                    </div>
                    <h4 class="page-title">Detail Layanan</h4>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12 mb-3">
                                <div class="d-flex justify-content-between align-items-center">
                                    <h5 class="card-title">Informasi Layanan</h5>
                                    @can('admin')
                                    <div>
                                        <a href="{{ route('services.edit', $service->id) }}" class="btn btn-primary btn-sm me-1">
                                            <i class="fe-edit"></i> Edit
                                        </a>
                                        <button type="button" class="btn btn-danger btn-sm" onclick="confirmDelete('{{ route('services.destroy', $service->id) }}')">
                                            <i class="fe-trash-2"></i> Hapus
                                        </button>
                                    </div>
                                    @endcan
                                </div>
                                <hr>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <h5 class="mb-3">Informasi Pelanggan</h5>
                                <table class="table table-sm table-borderless">
                                    <tr>
                                        <td width="40%"><strong>Nama</strong></td>
                                        <td>{{ $service->user->name }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Email</strong></td>
                                        <td>{{ $service->user->email }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>No. HP</strong></td>
                                        <td>{{ $service->user->phone ?? '-' }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Nama Badan Usaha</strong></td>
                                        <td>{{ $service->user->business_name ?? '-' }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Alamat Badan Usaha</strong></td>
                                        <td>{{ $service->user->business_address ?? '-' }}</td>
                                    </tr>
                                </table>

                                <h5 class="mt-4 mb-3">Informasi Permintaan</h5>
                                <table class="table table-sm table-borderless">
                                    <tr>
                                        <td width="40%"><strong>Status</strong></td>
                                        <td>
                                            @php 
                                                $statusClass = [
                                                    'Menunggu' => 'badge-warning',
                                                    'Diterima' => 'badge-info',
                                                    'Diproses' => 'badge-primary',
                                                    'Selesai' => 'badge-success',
                                                    'Ditolak' => 'badge-danger'
                                                ];
                                            @endphp
                                            <span class="badge {{ $statusClass[$service->status] ?? 'badge-secondary' }}">
                                                {{ $service->status }}
                                            </span>
                                        </td>
                                    </tr>
                                    @if($service->keterangan && ($service->status == 'Diterima' || $service->status == 'Ditolak'))
                                    <tr>
                                        <td><strong>Keterangan Status</strong></td>
                                        <td>
                                            <div class="alert alert-{{ $service->status == 'Diterima' ? 'info' : 'danger' }} mb-0 py-2">
                                                {{ $service->keterangan }}
                                            </div>
                                        </td>
                                    </tr>
                                    @endif
                                    <tr>
                                        <td><strong>Jenis Permintaan</strong></td>
                                        <td>{{ $service->jenis_permintaan }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Tanggal Uji</strong></td>
                                        <td>{{ \Carbon\Carbon::parse($service->tanggal_uji)->format('d F Y') }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Parameter</strong></td>
                                        <td>{{ $service->parameter }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Waktu Pendaftaran</strong></td>
                                        <td>{{ $service->created_at->format('d F Y, H:i') }}</td>
                                    </tr>
                                </table>
                            </div>
                            <div class="col-md-6">
                                <h5 class="mb-3">Detail Pengujian</h5>
                                <table class="table table-sm table-borderless">
                                    <tr>
                                        <td width="40%"><strong>Pengujian Kualitas Air</strong></td>
                                        <td>{{ $service->pengujian_kualitas_air }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Total Sampel</strong></td>
                                        <td>{{ $service->total_sampel }} sampel</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Jarak Pengambilan Sampel</strong></td>
                                        <td>{{ $service->jarak_pengambilan_sampel }}</td>
                                    </tr>
                                    <tr>
                                        <td><strong>Tanggal Selesai Uji</strong></td>
                                        <td>
                                            @if($service->tanggal_selesai_uji)
                                                {{ \Carbon\Carbon::parse($service->tanggal_selesai_uji)->format('d F Y') }}
                                            @elseif($service->status == 'Ditolak')
                                                <span class="badge badge-danger">Ditolak</span>
                                            @else
                                                <span class="badge badge-warning">Menunggu</span>
                                            @endif
                                        </td>
                                    </tr>
                                </table>

                                <h5 class="mt-4 mb-3">Informasi Biaya</h5>
                                <table class="table table-sm table-borderless">
                                    <tr>
                                        <td width="40%"><strong>Biaya Retribusi Parameter</strong></td>
                                        <td>
                                            @if($service->biaya_retribusi_parameter)
                                                Rp {{ number_format($service->biaya_retribusi_parameter, 0, ',', '.') }}
                                            @elseif($service->status == 'Ditolak')
                                                <span class="badge badge-danger">Ditolak</span>
                                            @else
                                                <span class="badge badge-warning">Menunggu</span>
                                            @endif
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><strong>Biaya Retribusi Jarak</strong></td>
                                        <td>
                                            @if($service->biaya_retribusi_jarak)
                                                Rp {{ number_format($service->biaya_retribusi_jarak, 0, ',', '.') }}
                                            @elseif($service->status == 'Ditolak')
                                                <span class="badge badge-danger">Ditolak</span>
                                            @else
                                                <span class="badge badge-warning">Menunggu</span>
                                            @endif
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><strong>Total Biaya Retribusi</strong></td>
                                        <td>
                                            @if($service->biaya_retribusi)
                                                <strong>Rp {{ number_format($service->biaya_retribusi, 0, ',', '.') }}</strong>
                                            @elseif($service->status == 'Ditolak')
                                                <span class="badge badge-danger">Ditolak</span>
                                            @else
                                                <span class="badge badge-warning">Menunggu</span>
                                            @endif
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>

                        @if($service->file_hasil_uji)
                        <div class="row mt-4">
                            <div class="col-md-12">
                                <div class="card border">
                                    <div class="card-body">
                                        <h5 class="card-title">Hasil Uji</h5>
                                        <p>File hasil uji telah tersedia dan dapat dilihat melalui tautan di bawah ini:</p>
                                        <div class="btn-group">
                                            <a href="{{ asset('uploads/hasil_uji/'.$service->file_hasil_uji) }}" class="btn btn-success" target="_blank">
                                                <i class="fe-eye"></i> Lihat Hasil Uji
                                            </a>
                                            <a href="{{ asset('uploads/hasil_uji/'.$service->file_hasil_uji) }}" class="btn btn-primary" download>
                                                <i class="fe-download"></i> Unduh Hasil Uji
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        @else
                        <div class="row mt-4">
                            <div class="col-md-12">
                                <div class="card border">
                                    <div class="card-body">
                                        <h5 class="card-title">Hasil Uji</h5>
                                        <p>
                                            @if($service->status == 'Ditolak')
                                                Hasil uji tidak tersedia karena permintaan layanan ditolak.
                                                @if($service->keterangan)
                                                <div class="alert alert-danger mt-2">
                                                    <strong>Alasan Penolakan:</strong> {{ $service->keterangan }}
                                                </div>
                                                @endif
                                            @else
                                                Hasil uji belum tersedia.
                                            @endif
                                        </p>
                                        @if($service->status == 'Ditolak')
                                            <span class="badge badge-danger">Ditolak</span>
                                        @else
                                            <span class="badge badge-warning">Menunggu</span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Sertakan Modal Konfirmasi Hapus -->
@include('layouts.delete-modal')
@endsection 