@extends('user.template')

@section('title', 'Detail ' . $tps->nama_tps)

@section('content')

@php
function toDMS($decimal, $type = 'lat') {
	$direction = $decimal < 0
            ? ($type === 'lat' ? 'LS' : 'BB')
            : ($type === 'lat' ? 'LU' : 'BT');

        $decimal = abs($decimal);
        $degrees = floor($decimal);
        $minutesFloat = ($decimal - $degrees) * 60;
        $minutes = floor($minutesFloat);
        $seconds = round(($minutesFloat - $minutes) * 60, 2);

        return $degrees . '° ' . $minutes . "' " . $seconds . '" ' . $direction;
    }
@endphp

<div class="page-title">
	<div class="container d-lg-flex justify-content-between align-items-center">
		<h1>Detail TPS</h1>
	    <nav class="breadcrumbs">
            <ol>
                <li><a href="/">Beranda</a></li>
                <li>Sebaran TPS</li>
                <li class="current">Detail TPS</li>
            </ol>
        </nav>
    </div>
</div>

<section class="section">
    <div class="container">

        {{-- HERO TPS --}}
        <div class="mb-4 border-0 shadow-sm card">
            <div class="row g-0">
                <div class="col-lg-5">
                    <img src="{{ $tps->foto_tps ? asset('assets/admin/images/tps/'.$tps->foto_tps) : asset('assets/user/img/about-portrait.jpg') }}"
                         class="img-fluid h-100 w-100 rounded-start"
                         style="object-fit:cover">
                </div>

                <div class="col-lg-7">
                    <div class="p-4 card-body">
                        <h3 class="mb-1 fw-bold">{{ $tps->nama_tps }}</h3>
                        <p class="mb-3 text-muted">{{ $tps->alamat_tps }}</p>

                        <span class="mb-3 badge bg-success">
                            {{ $tps->status_tps ?? 'Tidak diketahui' }}
                        </span>

                        {{-- INFO GRID --}}
                        <div class="mt-3 row">
                            <div class="mb-3 col-md-6">
                                <small class="text-muted">Kategori TPS</small>
                                <div class="fw-semibold">
                                    {{ $tps->kategori->nama_kategori ?? '-' }}
                                </div>
                            </div>

                            <div class="mb-3 col-md-6">
                                <small class="text-muted">Kapasitas</small>
                                <div class="fw-semibold">
                                    {{ $tps->kapasitas_tps ?? '-' }}
                                </div>
                            </div>

                            <div class="mb-3 col-md-6">
                                <small class="text-muted">Tahun Pembuatan</small>
                                <div class="fw-semibold">
                                    {{ $tps->tahun_pembuatan ?? '-' }}
                                </div>
                            </div>

                            <div class="mb-3 col-md-6">
                                <small class="text-muted">Koordinat</small>
                                <div class="fw-semibold">
                                    {{ toDMS($tps->latitude, 'lat') }} <br>
                                    {{ toDMS($tps->longitude, 'lng') }}
                                </div>
                            </div>
                        </div>

                        <a href="{{ route('user.aduan', ['tps_id' => $tps->id_tps]) }}"
                           class="mt-3 btn btn-danger">
                            Adukan TPS
                        </a>
                    </div>
                </div>
            </div>
        </div>

        {{-- ADUAN TPS --}}
        <div class="border-0 shadow-sm card">
            <div class="p-4 card-body">
                <h5 class="mb-3 fw-bold">Aduan yang Telah Ditanggapi</h5>

                @if($aduanTps->count())
                    @foreach($aduanTps as $aduan)
                        <div class="p-3 mb-3 rounded bg-light">
                            <div class="mb-1 d-flex justify-content-between">
                                <strong>{{ $aduan->nama_pelapor }}</strong>
                                <small class="text-muted">
                                    {{ \Carbon\Carbon::parse($aduan->tanggal_aduan)->translatedFormat('d M Y') }}
                                </small>
                            </div>

                            <p class="mb-2 small text-secondary">
                                {{ $aduan->isi_aduan }}
                            </p>

                            <div class="border-start border-success ps-3">
                                <small class="text-success fw-semibold">
                                    Tanggapan Admin
                                </small>
                                <div class="small">
                                    {{ $aduan->tanggapan_admin }}
                                </div>
                            </div>
                        </div>
                    @endforeach
                @else
                    <small class="text-muted">
                        Belum ada aduan yang ditanggapi.
                    </small>
                @endif
            </div>
        </div>

    </div>
</section>

@endsection
