@extends('dashboard.app')

@section('title', 'Detail Tracer Study')

@section('content')
    <div class="page-content">
        <nav class="page-breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                <li class="breadcrumb-item"><a href="{{ route('tracer.index') }}">Data Tracer Study</a></li>
                <li class="breadcrumb-item active" aria-current="page">Detail Tracer Study</li>
            </ol>
        </nav>

        <div class="row">
            <div class="col-md-12 grid-margin stretch-card">
                <div class="card">
                    <div class="card-body">
                        <h6 class="card-title">Detail Data Tracer Study</h6>
                        <hr>
                        
                        <div class="row">
                            <div class="col-md-6">
                                <table class="table table-bordered">
                                    <tr>
                                        <th width="200">Tanggal Dibuat</th>
                                        <td>{{ \Carbon\Carbon::parse($tracer->created_at)->format('d/m/Y H:i:s') }}</td>
                                    </tr>
                                    <tr>
                                        <th>Nama Lengkap</th>
                                        <td>{{ $tracer->nama }}</td>
                                    </tr>
                                    <tr>
                                        <th>Jenis Kelamin</th>
                                        <td>{{ $tracer->jenis_kelamin == 'L' ? 'Laki-laki' : 'Perempuan' }}</td>
                                    </tr>
                                    <tr>
                                        <th>Alamat Domisili</th>
                                        <td>{{ $tracer->alamat_domisili }}</td>
                                    </tr>
                                    <tr>
                                        <th>Jurusan</th>
                                        <td>{{ $tracer->jurusan }}</td>
                                    </tr>
                                    <tr>
                                        <th>No HP / WhatsApp</th>
                                        <td>
                                            <a href="https://wa.me/{{ preg_replace('/^0/', '62', $tracer->no_hp) }}" target="_blank">
                                                {{ $tracer->no_hp }}
                                            </a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>Email Pribadi</th>
                                        <td>{{ $tracer->email_pribadi }}</td>
                                    </tr>
                                    <tr>
                                        <th>Tanggal Kelulusan</th>
                                        <td>{{ \Carbon\Carbon::parse($tracer->tanggal_kelulusan)->format('d/m/Y') }}</td>
                                    </tr>
                                    <tr>
                                        <th>Memiliki Sertifikat</th>
                                        <td>
                                            <span class="badge bg-{{ $tracer->memiliki_sertifikat == 'Ya' ? 'success' : 'danger' }}">
                                                {{ $tracer->memiliki_sertifikat }}
                                            </span>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="col-md-6">
                                <table class="table table-bordered">
                                    <tr>
                                        <th width="200">Nama Instansi/Perusahaan</th>
                                        <td>{{ $tracer->nama_instansi ?? '-' }}</td>
                                    </tr>
                                    <tr>
                                        <th>Mulai Bekerja</th>
                                        <td>{{ $tracer->mulai_bekerja ? \Carbon\Carbon::parse($tracer->mulai_bekerja)->format('d/m/Y') : '-' }}</td>
                                    </tr>
                                    <tr>
                                        <th>Waktu Menunggu Pekerjaan</th>
                                        <td>{{ $tracer->waktu_menunggu ?? '-' }}</td>
                                    </tr>
                                    <tr>
                                        <th>Alamat Perusahaan</th>
                                        <td>{{ $tracer->alamat_perusahaan ?? '-' }}</td>
                                    </tr>
                                    <tr>
                                        <th>Sosial Media</th>
                                        <td>{{ $tracer->sosial_media ?? '-' }}</td>
                                    </tr>
                                    <tr>
                                        <th>Kesan Selama Kuliah</th>
                                        <td>{{ $tracer->kesan ?? '-' }}</td>
                                    </tr>
                                    <tr>
                                        <th>Saran untuk Kampus</th>
                                        <td>{{ $tracer->saran ?? '-' }}</td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        
                        <!-- Sertifikat Section -->
                        @if($tracer->memiliki_sertifikat == 'Ya' && $tracer->sertifikat)
                            <div class="row mt-4">
                                <div class="col-12">
                                    <h6 class="card-title">Daftar Sertifikat Kompetensi</h6>
                                    <hr>
                                    <div class="table-responsive">
                                        <table class="table table-bordered">
                                            <thead>
                                                <tr>
                                                    <th>No</th>
                                                    <th>Nama Sertifikat</th>
                                                    <th>File Sertifikat</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                @php
                                                    $sertifikats = is_string($tracer->sertifikat) ? json_decode($tracer->sertifikat, true) : $tracer->sertifikat;
                                                @endphp
                                                @if(is_array($sertifikats) && count($sertifikats) > 0)
                                                    @foreach($sertifikats as $index => $sertifikat)
                                                        <tr>
                                                            <td>{{ $loop->iteration }}</td>
                                                            <td>{{ $sertifikat['nama'] ?? '-' }}</td>
                                                            <td>
                                                                @if(isset($sertifikat['file']))
                                                                    <a href="{{ Storage::url($sertifikat['file']) }}" target="_blank" class="btn btn-sm btn-primary">
                                                                        <i class="fa fa-download"></i> Lihat Sertifikat
                                                                    </a>
                                                                @else
                                                                    -
                                                                @endif
                                                            </td>
                                                        </tr>
                                                    @endforeach
                                                @else
                                                    <tr>
                                                        <td colspan="3" class="text-center">Data sertifikat tidak tersedia</td>
                                                    </tr>
                                                @endif
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        @endif
                        
                        <div class="mt-3">
                            <a href="{{ route('tracer.index') }}" class="btn btn-secondary">
                                <i class="fa fa-arrow-left"></i> Kembali
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection