<?php
    require '../../data.php';
    $kodekeluhan = mysqli_real_escape_string($data, $_POST['tampilkode']);

    $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-end">
                <div class="sender">
                <h2 class="m-0 text-capitalize p-0">'.$sender.' '.$kodekeluhan.'</h2>
                <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>'.$message.'</p>
                </div>
            </div>';

            } else {
                echo '<div class="d-flex justify-content-start">
                <div class="receiver">
                    <h2 class="m-0 text-capitalize p-0">'.$receiver.'</h2>';
                        if($baca == '0') {
                            echo '<span class="badge bg-danger blinks">BARU</span>';
                        }

                    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>'.$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>';

    }


?>



<!-- <div class="d-flex justify-content-start">
    <div class="receiver">
        <h2>CS Zoro Toto #72831607</h2>
        <p>begini pak bla bla bla bla..</p>
    </div>
</div>

    <div class="d-flex justify-content-end">
        <div class="sender">
        <h2>CS Zoro Toto #72831607</h2>
        <p>begini pak bla bla bla bla..</p>
        </div>
    </div>

    <div class="d-flex justify-content-start">
        <div class="receiver">
            <h2>CS Zoro Toto #72831607</h2>
            <p>begini pak bla bla bla bla..</p>
        </div>
    </div>

    <div class="d-flex justify-content-start">
        <div class="receiver">
            <h2>CS Zoro Toto #72831607</h2>
            <p>begini pak bla bla bla bla..</p>
        </div>
    </div>

    <div class="d-flex justify-content-end">
        <div class="sender">
        <h2>Member #72831607</h2>
        <p>Iya saya tahu tapi masalahnya begitu saya cek dan buka itu tidak ada masuk sama sekali. tolong dong dicek dulu itu.
            keknya ada masalah itu pak.
        </p>
        </div>
    </div> -->