
<?php
include("../db/cn.php");
ob_start();

if (isset($_SESSION['user_name']) && isset($_SESSION['user_role']) && isset($_SESSION['outlet_name']) && isset($_SESSION['outlet_address'])) {
    $userName = $_SESSION['user_name'];
    $userRole = $_SESSION['user_role'];
    $outlet_address = $_SESSION['outlet_address'];
    $outlet_name = $_SESSION['outlet_name'];
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Escape input data to prevent SQL injection
    $applicantName = mysqli_real_escape_string($connection, $_POST['applicantName']);
    $fatherName = mysqli_real_escape_string($connection, $_POST['fatherName']);
    @$idCard = mysqli_real_escape_string($connection, $_POST['idCard']);
    $dob = mysqli_real_escape_string($connection, $_POST['dob']);
    $maritalStatus = mysqli_real_escape_string($connection, $_POST['maritalStatus']);
    $address = mysqli_real_escape_string($connection, $_POST['address']);
   @$relationship = mysqli_real_escape_string($connection, $_POST['relationship']);
    $occupation = mysqli_real_escape_string($connection, $_POST['occupation']);
    $monthlyIncome = mysqli_real_escape_string($connection, $_POST['monthlyIncome']);
    $prevAccountNumber = mysqli_real_escape_string($connection, $_POST['prevAccountNumber']);
    @$rentedBefore = mysqli_real_escape_string($connection, $_POST['rentedBefore']);
    @$previousRentedItem = mysqli_real_escape_string($connection, $_POST['previousRentedItem']);
    $priceDetermination = mysqli_real_escape_string($connection, $_POST['priceDetermination']);
    $guarantor1Name = mysqli_real_escape_string($connection, $_POST['guarantor1Name']);
    $guarantor1FatherName = mysqli_real_escape_string($connection, $_POST['guarantor1FatherName']);
    $guarantor1IdCard = mysqli_real_escape_string($connection, $_POST['guarantor1IdCard']);
    $guarantor1Dob = mysqli_real_escape_string($connection, $_POST['guarantor1Dob']);
    $guarantor1Address = mysqli_real_escape_string($connection, $_POST['guarantor1Address']);
    $guarantor1MaritalStatus = mysqli_real_escape_string($connection, $_POST['guarantor1MaritalStatus']);
    $guarantor1Relationship = mysqli_real_escape_string($connection, $_POST['guarantor1Relationship']);
    $guarantor1Occupation = mysqli_real_escape_string($connection, $_POST['guarantor1Occupation']);
    $guarantor1MonthlyIncome = mysqli_real_escape_string($connection, $_POST['guarantor1MonthlyIncome']);
    $guarantor1PrevAccountNumber = mysqli_real_escape_string($connection, $_POST['guarantor1PrevAccountNumber']);
    $guarantor2Name = mysqli_real_escape_string($connection, $_POST['guarantor2Name']);
    $guarantor2FatherName = mysqli_real_escape_string($connection, $_POST['guarantor2FatherName']);
    $guarantor2IdCard = mysqli_real_escape_string($connection, $_POST['guarantor2IdCard']);
    $guarantor2Dob = mysqli_real_escape_string($connection, $_POST['guarantor2Dob']);
    $guarantor2Address = mysqli_real_escape_string($connection, $_POST['guarantor2Address']);
    $guarantor2MaritalStatus = mysqli_real_escape_string($connection, $_POST['guarantor2MaritalStatus']);
    $guarantor2Relationship = mysqli_real_escape_string($connection, $_POST['guarantor2Relationship']);
    $guarantor2Occupation = mysqli_real_escape_string($connection, $_POST['guarantor2Occupation']);
    $guarantor2MonthlyIncome = mysqli_real_escape_string($connection, $_POST['guarantor2MonthlyIncome']);
    $guarantor2PrevAccountNumber = mysqli_real_escape_string($connection, $_POST['guarantor2PrevAccountNumber']);
    
    // Handle file uploads
    $signature = $_FILES['signature']['name'];
    $guarantorSignature1 = $_FILES['guarantorSignature1']['name'];
    $guarantorSignature2 = $_FILES['guarantorSignature2']['name'];

    // Move uploaded files
    move_uploaded_file($_FILES['signature']['tmp_name'], "uploads/" . $signature);
    move_uploaded_file($_FILES['guarantorSignature1']['tmp_name'], "uploads/" . $guarantorSignature1);
    move_uploaded_file($_FILES['guarantorSignature2']['tmp_name'], "uploads/" . $guarantorSignature2);

    // Prepare the SQL query
    $sql = "INSERT INTO lease (
        name, father_name, id_card, dob, marital_status, address, relationship, occupation, monthly_income, 
        prev_account_number, rented_before, previous_rented_item, price_determination, guarantor1_name, 
        guarantor1_father_name, guarantor1_id_card, guarantor1_dob, guarantor1_address, guarantor1_marital_status, 
        guarantor1_relationship, guarantor1_occupation, guarantor1_monthly_income, guarantor1_prev_account_number, 
        guarantor2_name, guarantor2_father_name, guarantor2_id_card, guarantor2_dob, guarantor2_address, 
        guarantor2_marital_status, guarantor2_relationship, guarantor2_occupation, guarantor2_monthly_income, 
        guarantor2_prev_account_number, signature, guarantor_signature1, guarantor_signature2
    ) VALUES (
        '$applicantName', '$fatherName', '$idCard', '$dob', '$maritalStatus', '$address', '$relationship', '$occupation', '$monthlyIncome', 
        '$prevAccountNumber', '$rentedBefore', '$previousRentedItem', '$priceDetermination', '$guarantor1Name', 
        '$guarantor1FatherName', '$guarantor1IdCard', '$guarantor1Dob', '$guarantor1Address', '$guarantor1MaritalStatus', 
        '$guarantor1Relationship', '$guarantor1Occupation', '$guarantor1MonthlyIncome', '$guarantor1PrevAccountNumber', 
        '$guarantor2Name', '$guarantor2FatherName', '$guarantor2IdCard', '$guarantor2Dob', '$guarantor2Address', 
        '$guarantor2MaritalStatus', '$guarantor2Relationship', '$guarantor2Occupation', '$guarantor2MonthlyIncome', 
        '$guarantor2PrevAccountNumber', '$signature', '$guarantorSignature1', '$guarantorSignature2'
    )";

    // Execute the query
    if (mysqli_query($connection, $sql)) {
        echo "New record created successfully";
    } else {
        echo "Error: " . mysqli_error($connection);
    }
}

