<?php
include('../../routes/db_conn.php');

$product_id = $_GET['id']; // Fetching product ID from URL parameter

// SQL query to fetch product details
$sql = "SELECT * FROM barang WHERE id_barang = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $product_id); // Bind product_id as integer
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $product = $result->fetch_assoc();
} else {
    echo "Product not found.";
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <meta name="description" content="POS - Bootstrap Admin Template">
    <meta name="keywords"
        content="admin, estimates, bootstrap, business, corporate, creative, invoice, html5, responsive, Projects">
    <meta name="author" content="Dreamguys - Bootstrap Admin Template">
    <meta name="robots" content="noindex, nofollow">
    <title>Dreams Pos admin template</title>

    <link rel="shortcut icon" type="image/x-icon" href="/ayula-store/bootstrap/assets/img/favicon.jpg">

    <link rel="stylesheet" href="/ayula-store/bootstrap/assets/css/bootstrap.min.css">

    <link rel="stylesheet" href="/ayula-store/bootstrap/assets/css/animate.css">

    <link rel="stylesheet" href="/ayula-store/bootstrap/assets/plugins/select2/css/select2.min.css">

    <link rel="stylesheet" href="/ayula-store/bootstrap/assets/plugins/owlcarousel/owl.carousel.min.css">

    <link rel="stylesheet" href="/ayula-store/bootstrap/assets/css/dataTables.bootstrap4.min.css">

    <link rel="stylesheet" href="/ayula-store/bootstrap/assets/plugins/fontawesome/css/fontawesome.min.css">
    <link rel="stylesheet" href="/ayula-store/bootstrap/assets/plugins/fontawesome/css/all.min.css">

    <link rel="stylesheet" href="/ayula-store/bootstrap/assets/css/style.css">
    
    <!-- Add JsBarcode library -->
    <script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js"></script>
    
    <style>
        .barcode-container {
            text-align: center;
            margin-bottom: 20px;
        }
        .barcode-label {
            display: block;
            font-size: 14px;
            margin-top: 5px;
            font-weight: bold;
        }
        .barcode-print-btn {
            margin-top: 10px;
            display: inline-block;
            background-color: #ff9f43;
            color: white;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }
        .barcode-print-btn:hover {
            background-color: #ff8a1e;
            color: white;
        }
        .barcode-print-btn i {
            margin-right: 5px;
        }
        @media print {
            body * {
                visibility: hidden;
            }
            .barcode-print-section, .barcode-print-section * {
                visibility: visible;
            }
            .barcode-print-section {
                position: absolute;
                left: 0;
                top: 0;
                width: 100%;
            }
            .barcode-print-btn {
                display: none;
            }
        }
    </style>
</head>

<body>
    <div id="global-loader">
        <div class="whirly-loader"> </div>
    </div>

    <div class="main-wrapper">

        <div class="header">

            <div class="header-left active">
                <a href="index.html" class="logo">
                    <img src="/ayula-store/bootstrap/assets/img/logo.png" alt="">
                </a>
                <a href="index.html" class="logo-small">
                    <img src="/ayula-store/bootstrap/assets/img/logo-small.png" alt="">
                </a>
                <a id="toggle_btn" href="javascript:void(0);">
                </a>
            </div>

            <a id="mobile_btn" class="mobile_btn" href="#sidebar">
                <span class="bar-icon">
                    <span></span>
                    <span></span>
                    <span></span>
                </span>
            </a>

            <ul class="nav user-menu">

                <li class="nav-item">
                    <div class="top-nav-search">
                        <a href="javascript:void(0);" class="responsive-search">
                            <i class="fa fa-search"></i>
                        </a>
                        <form action="#">
                            <div class="searchinputs">
                                <input type="text" placeholder="Search Here ...">
                                <div class="search-addon">
                                    <span><img src="/ayula-store/bootstrap/assets/img/icons/closes.svg"
                                            alt="img"></span>
                                </div>
                            </div>
                            <a class="btn" id="searchdiv"><img src="/ayula-store/bootstrap/assets/img/icons/search.svg"
                                    alt="img"></a>
                        </form>
                    </div>
                </li>


                <li class="nav-item dropdown has-arrow flag-nav">
                    <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="javascript:void(0);"
                        role="button">
                        <img src="/ayula-store/bootstrap/assets/img/flags/us1.png" alt="" height="20">
                    </a>
                    <div class="dropdown-menu dropdown-menu-right">
                        <a href="javascript:void(0);" class="dropdown-item">
                            <img src="/ayula-store/bootstrap/assets/img/flags/us.png" alt="" height="16"> English
                        </a>
                        <a href="javascript:void(0);" class="dropdown-item">
                            <img src="/ayula-store/bootstrap/assets/img/flags/fr.png" alt="" height="16"> French
                        </a>
                        <a href="javascript:void(0);" class="dropdown-item">
                            <img src="/ayula-store/bootstrap/assets/img/flags/es.png" alt="" height="16"> Spanish
                        </a>
                        <a href="javascript:void(0);" class="dropdown-item">
                            <img src="/ayula-store/bootstrap/assets/img/flags/de.png" alt="" height="16"> German
                        </a>
                    </div>
                </li>


                <li class="nav-item dropdown">
                    <a href="javascript:void(0);" class="dropdown-toggle nav-link" data-bs-toggle="dropdown">
                        <img src="/ayula-store/bootstrap/assets/img/icons/notification-bing.svg" alt="img"> <span
                            class="badge rounded-pill">4</span>
                    </a>
                    <div class="dropdown-menu notifications">
                        <div class="topnav-dropdown-header">
                            <span class="notification-title">Notifications</span>
                            <a href="javascript:void(0)" class="clear-noti"> Clear All </a>
                        </div>
                        <div class="noti-content">
                            <ul class="notification-list">
                                <li class="notification-message">
                                    <a href="activities.html">
                                        <div class="media d-flex">
                                            <span class="avatar flex-shrink-0">
                                                <img alt=""
                                                    src="/ayula-store/bootstrap/assets/img/profiles/avatar-02.jpg">
                                            </span>
                                            <div class="media-body flex-grow-1">
                                                <p class="noti-details"><span class="noti-title">John Doe</span> added
                                                    new task <span class="noti-title">Patient appointment booking</span>
                                                </p>
                                                <p class="noti-time"><span class="notification-time">4 mins ago</span>
                                                </p>
                                            </div>
                                        </div>
                                    </a>
                                </li>
                                <li class="notification-message">
                                    <a href="activities.html">
                                        <div class="media d-flex">
                                            <span class="avatar flex-shrink-0">
                                                <img alt=""
                                                    src="/ayula-store/bootstrap/assets/img/profiles/avatar-03.jpg">
                                            </span>
                                            <div class="media-body flex-grow-1">
                                                <p class="noti-details"><span class="noti-title">Tarah Shropshire</span>
                                                    changed the task name <span class="noti-title">Appointment booking
                                                        with payment gateway</span></p>
                                                <p class="noti-time"><span class="notification-time">6 mins ago</span>
                                                </p>
                                            </div>
                                        </div>
                                    </a>
                                </li>
                                <li class="notification-message">
                                    <a href="activities.html">
                                        <div class="media d-flex">
                                            <span class="avatar flex-shrink-0">
                                                <img alt=""
                                                    src="/ayula-store/bootstrap/assets/img/profiles/avatar-06.jpg">
                                            </span>
                                            <div class="media-body flex-grow-1">
                                                <p class="noti-details"><span class="noti-title">Misty Tison</span>
                                                    added <span class="noti-title">Domenic Houston</span> and <span
                                                        class="noti-title">Claire Mapes</span> to project <span
                                                        class="noti-title">Doctor available module</span></p>
                                                <p class="noti-time"><span class="notification-time">8 mins ago</span>
                                                </p>
                                            </div>
                                        </div>
                                    </a>
                                </li>
                                <!-- Other notification items -->
                            </ul>
                        </div>
                        <div class="topnav-dropdown-footer">
                            <a href="activities.html">View all Notifications</a>
                        </div>
                    </div>
                </li>

                <li class="nav-item dropdown has-arrow main-drop">
                    <a href="javascript:void(0);" class="dropdown-toggle nav-link userset" data-bs-toggle="dropdown">
                        <span class="user-img"><img src="/ayula-store/bootstrap/assets/img/profiles/avator1.jpg" alt="">
                            <span class="status online"></span></span>
                    </a>
                    <div class="dropdown-menu menu-drop-user">
                        <div class="profilename">
                            <div class="profileset">
                                <span class="user-img"><img src="/ayula-store/bootstrap/assets/img/profiles/avator1.jpg"
                                        alt="">
                                    <span class="status online"></span></span>
                                <div class="profilesets">
                                    <h6>John Doe</h6>
                                    <h5>Admin</h5>
                                </div>
                            </div>
                            <hr class="m-0">
                            <a class="dropdown-item" href="profile.html"> <i class="me-2" data-feather="user"></i> My
                                Profile</a>
                            <a class="dropdown-item" href="generalsettings.html"><i class="me-2"
                                    data-feather="settings"></i>Settings</a>
                            <hr class="m-0">
                            <a class="dropdown-item logout pb-0" href="signin.html"><img
                                    src="/ayula-store/bootstrap/assets/img/icons/log-out.svg" class="me-2"
                                    alt="img">Logout</a>
                        </div>
                    </div>
                </li>
            </ul>


            <div class="dropdown mobile-user-menu">
                <a href="javascript:void(0);" class="nav-link dropdown-toggle" data-bs-toggle="dropdown"
                    aria-expanded="false"><i class="fa fa-ellipsis-v"></i></a>
                <div class="dropdown-menu dropdown-menu-right">
                    <a class="dropdown-item" href="profile.html">My Profile</a>
                    <a class="dropdown-item" href="generalsettings.html">Settings</a>
                    <a class="dropdown-item" href="signin.html">Logout</a>
                </div>
            </div>

        </div>


        <div class="sidebar" id="sidebar">
            <div class="sidebar-inner slimscroll">
                <div id="sidebar-menu" class="sidebar-menu">
                    <ul>
                        <li>
                            <a href="/ayula-store/views/dashboard/"><img src="../../bootstrap/assets/img/icons/dashboard.svg" alt="img" /><span>
                                    Dashboard</span>
                            </a>
                        </li>
                        <li class="submenu">
                            <a href="javascript:void(0);"><img src="../../bootstrap/assets/img/icons/product.svg" alt="img" /><span>
                                    Product</span>
                                <span class="menu-arrow"></span></a>
                            <ul>
                                <li><a href="/ayula-store/views/barang/productlist.php">Product List</a></li>
                                <li><a href="/ayula-store/views/barang/addproduct.php">Add Product</a></li>
                                <li><a href="categorylist.html">Category List</a></li>
                                <li><a href="addcategory.html">Add Category</a></li>
                            </ul>
                        </li>
                        <!-- Other menu items -->
                    </ul>
                </div>
            </div>
        </div>

        <div class="page-wrapper">
        <div class="content">
            <div class="page-header">
                <div class="page-title">
                    <h4>Product Details</h4>
                    <h6>Full details of a product</h6>
                </div>
            </div>

            <div class="row">
                <div class="col-lg-8 col-sm-12">
                    <div class="card">
                        <div class="card-body">
                            <!-- Barcode Section -->
                            <div class="barcode-container barcode-print-section">
                                <svg id="barcode"></svg>
                                <span class="barcode-label"><?php echo isset($product['kode_barang']) ? $product['kode_barang'] : 'No Product Code'; ?></span>
                                <a href="javascript:void(0);" class="barcode-print-btn" onclick="printBarcode()">
                                    <i class="fa fa-print"></i> Print Barcode
                                </a>
                            </div>
                            
                            <div class="productdetails">
                                <ul class="product-bar">
                                    <li>
                                        <h4>Product</h4>
                                        <h6><?php echo isset($product['nama_barang']) ? $product['nama_barang'] : ''; ?></h6>
                                    </li>
                                    <li>
                                        <h4>Product Code</h4>
                                        <h6><?php echo isset($product['kode_barang']) ? $product['kode_barang'] : ''; ?></h6>
                                    </li>
                                    <li>
                                        <h4>Brand</h4>
                                        <h6><?php echo isset($product['brand']) ? $product['brand'] : ''; ?></h6>
                                    </li>
                                    <li>
                                        <h4>Unit</h4>
                                        <h6>Piece</h6>
                                    </li>
                                    <li>
                                        <h4>SKU</h4>
                                        <h6><?php echo isset($product['id_barang']) ? $product['id_barang'] : ''; ?></h6>
                                    </li>
                                    <li>
                                        <h4>Minimum Qty</h4>
                                        <h6>5</h6>
                                    </li>
                                    <li>
                                        <h4>Quantity</h4>
                                        <h6><?php echo isset($product['stok']) ? $product['stok'] : '0'; ?></h6>
                                    </li>
                                    <li>
                                        <h4>Price</h4>
                                        <h6>Rp <?php echo isset($product['harga']) ? number_format($product['harga'], 0, ',', '.') : '0'; ?></h6>
                                    </li>
                                    <li>
                                        <h4>Status</h4>
                                        <h6>Active</h6>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 col-sm-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="slider-product-details">
                                <div class="owl-carousel owl-theme product-slide">
                                    <div class="slider-product">
                                        <?php if (isset($product['image']) && !empty($product['image'])): ?>
                                            <img src="image/<?php echo $product['image']; ?>" alt="Product Image">
                                            <h4><?php echo $product['image']; ?></h4>
                                        <?php else: ?>
                                            <img src="/ayula-store/bootstrap/assets/img/product/noimage.png" alt="No Image">
                                            <h4>No Image Available</h4>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    </div>


    <script src="/ayula-store/bootstrap/assets/js/jquery-3.6.0.min.js"></script>

    <script src="/ayula-store/bootstrap/assets/js/feather.min.js"></script>

    <script src="/ayula-store/bootstrap/assets/js/jquery.slimscroll.min.js"></script>

    <script src="/ayula-store/bootstrap/assets/js/bootstrap.bundle.min.js"></script>

    <script src="/ayula-store/bootstrap/assets/plugins/owlcarousel/owl.carousel.min.js"></script>

    <script src="/ayula-store/bootstrap/assets/plugins/select2/js/select2.min.js"></script>

    <script src="/ayula-store/bootstrap/assets/js/script.js"></script>
    
    <script>
        // Generate barcode
        $(document).ready(function() {
            <?php if (isset($product['kode_barang']) && !empty($product['kode_barang'])): ?>
                JsBarcode("#barcode", "<?php echo $product['kode_barang']; ?>", {
                    format: "CODE128",
                    width: 2,
                    height: 70,
                    displayValue: false,
                    margin: 10,
                    background: "#ffffff",
                    lineColor: "#000000"
                });
            <?php else: ?>
                JsBarcode("#barcode", "BRG000", {
                    format: "CODE128",
                    width: 2,
                    height: 70,
                    displayValue: false,
                    margin: 10,
                    background: "#ffffff",
                    lineColor: "#000000"
                });
            <?php endif; ?>
        });
        
        // Function to print barcode
        function printBarcode() {
            window.print();
        }
    </script>
</body>

</html>