<?php
session_start();
include_once ('../include/session.php');
require_once '../include/class.user.php';
if(!isset($_SESSION['acc_no'])){
    
header("Location: login.php");
exit(); 
}
$reg_user = new USER();



$stmt = $reg_user->runQuery("SELECT * FROM account WHERE acc_no=:acc_no");
$stmt->execute(array(":acc_no"=>$_SESSION['acc_no']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

if(isset($_GET['subject'])){
    
$subject=$_GET['subject'];  

$msg = $reg_user->runQuery("SELECT * FROM message WHERE subject='$subject'");
$msg->execute();
$show = $msg->fetch(PDO::FETCH_ASSOC);


}


?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>View Messages - Fintech</title>
            
            <?php include 'header.php';?>

            <main>
    <div class="td flex">

        <!-- Inbox body -->
        <div class="ad flex fh qq fe ws wl wc" :class="inboxSidebarOpen ? 'translate-x-1/3' : 'translate-x-0'">
            <div class="ad vd jd zx mr">
                <header class="_y je js rw">
                    <h1 class="gy yt text-slate-800 font-bold rx _a r_"><?php echo $show['subject']; ?></h1>
                </header>
                <div class="bg-white by rounded-sm border border-slate-200 vw lg lb">
                    <div class="mu" x-data="{ open: true }">
                        <header class="flex fd">
                            <div class="ad">
                                <div class="_y fd fg ib">
                                    <div class="tnr items-center in _a">
                                        <button class="text-sm g_ text-slate-800 gh ci" @click.prevent="open = !open"><?php echo $show['sender_name']; ?></button>
                                    </div>
                                    <div class="gb gk text-slate-500 co in _a"><?php echo $show['date']; ?></div>
                                </div>
                                <div class="gb gk text-slate-500" x-show="open" x-cloak="">To me, <?php echo $row['fname']; ?> <?php echo $row['lname']; ?></div>
                                <div class="text-sm" x-show="!open"><?php echo $show['subject']; ?></div>
                            </div>
                        </header>
                        <div class="text-sm text-slate-800 ij li" x-show="open" x-cloak="">
                           <?php echo $show['msg']; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>


            <?php include 'footer.php';?>