$connection->close();

ob_end_flush();
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Lease Form</title>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="css/custom_css.css" />
  
</head>

<style>
 #product-container-wrapper {
    max-height: 900px; /* Adjust the maximum height as needed */
    overflow-y: auto; /* Enable vertical scroll when content overflows */
}
/* Custom styles for sidebar */
 #table-container-wrapper {
    max-height: 500px; /* Adjust the maximum height as needed */
    overflow-y: auto; /* Enable vertical scroll when content overflows */
}
@media (max-width: 880px) {
    .col-4 {
        width: 33.33% !important;
    }
    .fa-wifi {
        display: none !important;
    }
    .col-6 {
        width: 50% !important;
    }
}

@media (min-width: 880px) {
    .sidebar {
        width: 100%;
        /* Change sidebar width to 100% on mobile */
        max-width: 120px; /* Set maximum width for the sidebar */
    }
}

@media (min-width: 880px) {
    .main-content {
        margin-left: ; /* Width of the sidebar */
    }
}

/* Added new class to control overlay */
.overlay {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 999;
    display: none; /* Initially hidden */
}   
    .sidebar {
        width: 100px;
        background: linear-gradient(360deg, #060606, #0A5064);
        position: fixed;
        bottom: 0;
        top: 60px;
        transition: transform 0.3s ease-in-out;
        transform: translateX(0);
        z-index: 1;
        height: 100%;
        border-radius: 0px;
		   transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
    }
    .sidebar.hide {
        transform: translateX(-100px);
        /* Move sidebar out of the viewport when it is hidden */
    }

    .sidebar .nav-item {
        padding: 10px 0;
        text-align: center;
        position: relative;
        font-size: 12px;
    }

    .sidebar .nav-link {
        color: #fff;
        position: relative;
        /* Ensure icon and text are positioned relative to the nav link */
        z-index: 2;
        /* Ensure the text and icon are above the hover background */
    }

    .sidebar .nav-link i {
        margin-bottom: 5px;
        /* Adjust the margin of the icon */
    }

    /* Custom styles for hover effect */
    .sidebar .nav-item:hover:after {
        background-color: #fff;
        content: '';
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
        /* Ensure the hover background is below the text and icon */
    }

    .sidebar .nav-item:hover .nav-link {
        color: #2E236C;
    }

    /* Custom styles for divider */
    .sidebar .nav-item:after {
        content: "";
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 1px;
        background-color: #fff;
        transition: height 0.3s ease-in-out;
        /* Transition effect for smooth animation */
    }    /* Custom styles for header 
	background: linear-gradient(270deg, #060606, #597445);
	*/
  /* Custom styles for header */
    .header {
        background: linear-gradient(270deg, #060606, #0A5064);
        color: #fff;
        padding: 10px;
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 2;
        height: 69px;
        box-shadow: #FFF 2px 0px 0px 0px;
        /* Ensure header appears above sidebar */
    }

    .header .navbar-toggler {
        color: #fff;
    }

    .header .navbar-toggler-icon {
        color: #fff;
        /* Set the color of the toggle button to white */
    }

    .header .navbar-toggler.white {
        color: #fff !important;
        /* Ensure the toggle button is white */
    }

    .header .navbar-brand {
        color: #fff;
        /* Set navbar brand text color to white */
    }

    .header .nav-item .nav-link {
        color: #fff;
        /* Set nav link text color to white */
    }

.main-content {
    margin-top: 50px; /* Height of fixed header */
    margin-left: 100px; /* Initially, set margin-left to 0 */
    padding-top: 30px; /* Height of fixed header */
    transition: margin-left 0.3s ease-in-out; /* Add transition for smoother animation */
}


    /* Custom styles for search bar */
    .search-container {
        display: flex;
        align-items: center;
       width:100%;
        margin: 2px auto;
        float:left;
	}

/* Updated hide class to apply to the overlay */
.sidebar.hide, .overlay.hide {
    transform: translateX(-100%);
}

    .search-input {
        width: 100%;
        padding: 10px 30px 10px 10px;
        /* Adjust padding to accommodate the icon */
        border: 1px solid #ccc;
        border-radius: 20px;
        font-size: 16px;
    }

    .search-icon {
        position: relative;
        left: -25px;
        /* Adjust the position of the icon */
        color: #aaa;
    }

    .search-icon i {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
    }      
	  .btn-dark {
        background: #0A5064;
        color: #fff;
        border: 1px solid #0A5064;
    }

    .btn-dark:hover {
        background: #fff;
        color: #0A5064;
        border: 1px solid #0A5064;
    }

    .bg-dark2 {
        background: #8A1218;
        color: #fff;
    }

    .modal-content {
        animation: modal-animation 0.5s;
    }

    @keyframes modal-animation {
        from {
            opacity: 0;
            transform: scale(0.8);
        }

        to {
            opacity: 1;
            transform: scale(1);
        }
    }

	
		
		        #searchResults {
            position: absolute;
            background-color: #f9f9f9;
            border: 1px solid #ddd;
            max-height: 200px;
            overflow-y: auto;
            width: 85%;
            display: none;
        }
        #searchResults div {
            padding: 10px;
            cursor: pointer;
        }
        #searchResults div:hover {
            background-color: #f1f1f1;
        }
