<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Formulir Pendaftaran - {{ $registrationData->daftar_id }}</title>
    <style>
        /* Reset & Base Styles */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'DejaVu Sans', 'Helvetica', 'Arial', sans-serif;
            font-size: 11px;
            line-height: 1.4;
            color: #333333;
            background: white;
            padding: 15px;
        }
        
        /* Container */
        .pdf-container {
            max-width: 100%;
            margin: 0 auto;
            background: white;
        }
        
        /* Header */
        .header {
            text-align: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 3px solid #169E16;
        }
        
        .logo {
            width: 80px;
            margin-bottom: 10px;
        }
        
        .header h1 {
            font-size: 16px;
            font-weight: bold;
            color: #169E16;
            margin-bottom: 5px;
        }
        
        .header h2 {
            font-size: 13px;
            font-weight: normal;
            color: #555;
        }
        
        /* Section Styles */
        .section {
            margin-bottom: 15px;
            page-break-inside: avoid;
        }
        
        .section-title {
            font-size: 13px;
            font-weight: bold;
            color: #169E16;
            background-color: #e8f5e8;
            padding: 6px 10px;
            margin-bottom: 10px;
            border-left: 4px solid #169E16;
        }
        
        /* Table Styles */
        .info-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 5px;
        }
        
        .info-table td {
            padding: 5px 8px;
            vertical-align: top;
            border-bottom: 1px solid #eeeeee;
        }
        
        .info-table td.label {
            width: 170px;
            font-weight: 600;
            color: #555;
            background-color: #f9f9f9;
        }
        
        .info-table td.value {
            color: #333;
        }
        
        .info-table td.value strong {
            color: #169E16;
            font-size: 12px;
        }
        
        /* Badge Nomor Pendaftaran */
        .badge-number {
            background-color: #169E16;
            border-radius: 8px;
            padding: 10px 15px;
            margin-bottom: 20px;
            color: white;
        }
        
        .badge-number table {
            background: transparent;
        }
        
        .badge-number td.label {
            background: transparent;
            color: rgba(255,255,255,0.9);
        }
        
        .badge-number td.value {
            color: white;
        }
        
        .badge-number td.value strong {
            color: white;
            font-size: 16px;
        }
        
        /* Signature Section */
        .signature-section {
            margin-top: 30px;
            display: table;
            width: 100%;
            page-break-inside: avoid;
        }
        
        .signature-left {
            display: table-cell;
            width: 45%;
            text-align: center;
        }
        
        .signature-right {
            display: table-cell;
            width: 55%;
            text-align: center;
        }
        
        .signature-stamp {
            margin-top: 10px;
        }
        
        .signature-stamp img {
            width: 110px;
            height: auto;
        }
        
        .signature-line {
            margin-top: 40px;
            margin-bottom: 5px;
            font-weight: bold;
        }
        
        .signature-name {
            font-weight: bold;
            text-decoration: underline;
            margin-top: 30px;
            font-size: 12px;
            color: #169E16;
        }
        
        /* Footer */
        .footer {
            margin-top: 20px;
            padding-top: 10px;
            text-align: center;
            font-size: 9px;
            color: #999;
            border-top: 1px solid #ddd;
        }
        
        /* Spacing */
        .text-center { text-align: center; }
        .font-bold { font-weight: bold; }
    </style>
