<?php 

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

include("config.php"); 
include 'inc/header.php'; 
include("functions.php"); 

    // Initialize feedback data safely
    $update       = false;
    $feedbackData = [];
    if (isset($_GET['userId'])) {
        $update       = true;
        $feedbackData = get_single_feedback_details($_GET['userId']);
        if (!is_array($feedbackData)) {
            $feedbackData = [];
        }
    }

    // Resolve branch name from branch_id (branch_name column no longer exists)
    $branchName = 'N/A';
    if (!empty($feedbackData['branch_id'])) {
        $branch = get_single_branch($feedbackData['branch_id']);
        if (is_array($branch) && !empty($branch['name'])) {
            $branchName = $branch['name'];
        }
    }

$all_admins = get_all_admins("all");

?>

    <!--== BODY CONTNAINER ==-->
    <div class="container-fluid sb2">


       

        <div class="row">
            <?php include 'inc/sidebar.php';?>
            <div class="sb2-2">
                <div class="sb2-2-2">
                    <ul>
                        <li><a href="dashboard.php"><i class="fa fa-home" aria-hidden="true"></i> Home</a>
                        </li>
                        <li class="active-bre"><a href="#"> Feedback Detail</a>
                        </li>
                    </ul>
                </div>
                <div class="sb2-2-3">
                    <div class="row">
                        <div class="col-md-6 col-lg-6 col-sm-12 col-xs-12">
                            <div class="box-inn-sp">
                                <div class="inn-title">
                                    <h4>User Details</h4>
                                </div>
                                <div class="tab-inn">
                                    <form>
                                        <div class="row">
                                            <div class="input-field col s6">
                                                <input id="name" type="text" value="<?= isset($feedbackData['name']) ? $feedbackData['name'] : 'N/A'; ?>" class="validate" readonly>
                                                <label for="name">Customer Name</label>
                                            </div>
                                            <div class="input-field col s6">
                                                <input id="branch_name" type="text" value="<?= $branchName; ?>" class="validate" readonly>
                                                <label for="branch_name">Branch Name</label>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="input-field col s6">
                                                <input id="number" type="text" value="<?= isset($feedbackData['number']) ? $feedbackData['number'] : 'N/A'; ?>" class="validate" readonly>
                                                <label for="number">Mobile</label>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="input-field col s12">
                                                <textarea id="message" class="materialize-textarea" rows="4" readonly><?= isset($feedbackData['message']) ? $feedbackData['message'] : 'N/A'; ?></textarea>
                                                <label for="message">Message</label>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <hr>
                        </div>
                        <div class="col-md-6 col-lg-6 col-sm-12 col-xs-12">
                            <div class="box-inn-sp">
                                <div class="inn-title">
                                    <h4>User Feedbacks </h4>
                                </div>
                                <?php
                                    $rating_1 = isset($feedbackData['FoodQualityrating']) ? (int)$feedbackData['FoodQualityrating'] : 0;
                                    $rating_2 = isset($feedbackData['FoodPresentationrating']) ? (int)$feedbackData['FoodPresentationrating'] : 0;
                                    $rating_3 = isset($feedbackData['Atmosphererating']) ? (int)$feedbackData['Atmosphererating'] : 0;
                                    $rating_4 = isset($feedbackData['Ambiancerating']) ? (int)$feedbackData['Ambiancerating'] : 0;
                                    $rating_5 = isset($feedbackData['Servicerating']) ? (int)$feedbackData['Servicerating'] : 0;
                                ?>
                                <div class="tab-inn">
                                    <div class="row">
                                        <div class="input-field col s6">
                                            <p>Software Performance </p>
                                            <div class="FoodQualitymain_star_custom">
                                                <?php
                                                    for ($i=1; $i <= 5; $i++) {
                                                        $classRating = "fa FoodQualitycustomstar fa-star FoodQuality_star_custom";
                                                        if($rating_1 < $i){
                                                            $classRating = "fa fa-star-o FoodQuality_star_custom";
                                                        }
                                                ?>
                                                    <i class="<?= $classRating;?>" FoodQualitydata-id="1"></i>
                                                <?php } ?>
                                                <span>(<b><?= $rating_1 ?></b> Out of <b>5</b>) <b> </b></span>
                                            </div>
                                        </div>
                                        <div class="input-field col s6">
                                            <p>Issue Resolution Time </p>
                                            <div class="FoodPresentationmain_star_custom">
                                                <?php
                                                    for ($i=1; $i <= 5; $i++) {
                                                        $classRating = "fa FoodQualitycustomstar fa-star FoodQuality_star_custom";
                                                        if($rating_2 < $i){
                                                            $classRating = "fa fa-star-o FoodQuality_star_custom";
                                                        }
                                                ?>
                                                    <i class="<?= $classRating;?>" FoodQualitydata-id="1"></i>
                                                <?php } ?>
                                                <span>(<b><?= $rating_2 ?></b> Out of <b>5</b>) <b> </b></span>
                                            </div>
                                        </div>
                                    </div>
                                    <hr>
                                    <div class="row">
                                        <div class="input-field col s6">
                                            <p>Support Response Time</p>
                                            <div class="Atmospheremain_star_custom">
                                                <?php
                                                    for ($i=1; $i <= 5; $i++) {
                                                        $classRating = "fa FoodQualitycustomstar fa-star FoodQuality_star_custom";
                                                        if($rating_3 < $i){
                                                            $classRating = "fa fa-star-o FoodQuality_star_custom";
                                                        }
                                                ?>
                                                    <i class="<?= $classRating;?>" FoodQualitydata-id="1"></i>
                                                <?php } ?>
                                                <span>(<b><?= $rating_3 ?></b> Out of <b>5</b>) <b> </b></span>
                                            </div>
                                        </div>
                                        <div class="input-field col s6">
                                            <p>Clarity of Communication </p>
                                            <div class="Ambiancemain_star_custom">
                                                <?php
                                                    for ($i=1; $i <= 5; $i++) {
                                                        $classRating = "fa FoodQualitycustomstar fa-star FoodQuality_star_custom";
                                                        if($rating_4 < $i){
                                                            $classRating = "fa fa-star-o FoodQuality_star_custom";
                                                        }
                                                ?>
                                                    <i class="<?= $classRating;?>" FoodQualitydata-id="1"></i>
                                                <?php } ?>
                                                <span>(<b><?= $rating_4 ?></b> Out of <b>5</b>) <b> </b></span>
                                            </div>
                                        </div>
                                    </div>
                                    <hr>
                                    <div class="row">
                                        <div class="input-field col s6">
                                            <p>Ease of Use</p>
                                            <div class="Servicemain_star_custom">
                                                <?php
                                                    for ($i=1; $i <= 5; $i++) {
                                                        $classRating = "fa FoodQualitycustomstar fa-star FoodQuality_star_custom";
                                                        if($rating_5 < $i){
                                                            $classRating = "fa fa-star-o FoodQuality_star_custom";
                                                        }
                                                ?>
                                                    <i class="<?= $classRating;?>" FoodQualitydata-id="1"></i>
                                                <?php } ?>
                                                <span>(<b><?= $rating_5 ?></b> Out of <b>5</b>) <b> </b></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
                    <div class="row">
                        <div class="col col-md-12 col-lg-12 col-sm-12">
                            <p style="color:#e8edf2 !important;">asasasasas</p>
                            <p style="color:#e8edf2 !important;">asasasasas</p>
                            <p style="color:#e8edf2 !important;">asasasasas</p>
                        </div>
                    </div>
    </div>
<?php include 'inc/footer.php';?>