</style>

<body>

<?php
if(isset($msg)){
	
	echo $msg;
	}
?>
<?php include("common/hd.php"); ?>
<!-- Sidebar -->
<?php include("common/sd.php"); ?>
<div class="main-content">
<div class="container">
<div class="row">
<div class="col-sm-7">
<h3 style="color:#212529;">Lease Form</h3>

</div>
<div class="col-sm-5">
<button type="button" class="btn btn-dark btn-lg" style="float:right;"><i class="fa fa-arrow-left fa-1x"></i></button>


</div>
</div>

</div>
<div class="contanier">
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-10" >
<div class="container ">
        <form method="post" action="lease.php" enctype="multipart/form-data">
            <div class="row mb-3">
                <div class="col-sm-4">
                    <label for="date" class="form-label">Date</label>
                    <input type="date" class="form-control" id="date" name="date">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="applicantName" class="form-label">Applicant's Name</label>
                    <input type="text" class="form-control" id="applicantName" name="applicantName">
                </div>
                <div class="col">
                    <label for="fatherName" class="form-label">Father/Husband's Name</label>
                    <input type="text" class="form-control" id="fatherName" name="fatherName">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="address" class="form-label">Current Residential Address</label>
                    <input type="text" class="form-control" id="address" name="address">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="maritalStatus" class="form-label">Marital Status</label>
                    <select class="form-control" id="maritalStatus" name="maritalStatus">
                        <option value="married">Married</option>
                        <option value="unmarried">Unmarried</option>
                    </select>
                </div>
                <div class="col">
                    <label for="dob" class="form-label">Date of Birth</label>
                    <input type="date" class="form-control" id="dob" name="dob">
                </div>
            </div>

            <div class="row mb-3">
                <div class="col">
                    <label for="position" class="form-label">Position</label>
                    <input type="text" class="form-control" id="position" name="position">
                </div>
                <div class="col">
                    <label for="phone" class="form-label">Phone Number</label>
                    <input type="tel" class="form-control" id="phone" name="phone">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="businessAddress" class="form-label">Current Business Address</label>
                    <input type="text" class="form-control" id="businessAddress" name="businessAddress">
                </div>
                <div class="col">
                    <label for="positionDuration" class="form-label">Duration</label>
                    <input type="text" class="form-control" id="positionDuration" name="positionDuration">
                </div>
                <div class="col">
                    <label for="businessPhone" class="form-label">Phone Number</label>
                    <input type="tel" class="form-control" id="businessPhone" name="businessPhone">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="occupation" class="form-label">Occupation</label>
                    <input type="text" class="form-control" id="occupation" name="occupation">
                </div>
                <div class="col">
                    <label for="monthlyIncome" class="form-label">Monthly Income</label>
                    <input type="number" class="form-control" id="monthlyIncome" name="monthlyIncome">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="prevAccountNumber" class="form-label">Previous Account Number</label>
                    <input type="text" class="form-control" id="prevAccountNumber" name="prevAccountNumber">
                </div>
            </div>
            
            <div class="mb-3">
                <label for="serviceCharges" class="form-label">Service Charges</label>
                <input type="text" class="form-control" id="serviceCharges" name="serviceCharges">
            </div>
            
            <div class="mb-3">
                <label for="rentedBefore" class="form-label">Have you previously rented any items?</label>
                <div class="form-check">
                    <input class="form-check-input" type="radio" name="rentedBefore" id="rentedYes" value="yes">
                    <label class="form-check-label" for="rentedYes">Yes</label>
                </div>
                <div class="form-check">
                    <input class="form-check-input" type="radio" name="rentedBefore" id="rentedNo" value="no">
                    <label class="form-check-label" for="rentedNo">No</label>
                </div>
            </div>
            
            <!-- Additional fields for rental items if 'Yes' is selected -->
            <div id="rentalDetails" class="d-none">
                <div class="row mb-3">
                    <div class="col">
                        <label for="rentalItems" class="form-label">Name of Rented Items</label>
                        <input type="text" class="form-control" id="rentalItems" name="rentalItems">
                    </div>
                    <div class="col">
                        <label for="modelNumber" class="form-label">Model Number</label>
                        <input type="text" class="form-control" id="modelNumber" name="modelNumber">
                    </div>
                </div>
                
                <div class="row mb-3">
                    <div class="col">
                        <label for="firstMonthRent" class="form-label">First Month's Rent</label>
                        <input type="number" class="form-control" id="firstMonthRent" name="firstMonthRent">
                    </div>
                    <div class="col">
                        <label for="priceDetermination" class="form-label">Price Determination</label>
                        <input type="text" class="form-control" id="priceDetermination" name="priceDetermination">
                    </div>
                </div>
            </div>
            
            <!-- Guarantor 1 -->
            <h5 style="background:#0A5064; padding:20px; border-radius:10px;color:#fff;">Guarantor No. 1</h5>
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor1Name" class="form-label">Name</label>
                    <input type="text" class="form-control" id="guarantor1Name" name="guarantor1Name">
                </div>
                <div class="col">
                    <label for="guarantor1FatherName" class="form-label">Father/Husband's Name</label>
                    <input type="text" class="form-control" id="guarantor1FatherName" name="guarantor1FatherName">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor1IdCard" class="form-label">ID Card Number</label>
                    <input type="text" class="form-control" id="guarantor1IdCard" name="guarantor1IdCard">
                </div>
                <div class="col">
                    <label for="guarantor1Dob" class="form-label">Date of Birth</label>
                    <input type="date" class="form-control" id="guarantor1Dob" name="guarantor1Dob">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor1Address" class="form-label">Current Residential Address</label>
                    <input type="text" class="form-control" id="guarantor1Address" name="guarantor1Address">
                </div>
                <div class="col">
                    <label for="guarantor1MaritalStatus" class="form-label">Marital Status</label>
                    <select class="form-control" id="guarantor1MaritalStatus" name="guarantor1MaritalStatus">
                        <option value="married">Married</option>
                        <option value="unmarried">Unmarried</option>
                    </select>
                </div>
            </div>
            
            <div class="mb-3">
                <label for="guarantor1Relationship" class="form-label">Relationship</label>
                <input type="text" class="form-control" id="guarantor1Relationship" name="guarantor1Relationship">
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor1Occupation" class="form-label">Occupation</label>
                    <input type="text" class="form-control" id="guarantor1Occupation" name="guarantor1Occupation">
                </div>
                <div class="col">
                    <label for="guarantor1MonthlyIncome" class="form-label">Monthly Income</label>
                    <input type="number" class="form-control" id="guarantor1MonthlyIncome" name="guarantor1MonthlyIncome">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor1PrevAccountNumber" class="form-label">Previous Account Number</label>
                    <input type="text" class="form-control" id="guarantor1PrevAccountNumber" name="guarantor1PrevAccountNumber">
                </div>
            </div>
            
            <!-- Guarantor 2 -->
            <h5 style="background:#0A5064; padding:20px; border-radius:10px;color:#fff;">Guarantor No. 2</h5>
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor2Name" class="form-label">Name</label>
                    <input type="text" class="form-control" id="guarantor2Name" name="guarantor2Name">
                </div>
                <div class="col">
                    <label for="guarantor2FatherName" class="form-label">Father/Husband's Name</label>
                    <input type="text" class="form-control" id="guarantor2FatherName" name="guarantor2FatherName">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor2IdCard" class="form-label">ID Card Number</label>
                    <input type="text" class="form-control" id="guarantor2IdCard" name="guarantor2IdCard">
                </div>
                <div class="col">
                    <label for="guarantor2Dob" class="form-label">Date of Birth</label>
                    <input type="date" class="form-control" id="guarantor2Dob" name="guarantor2Dob">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor2Address" class="form-label">Current Residential Address</label>
                    <input type="text" class="form-control" id="guarantor2Address" name="guarantor2Address">
                </div>
                <div class="col">
                    <label for="guarantor2MaritalStatus" class="form-label">Marital Status</label>
                    <select class="form-control" id="guarantor2MaritalStatus" name="guarantor2MaritalStatus">
                        <option value="married">Married</option>
                        <option value="unmarried">Unmarried</option>
                    </select>
                </div>
            </div>
            
            <div class="mb-3">
                <label for="guarantor2Relationship" class="form-label">Relationship</label>
                <input type="text" class="form-control" id="guarantor2Relationship" name="guarantor2Relationship">
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor2Occupation" class="form-label">Occupation</label>
                    <input type="text" class="form-control" id="guarantor2Occupation" name="guarantor2Occupation">
                </div>
                <div class="col">
                    <label for="guarantor2MonthlyIncome" class="form-label">Monthly Income</label>
                    <input type="number" class="form-control" id="guarantor2MonthlyIncome" name="guarantor2MonthlyIncome">
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col">
                    <label for="guarantor2PrevAccountNumber" class="form-label">Previous Account Number</label>
                    <input type="text" class="form-control" id="guarantor2PrevAccountNumber" name="guarantor2PrevAccountNumber">
                </div>
            </div>
            
            <!-- Signature -->
            <div class="mb-3">
                <label for="signature" class="form-label">Thumb Impression & Signature of Applicant</label>
                <input type="file" class="form-control" id="signature" name="signature">
            </div>
            
            <div class="mb-3">
                <label for="guarantorSignature1" class="form-label">Guarantor 1 - Thumb Impression & Signature</label>
                <input type="file" class="form-control" id="guarantorSignature1" name="guarantorSignature1">
            </div>
            
            <div class="mb-3">
                <label for="guarantorSignature2" class="form-label">Guarantor 2 - Thumb Impression & Signature</label>
                <input type="file" class="form-control" id="guarantorSignature2" name="guarantorSignature2">
            </div>
            
            <button type="submit" class="btn btn-dark">Submit</button>
        </form>
    </div>

