<link rel="stylesheet" href="<?php echo plugins_url('opay/');?>css/transactions.css?ver=<?php echo $rand;?>" />

<script src="<?php echo plugins_url('opay/');?>js/transactions.js?ver=<?php echo $rand;?>"></script>

        <div class="container" id="main-page" >

            <div id="history-page-header" class="row p-4 bg-white position-relative">
                <div class="col d-flex flex-row justify-content-between align-items-start">
                   <span class="general-text"><a href="#" class="back go-back text-decoration-none text-black"><i class="fa-solid fa-angle-left me-3 "></i></a>Transaction Details</span>
                   <i class="fa-solid fa-headset support" link='<?php whatsapp_message();?>'></i>
                </div>

            </div>

            <div class="lower-part-1 px-1 receipt">

                <?php
                    if(!isset($_GET["id"]) && !isset($_GET["generate"])){
                        ?>
                        <span link="#" class=" cursor-pointer d-flex justify-content-center align-items-center <?php echo $status;?>">

                            <span class="">No Transaction Id Received</span>
                        
                        </span>
                        <?php
                    }






                    if(isset($_GET["id"])){

                        $id = $_GET["id"];
                        
                    }else{
                        $id = "0";

                    }
                
                
                    $user_id = get_current_user_id();
                    global $wpdb;
                    
                    $sub = $_GET["sub"];
                
                    switch($sub){
                        case"wallet":
                
                            $table = $wpdb->prefix."vtupress_wallet";
                            $info = "Your account should be credit/debited almost instantly";
                                
                        break;
                        case"airtime":
                                
                            $table = $wpdb->prefix."sairtime";
                            $info = "The recipient phone number is expected to be credited within 2 minutes (max). Subject to notification by network provider";

                                    
                        break;
                        case"data":
                            
                            $table = $wpdb->prefix."sdata";
                            $info = "The recipient phone number is expected to be credited within 2 minutes (max). Subject to notification by network provider";

                                
                        break;
                        case"cable":
                            
                        $table = $wpdb->prefix."scable";
                        $info = "The recipient cableTv is expected to be renewed within 2 minutes (max).";

                            
                        break;
                        case"bill":
                            
                        $table = $wpdb->prefix."sbill";
                        $info = "The recipient bill is expected to be credited within 5 minutes (max). ";

                            
                        break;
                        case"bet":
                            
                        $table = $wpdb->prefix."sbet";
                        $info = "The recipient account is expected to be credited within 5 minutes (max). ";

                            
                        break;
                        case"verification":
                            
                        $table = $wpdb->prefix."vtupress_verifications";
                        $info = "Verification is always instant";

                            
                        break;
    
                    }


                    
                    if(isset($_GET["generate"])){

                        $prepare = $wpdb->prepare("SELECT * FROM $table WHERE user_id = %s ORDER BY ID DESC LIMIT 1",$user_id);

                    }else{
                        $prepare = $wpdb->prepare("SELECT * FROM $table WHERE user_id = %s AND id = %d LIMIT 1",$user_id,$id);
                    }


                    $results = $wpdb->get_results($prepare);



                    if($results != NULL && !empty($results)){

                        $thisResult = $results[0];

                        include(__DIR__."/functions.php");

                        if(strtolower($status) == "credit"){
                            $statusText = "Credited";
                            $status = "successful";
                        }
                        elseif(strtolower($status) == "debit"){
                            $statusText = "Debited";
                            $status = "failed";
                        }
                        else{
                            $statusText = $status;
                        }

                        if($sub == "wallet"){
                            $info = ucfirst($thisResult->description);
                        }
?>

                        <div class="container  mt-2 px-2 py-3 m-auto sections first-section d-flex bg-white flex-column justify-content-center align-items-center">

                                <span class="amount fs-3"><?php echo $sign;?> ₦<?php echo number_format($amount);?></span>
                                <span class="text-<?php echo $status;?> mb-3"><?php echo ucfirst($statusText);?></span>

                                <div class="row stat-design d-flex justify-content-center ">
                                    <div class="col first-seg seg text-successful d-flex flex-column justify-content-start align-items-center">
                                        <i class=" icon fa-solid fa-circle-check"></i>
                                        <span class="text">Started</span>
                                        <span class="time">< <?php echo $time;?></span>
                                    </div>
                                    <div class="col line d-flex flex-grow-1 align-items-start"><span class="line bg-successful"></span></div>
                                    <div class="col second-seg seg  d-flex flex-column justify-content-start align-items-center  text-<?php echo $status;?>">
                                        <i class=" icon fa-solid fa-circle-check"></i>
                                        <span class="text">Completed</span>
                                        <span class="time">< <?php echo $time;?></span>
                                    </div>
                                    <div class="col line d-flex flex-grow-1 align-items-start"><span class="line bg-<?php echo $status;?>"></span></div>
                                    <div class="col second-seg seg  d-flex flex-column justify-content-start align-items-center  text-<?php echo $status;?>">
                                        <i class=" icon fa-solid fa-circle-check"></i>
                                        <span class="text"><?php echo ucfirst($statusText);?></span>
                                        <span class="time"><?php echo $time;?></span>
                                    </div>


                                </div>

                                <span class="info p-2 mt-2" id="general-text">
                                    <?php echo $info;?>
                                </span>
                        </div>

                        <div class="container  mt-2 px-2 py-3 m-auto sections second-section d-flex bg-white flex-column justify-content-center align-items-center">

                                <div class="row mt-2 stat-design d-flex justify-content-center flex-column ">
                                    <span class="mt-2 trans-details fw-bold">Transaction Details</span>

                                    <span class="mt-2 detail d-flex justify-content-between align-items-center">
                                        <span class="key">Transaction Type</span>
                                        <span class="value"><?php echo $type;?></span>
                                    </span>
                                    <span class="mt-2 detail d-flex justify-content-between align-items-center">
                                        <span class="key">Recipient Details</span>
                                        <span class="value"><?php echo $recipient;?></span>
                                    </span>

                                    <?php
                                    if($_GET["sub"] == "bill"){

                                    ?>
                                    <span class="mt-2 detail d-flex justify-content-between align-items-center">
                                        <span class="key">Meter Token</span>
                                        <span class="value"><?php echo $meter_token;?></span>
                                    </span>
                                    <?php
                                        }
                                    ?>
                                    <span class="mt-2 detail d-flex justify-content-between align-items-center">
                                        <span class="key">Transaction Id</span>
                                        <span class="value"><?php echo $id;?></span>
                                    </span>

                                    <span class="mt-2 detail d-flex justify-content-between align-items-center">
                                        <span class="key">Payment Method</span>
                                        <span class="value">Wallet</span>
                                    </span>
                                    <span class="mt-2 detail d-flex justify-content-between align-items-center">
                                        <span class="key">Transaction Date</span>
                                        <span class="value"><?php echo $time;?></span>
                                    </span>

                                </div>



                        </div>

                        <div class="container  mt-2 px-2 py-3 m-auto sections third-section d-flex bg-white flex-column justify-content-center align-items-center">

                            <div class="row mt-2 stat-design d-flex justify-content-center flex-column ">
                                <span class="mt-2 trans-details fw-bold">More Actions</span>

                                <span class="mt-2 detail d-flex justify-content-between align-items-center">
                                    <span class="key">Service</span>
                                    <span class="value service-value"><?php echo $button;?></span>
                                </span>

                            </div>
                            
                        </div>

                        <div class="container  mt-2 px-2 py-1 m-auto sections fourth-section d-flex flex-column justify-content-center align-items-center">

                            <div class="row stat-design share-buttons">
                                <div class="col d-flex justify-content-between align-items-center ">
                                    <span class="fw-bold report" link='<?php whatsapp_message("I am having a $type issue with ID $id");?>'>Report Issue</span>
                                    
                                    <?php

                                    if(preg_match("/success/",$status) || preg_match("/credit/",$status) || preg_match("/approve/",$status)){
                                    ?>
                                    <span class="fw-bold share" link="&plain=yes">Share Receipt</span>

                                    <?php
                                    }
                                    ?>

                                </div>


                            </div>
                            
                        </div>
<?php


                    }else{
                        ?>
                        <span link="#" class=" cursor-pointer d-flex justify-content-center align-items-center <?php echo $status;?>">

                            <span class="">No Transaction With Id <?php echo $id;?> Recorded</span>
                        
                        </span>

                        <?php
                    }
?>

            </div>



        </div>

