<?php
// topbar.php

// Ensure that user data is available before trying to access it
if (isset($userData)) {
    // Access user data safely
    $username = $userData['UserName'];
    $fullName = $userData['UserName']; // Assuming this field exists in your table
} else {
    // Fallback if no user data is available
    $username = 'Guest';
    $fullName = 'Unknown User';
}

?>

<nav class="navbar top-navbar bg-white box-shadow">
    <div class="container-fluid">
        <div class="row">
            <div class="navbar-header no-padding">
                <a class="navbar-brand" href="admin.php">
                    MMSS | Admin
                </a>
                <span class="small-nav-handle hidden-sm hidden-xs"><i class="fa fa-outdent"></i></span>
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <i class="fa fa-ellipsis-v"></i>
                </button>
                <button type="button" class="navbar-toggle mobile-nav-toggle">
                    <i class="fa fa-bars"></i>
                </button>
            </div>

            <div class="collapse navbar-collapse" id="navbar-collapse-1">
                <ul class="nav navbar-nav" data-dropdown-in="fadeIn" data-dropdown-out="fadeOut">
                    <li class="hidden-sm hidden-xs">
                        <a href="#" class="user-info-handle">
                            <i class="fa fa-user"></i>
                            <span>Welcome, <?php echo htmlspecialchars($fullName); ?> (<?php echo htmlspecialchars($username); ?>)</span>
                        </a>
                    </li>
                    <li class="hidden-sm hidden-xs">
                        <a href="#" class="full-screen-handle"><i class="fa fa-arrows-alt"></i></a>
                    </li>
                </ul>

                <div class="col-sm-2">
                    <div class="navbar-custom-menu">
                        <ul class="nav navbar-nav">
                            <li class="dropdown user user-menu" style="background:#dbfc6f">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                    <i class="fa fa-calendar"></i> Date Converter
                                </a>
                                <ul class="dropdown-menu" style="width:300px;padding-left:5px;">
                                    <li>
                                        <iframe src="https://www.ashesh.com.np/linkdate-converter.php?h_color=21ADE2&amp;b_color=CFE4B1&amp;api=0930z5i583" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" style="border:none; overflow:hidden; width:98%; height:160px;" allowtransparency="true"></iframe>
                                        <br><span style="color:#6D6D6D; font-size:8px; text-align:left">Powered by © <a href="https://www.ashesh.com.np/nepali-date-converter.php" title="Nepali date converter" target="_top" style="text-decoration:none; color:#6D6D6D;">Nepali date converter</a></span>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
                <ul class="nav navbar-nav navbar-right" data-dropdown-in="fadeIn" data-dropdown-out="fadeOut">
                    <li><a href="logout.php" class="color-danger text-center"><i class="fa fa-sign-out"></i> Logout</a></li>
                </ul>
            </div>
        </div>
    </div>
</nav>