</div>
<div class="col-sm-1"></div>
</div>
</div>


    
    
    
</div>    
</body>
 <script>
 
document.addEventListener("DOMContentLoaded", function () {
    var sidebar = document.getElementById("sidebar");
    var overlay = document.createElement("div");
    overlay.classList.add("overlay");
    document.body.appendChild(overlay);

    function toggleSidebar() {
        sidebar.classList.toggle("hide");
        overlay.classList.toggle("hide");

        var mainContent = document.querySelector(".main-content");
        if (sidebar.classList.contains("hide")) {
            mainContent.style.marginLeft = "0";
        } else {
            mainContent.style.marginLeft = "100px"; // Width of the sidebar
        }
    }

    overlay.addEventListener("click", function () {
        toggleSidebar();
    });

    // Add toggle functionality to navbar toggler
    var navbarToggler = document.querySelector(".navbar-toggler");
    navbarToggler.addEventListener("click", function () {
        toggleSidebar();
    });

    // Automatically hide sidebar on all screen sizes
    // sidebar.classList.add("hide");
    // overlay.classList.add("hide");
    
    // Add class to body to prevent scrolling when sidebar is open
    // document.body.classList.add("noscroll");

    // Check if screen size is larger than a certain threshold (e.g., 768px for desktop screens)
    function checkScreenSize() {
        if (window.innerWidth > 768) {
            sidebar.classList.remove("hide");
            overlay.classList.remove("hide");
        } else {
            sidebar.classList.add("hide");
            overlay.classList.add("hide");
        }
    }

    // Check screen size on initial load and whenever the window is resized
    checkScreenSize();
    window.addEventListener("resize", checkScreenSize);
});
 
 
document.addEventListener("DOMContentLoaded", function () {
    const products = document.querySelectorAll('.product-row');
    let currentIndex = -1;

    // Function to handle up and down arrow keys
    document.addEventListener("keydown", function(event) {
        if (event.key === "ArrowDown" || event.key === "ArrowUp") {
            event.preventDefault();
            if (currentIndex === -1) {
                currentIndex = 0;
            } else {
                currentIndex += event.key === "ArrowDown" ? 1 : -1;
            }
            if (currentIndex < 0) currentIndex = 0;
            if (currentIndex >= products.length) currentIndex = products.length - 1;
            products[currentIndex].focus();
            products[currentIndex].scrollIntoView({ behavior: 'smooth', block: 'center' });
        }
    });

    // Set tabindex and index for each row
    products.forEach((row, index) => {
        row.setAttribute('tabindex', '0');
        row.dataset.index = index;
        row.addEventListener('focus', function() {
            currentIndex = parseInt(row.dataset.index);
        });
    });
});
document.addEventListener("DOMContentLoaded", function () {
    const categories = <?php echo json_encode($categories); ?>;
    const searchInput = document.getElementById('searchInput');
    const searchResults = document.getElementById('searchResults');
    const products = document.querySelectorAll('.product-row');

    searchInput.addEventListener('input', function () {
        const query = this.value.trim().toLowerCase();
        if (query === '') {
            searchResults.style.display = 'none';
            showAllProducts();
            return;
        }
        const filteredCategories = categories.filter(category => category.toLowerCase().includes(query));
        renderResults(filteredCategories);
        filterProducts(filteredCategories);
    });

    searchInput.addEventListener('blur', function () {
        setTimeout(() => {
            searchResults.style.display = 'none';
        }, 200); // Delay hiding dropdown to allow click event on dropdown items
    });

    function renderResults(results) {
        let html = '';
        results.forEach(result => {
            html += `<div>${result}</div>`;
        });
        searchResults.innerHTML = html;
        searchResults.style.display = 'block';
    }

    function filterProducts(filteredCategories) {
        products.forEach(function (product) {
            const category = product.getAttribute('data-category');
            if (!filteredCategories.includes(category)) {
                product.style.display = 'none';
            } else {
                product.style.display = 'table-row';
            }
        });
    }

    function showAllProducts() {
        products.forEach(function (product) {
            product.style.display = 'table-row';
        });
    }

    searchResults.addEventListener('click', function (event) {
        const clickedItem = event.target;
        if (clickedItem.tagName === 'DIV') {
            searchInput.value = clickedItem.innerText;
            searchResults.style.display = 'none';
            filterProducts([clickedItem.innerText]);
        }
    });
});
 
 document.addEventListener("DOMContentLoaded", function() {
    document.getElementById("search-input").addEventListener("input", function() {
        var searchText = this.value.toLowerCase();
        var rows = document.querySelectorAll(".product-row");

        rows.forEach(function(row) {
            var productName = row.querySelector("td:nth-child(3)").textContent.toLowerCase();
            if (productName.includes(searchText)) {
                row.style.display = "table-row";
            } else {
                row.style.display = "none";
            }
        });
    });
});



   
    // Function to toggle submenu
    function toggleSubMenu(element) {
        $(element).next('.sub-menu').slideToggle();
    }
</script>

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

</html>