<?php
    require '../assets/config-data.php';
    $kodekeluhan = mysqli_real_escape_string($data, $_GET['kode']);

    $skeluhan = "SELECT * FROM keluhan_member WHERE kode_keluhan = '$kodekeluhan'";
    $qkeluhan = mysqli_query($data, $skeluhan);

    if(mysqli_num_rows($qkeluhan) > 0) {
        $skas = "SELECT user_keluhan FROM kasus_keluhan WHERE kode_kasus = '$kodekeluhan'";
        $qkas = mysqli_query($data, $skas);
        $fkas = mysqli_fetch_assoc($qkas);

        echo '<input type="hidden" name="kodehid" value="'.$kodekeluhan.'" />
        <input type="hidden" name="userhid" value="'.$fkas['user_keluhan'].'" />';
           
        while($fkeluhan = mysqli_fetch_assoc($qkeluhan)) {
            $sender = $fkeluhan['sender_keluhan'];
            $receiver = $fkeluhan['receiver_keluhan'];
            $message = $fkeluhan['msg_keluhan'];
            $tglkelu = $fkeluhan['tgl_keluhan'];
            $baca = $fkeluhan['baca_keluhan'];
            if($sender) {
                echo '<div class="d-flex justify-content-start">
                <div style="width: 350px;">
                <h6 class="m-0 text-capitalize p-0">'.$sender.' #'.$kodekeluhan.'</h6>';
                if($baca == '0') {
                    echo '<span class="badge bg-danger text-light blinks">BARU</span>';
                }
                echo '<p style="font-size: 0.6rem; color : #715600;" class="m-0 mb-1 p-0"><i class="fas fa-clock"></i> '.date("d M Y H:i:s", strtotime($tglkelu)).'</p>
                <p style="background-color: #e7e7e7;" class="rounded p-2">'.$message.'</p>
                </div>
            </div>';

            } else {
                    echo '<div class="d-flex justify-content-end">
                    <div class="text-right" style="width: 350px;">
                        <h6 class="m-0 text-capitalize p-0">'.$receiver.'</h6>';

                        echo '<p style="font-size: 0.6rem;" class="text-secondary m-0 mb-1 p-0"><i class="fas fa-clock"></i> '.date("d M Y H:i:s", strtotime($tglkelu)).'</p>
                        <p style="background-color: #e7e7e7;" class="rounded p-2">'.$message.'</p>
                    </div>
                </div>';
            }
        }

    } else {
        
        echo '<p class="text-danger fw-bold">Kode Keluhan tidak ditemukan!!. Mohon diperiksa kembali kode yang dimasukkan.</p>
        <p class="text-danger">Pastikan ada tanda <strong>#</strong> diawal kode misal: #123456</p>';

    }


?>