</head>
<body>
    @php
        // Fungsi untuk convert gambar ke base64
        function imageToBase64($path) {
            if (file_exists($path)) {
                $type = pathinfo($path, PATHINFO_EXTENSION);
                $data = file_get_contents($path);
                return 'data:image/' . $type . ';base64,' . base64_encode($data);
            }
            return '';
        }
        
        // Cek beberapa kemungkinan path logo
        $logoPaths = [
            public_path('images/logo/logo1.png'),
            public_path('images/logo/logo1.jpg'),
            public_path('img/logo/logo1.png'),
            public_path('assets/images/logo/logo1.png'),
            base_path('public/images/logo/logo1.png'),
            $_SERVER['DOCUMENT_ROOT'] . '/images/logo/logo1.png',
        ];
        
        $logoBase64 = '';
        foreach ($logoPaths as $path) {
            if (file_exists($path)) {
                $logoBase64 = imageToBase64($path);
                break;
            }
        }
        
        // Cek beberapa kemungkinan path TTD
        $ttdPaths = [
            public_path('images/ttd_cap_fix.png'),
            public_path('images/ttd_cap_fix.jpg'),
            public_path('img/ttd_cap_fix.png'),
            public_path('assets/images/ttd_cap_fix.png'),
            base_path('public/images/ttd_cap_fix.png'),
            $_SERVER['DOCUMENT_ROOT'] . '/images/ttd_cap_fix.png',
        ];
        
        $ttdBase64 = '';
        foreach ($ttdPaths as $path) {
            if (file_exists($path)) {
                $ttdBase64 = imageToBase64($path);
                break;
            }
        }
        
        // Jika masih tidak ditemukan, coba cari manual dengan glob
        if (empty($logoBase64)) {
            $foundLogo = glob(public_path('**/logo1.png'));
            if (!empty($foundLogo)) {
                $logoBase64 = imageToBase64($foundLogo[0]);
            }
        }
        
        if (empty($ttdBase64)) {
            $foundTtd = glob(public_path('**/ttd_cap_fix.png'));
            if (!empty($foundTtd)) {
                $ttdBase64 = imageToBase64($foundTtd[0]);
            }
        }
    @endphp
    
    <div class="pdf-container">
        
        <!-- HEADER -->
        <div class="header">
            @if(!empty($logoBase64))
                <img class="logo" src="{{ $logoBase64 }}" alt="Logo Kampus">
            @else
                <div style="width: 80px; height: 80px; margin: 0 auto 10px; background-color: #f0f0f0; border-radius: 50%; display: flex; align-items: center; justify-content: center;">
                    <span style="font-size: 10px; color: #999;">Logo</span>
                </div>
            @endif
            <h1>FORMULIR PENDAFTARAN</h1>
            <h2>CALON MAHASISWA BARU<br>{{ strtoupper($settings['nama kampus'] ?? 'INSTITUT SAINS DAN TEKNOLOGI AL-KAMAL') }}</h2>
        </div>

        <!-- NOMOR PENDAFTARAN -->
        <div class="section">
            <div class="badge-number">
                <table class="info-table" style="margin-bottom: 0;">
                    <tr>
                        <td class="label" style="width: 170px; background: transparent; color: white;">Nomor Pendaftaran</td>
                        <td class="value"><strong style="font-size: 16px; color: white;">{{ $registrationData->daftar_id }}</strong></td>
                    </tr>
                    <tr>
                        <td class="label" style="background: transparent; color: white;">Tanggal Pendaftaran</td>
                        <td class="value" style="color: white;">{{ date('d-m-Y H:i:s') }}</td>
                    </tr>
                </table>
            </div>
        </div>

        <!-- DATA PRIBADI -->
        <div class="section">
            <div class="section-title">A. DATA PRIBADI</div>
            <table class="info-table">
                <tr>
                    <td class="label">Nama Lengkap</td>
                    <td class="value"><strong>{{ strtoupper($registrationData->nama_leng) }}</strong></td>
                </tr>
                <tr>
                    <td class="label">Jenis Kelamin</td>
                    <td class="value">{{ $registrationData->j_kel == 'L' ? 'Laki-laki' : 'Perempuan' }}</td>
                </tr>
                <tr>
                    <td class="label">Tempat, Tanggal Lahir</td>
                    <td class="value">{{ $registrationData->tmpt_lahir }}, {{ $registrationData->tgl_lahir }}</td>
                </tr>
                <tr>
                    <td class="label">Nama Ibu Kandung</td>
                    <td class="value">{{ $registrationData->ibu }}</td>
                </tr>
                <tr>
                    <td class="label">Agama</td>
                    <td class="value">{{ $registrationData->agama }}</td>
                </tr>
            </table>
        </div>

        <!-- DATA ALAMAT & KONTAK -->
        <div class="section">
            <div class="section-title">B. ALAMAT & KONTAK</div>
            <table class="info-table">
                <tr>
                    <td class="label">Alamat KTP</td>
                    <td class="value">{{ $registrationData->al_ktp }}</td>
                </tr>
                <tr>
                    <td class="label">Alamat Domisili</td>
                    <td class="value">{{ $registrationData->al_dom ?: '-' }}</td>
                </tr>
                <tr>
                    <td class="label">Nomor KTP</td>
                    <td class="value">{{ $registrationData->no_ktp }}</td>
                </tr>
                <tr>
                    <td class="label">Nomor Darurat (Orang Tidak Serumah)</td>
                    <td class="value">{{ $registrationData->no_hp ?: '-' }}</td>
                </tr>
                <tr>
                    <td class="label">Nomor HP/WhatsApp</td>
                    <td class="value">{{ $registrationData->no_wa }}</td>
                </tr>
                <tr>
                    <td class="label">Email</td>
                    <td class="value">{{ $registrationData->email }}</td>
                </tr>
            </table>
        </div>

        <!-- DATA PENDIDIKAN -->
        <div class="section">
            <div class="section-title">C. DATA PENDIDIKAN</div>
            <table class="info-table">
                <tr>
                    <td class="label">Perguruan Tinggi</td>
                    <td class="value">{{ $registrationData->kampus }}</td>
                </tr>
                <tr>
                    <td class="label">Jurusan</td>
                    <td class="value"><strong>{{ $registrationData->jurusan }}</strong></td>
                </tr>
                <tr>
                    <td class="label">Kelas</td>
                    <td class="value">{{ $registrationData->kelas }}</td>
                </tr>
                <tr>
                    <td class="label">Lulusan</td>
                    <td class="value">{{ $registrationData->lulusan }}</td>
                </tr>
                <tr>
                    <td class="label">Nama Sekolah / Universitas</td>
                    <td class="value">{{ $registrationData->sekolah }}</td>
                </tr>
            </table>
        </div>

        <!-- DATA LAINNYA -->
        <div class="section">
            <div class="section-title">D. DATA LAINNYA</div>
            <table class="info-table">
                <tr>
                    <td class="label">Pekerjaan</td>
                    <td class="value">{{ $registrationData->pekerjaan }}</td>
                </tr>
                <tr>
                    <td class="label">Ukuran Jaket Almamater</td>
                    <td class="value">{{ $registrationData->jaket }}</td>
                </tr>
                <tr>
                    <td class="label">Sumber Informasi</td>
                    <td class="value">{{ $registrationData->info }}</td>
                </tr>
                <tr>
                    <td class="label">Biaya</td>
                    <td class="value"><strong>{{ $registrationData->biaya }}</strong></td>
                </tr>
            </table>
        </div>

        <!-- INFORMASI PEMBAYARAN -->
        <div class="section">
            <div class="section-title">E. INFORMASI PEMBAYARAN</div>
            <table class="info-table">
                <tr>
                    <td class="label" style="background-color: #fff8e7;">Biaya Pendaftaran</td>
                    <td class="value" style="background-color: #fff8e7;"><strong>S1 Rp 100.000,-</strong></td>
                </tr>
                <tr>
                    <td class="label" style="background-color: #fff8e7;">Biaya Pendaftaran</td>
                    <td class="value" style="background-color: #fff8e7;"><strong>S2 Rp 300.000,-</strong></td>
                </tr>
                <tr>
                    <td class="label">Bank BNI</td>
                    <td class="value">No. Rekening: <strong>8282823875</strong> a.n. Edukasi Indonesia Jaya</td>
                </tr>
            </table>
        </div>

        <!-- TANDA TANGAN -->
        <div class="signature-section">
            <div class="signature-left">
                <p>{{ $settings['nama kampus'] ?? 'INSTITUT SAINS DAN TEKNOLOGI AL-KAMAL' }}</p>
                <div class="signature-stamp">
                    @if(!empty($ttdBase64))
                        <img src="{{ $ttdBase64 }}" alt="TTD Cap">
                    @else
                        <div style="width: 110px; height: 60px; margin: 0 auto; background-color: #f0f0f0; border: 1px solid #ddd; display: flex; align-items: center; justify-content: center;">
                            <span style="font-size: 10px; color: #999;">Cap & TTD</span>
                        </div>
                    @endif
                </div>
                <p>STAFF PMB</p>
                <p class="signature-line">(_____________________)</p>
            </div>
            <div class="signature-right">
                <p>{{ date('d-m-Y') }}</p><br>
                <p>Calon Mahasiswa,</p>
                <div class="signature-name">
                    {{ strtoupper($registrationData->nama_leng) }}
                </div>
            </div>
        </div>

        <!-- FOOTER -->
        <div class="footer">
            <p>Dokumen ini adalah bukti pendaftaran resmi. Harap disimpan untuk keperluan administrasi selanjutnya.</p>
            <p>*Konfirmasi pembayaran dapat dilakukan melalui WhatsApp ke 6287890198284</p>
        </div>
        
    </div>
</body>
</html>