<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Form Tambah Data</title>
    <style>
        body {
            font-family: 'Roboto', sans-serif;
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .form-container {
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            max-width: 400px;
            width: 100%;
            position: relative;
        }

        .form-container h2 {
            text-align: center;
            margin-bottom: 20px;
            color: #333;
        }

        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #555;
        }

        .form-group input, .form-group select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
        }

        .form-group input:focus, .form-group select:focus {
            outline: none;
            border-color: #6200ee;
        }

        .btn-submit {
            width: 100%;
            padding: 10px;
            background-color: #6200ee;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
        }

        .btn-submit:hover {
            background-color: #3700b3;
        }

        .back-button {
            position: absolute;
            top: 20px;
            left: 20px;
            background-color: transparent;
            border: none;
            font-size: 24px;
            color: #6200ee;
            cursor: pointer;
        }

        .back-button:hover {
            color: #3700b3;
        }
    </style>
</head>
<body>

    <div class="form-container">
        <h2>Tambah Data</h2>
        <?php
include 'koneksi.php';

// Ambil nomor pendaftaran terakhir
$query = mysqli_query($koneksi, "SELECT MAX(no_pendaftaran) as no_pendaftaran_terakhir FROM tbl_jadwal");
$data = mysqli_fetch_array($query);
$no_pendaftaran_terakhir = $data['no_pendaftaran_terakhir'];

// Generate nomor pendaftaran baru
if ($no_pendaftaran_terakhir) {
    // Extract angka dari nomor terakhir
    $nomor_baru = (int)substr($no_pendaftaran_terakhir, -4) + 1;
    $no_pendaftaran_baru = 'REG' . date('Ymd') . sprintf('%04s', $nomor_baru);
} else {
    // Jika belum ada nomor pendaftaran sebelumnya
    $no_pendaftaran_baru = 'REG' . date('Ymd') . '0001';
}
?>

        <form action="pasien_act.php" method="post" enctype="multipart/form-data">
            <div class="form-group">
                <label for="no_pendaftaran">No Pendaftaran</label>
                <input type="text" id="no_pendaftaran" name="no_pendaftaran" value="<?php echo $no_pendaftaran_baru; ?>" readonly>
            </div>
             <div class="form-group">
                <label for="nama">Nama Pasien</label>
                <input type="text" id="nama" name="nama_pasien" placeholder="Masukkan Nama Pasien" required>
            </div>
            <div class="form-group">
                <label for="nama">Hari</label>
                <input type="text" id="nama" name="nama" placeholder="Masukkan hari" required>
            </div>
            <div class="form-group">
                <label for="tanggal">Tanggal Berobat</label>
                <input type="date" id="tanggal" name="tanggal" required>
            </div>
            <div class="form-group">
                <label for="keterangan">Keterangan</label>
                <input type="text" id="keterangan" name="keterangan" placeholder="Masukkan keterangan" required>
            </div>
            <div class="form-group">
                <label for="nama_dokter">Dokter</label>
                <select id="nama_dokter" name="nama_dokter" required>
                    <option value="">- Pilih Dokter -</option>
                    <?php 
                    $data = mysqli_query($koneksi, "SELECT * FROM tbl_dokter");
                    while ($d = mysqli_fetch_array($data)) {
                        echo "<option value='".$d['id_dokter']."'>".$d['nama_dokter']."</option>";
                    }
                    ?>
                </select>
            </div>
            <div class="form-group">
                <label for="nama_poli">Poli</label>
                <select id="nama_poli" name="nama_poli" required>
                    <option value="">- Pilih Poli -</option>
                    <?php 
                    $data = mysqli_query($koneksi, "SELECT * FROM tbl_poli");
                    while ($d = mysqli_fetch_array($data)) {
                        echo "<option value='".$d['id_poli']."'>".$d['nama_poli']."</option>";
                    }
                    ?>
                </select>
            </div>

            <button type="submit" class="btn-submit">Tambah Data</button>
        </form>
    </div>

</body>
</html>
