<?php
/**
 * Product & Service Manager (Upgraded with Multi-Gallery Upload & Dynamic Specs)
 * Path: admin/services.php
 */

require_once 'layout-header.php';

if (!$conn) {
    echo "<main class='flex-1 p-6 md:p-8'><div class='p-4 bg-red-950/40 border border-red-800 text-red-200 text-sm rounded-xl flex items-center'><i class='fa-solid fa-triangle-exclamation mr-3 text-base'></i> ডাটাবেজ কানেক্টেড নেই!</div></main>";
    require_once 'layout-footer.php';
    exit;
}

$prefix = DB_PREFIX;
$msg_success = '';
$msg_error = '';

$action = isset($_GET['action']) ? $_GET['action'] : 'list';
$edit_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// --- ১. গ্যালারির ছবি ডিলিট করার সাব-অ্যাকশন ---
if ($action === 'delete_image' && isset($_GET['image_id']) && $edit_id > 0) {
    $image_id = intval($_GET['image_id']);
    
    // সার্ভার ফাইল চেক এবং রিমুভ
    $stmt = $conn->prepare("SELECT image_url FROM `{$prefix}product_images` WHERE id = ? AND product_id = ?");
    $stmt->bind_param("ii", $image_id, $edit_id);
    $stmt->execute();
    $result = $stmt->get_result();
    if ($row = $result->fetch_assoc()) {
        $file_path = '../' . $row['image_url'];
        if (is_file($file_path)) {
            unlink($file_path);
        }
    }
    $stmt->close();

    // ডাটাবেজ থেকে এন্ট্রি রিমুভ
    $stmt_del = $conn->prepare("DELETE FROM `{$prefix}product_images` WHERE id = ? AND product_id = ?");
    $stmt_del->bind_param("ii", $image_id, $edit_id);
    $stmt_del->execute();
    $stmt_del->close();

    $msg_success = "গ্যালারির ছবিটি সফলভাবে মুছে ফেলা হয়েছে!";
    $action = 'edit';
}

// --- ২. মেইন প্রোডাক্ট সম্পূর্ণ মুছে ফেলার লজিক ---
if ($action === 'delete' && $edit_id > 0) {
    // এটার সাথে যুক্ত গ্যালারির সব ফাইল সার্ভার থেকে মুছে ফেলা হবে
    $sql_images = "SELECT image_url FROM `{$prefix}product_images` WHERE product_id = ?";
    $stmt_imgs = $conn->prepare($sql_images);
    $stmt_imgs->bind_param("i", $edit_id);
    $stmt_imgs->execute();
    $res_imgs = $stmt_imgs->get_result();
    while ($img_row = $res_imgs->fetch_assoc()) {
        $file_path = '../' . $img_row['image_url'];
        if (is_file($file_path)) {
            unlink($file_path);
        }
    }
    $stmt_imgs->close();

    // প্রোডাক্টের মেইন ছবি রিমুভ
    $stmt_main = $conn->prepare("SELECT image_url FROM `{$prefix}services` WHERE id = ?");
    $stmt_main->bind_param("i", $edit_id);
    $stmt_main->execute();
    if ($main_row = $stmt_main->get_result()->fetch_assoc()) {
        $main_file = '../' . $main_row['image_url'];
        if (is_file($main_file)) {
            unlink($main_file);
        }
    }
    $stmt_main->close();

    // ডাটাবেজ ক্যাসকেড রিলেশনের কারণে চাইল্ড টেবিলগুলোর ডাটাও ডিলিট হয়ে যাবে
    $stmt = $conn->prepare("DELETE FROM `{$prefix}services` WHERE id = ?");
    $stmt->bind_param("i", $edit_id);
    if ($stmt->execute()) {
        $msg_success = "প্রোডাক্ট এবং এর সাথে যুক্ত সকল ইমেজ ও স্পেসিফিকেশন সফলভাবে মুছে ফেলা হয়েছে!";
    } else {
        $msg_error = "মুছে ফেলতে ত্রুটি: " . $conn->error;
    }
    $stmt->close();
    $action = 'list';
}

// --- ৩. প্রোডাক্ট ক্রিয়েট ও আপডেট লজিক ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['form_action'])) {
    $title = isset($_POST['title']) ? trim($_POST['title']) : '';
    $description = isset($_POST['description']) ? trim($_POST['description']) : '';
    $image_url = isset($_POST['image_url']) ? trim($_POST['image_url']) : '';
    
    $slug = preg_replace('/[^a-z0-9\-]/', '', str_replace(' ', '-', strtolower($title)));

    if (empty($title) || empty($description)) {
        $msg_error = "টাইটেল ও বিবরণী দেওয়া বাধ্যতামূলক।";
    } else {
        
        // ক) ফিচারড ইমেজ (ম্যানুয়াল আপলোড) প্রসেসিং
        if (isset($_FILES['image_file']) && $_FILES['image_file']['error'] === UPLOAD_ERR_OK) {
            $file_tmp = $_FILES['image_file']['tmp_name'];
            $file_name = $_FILES['image_file']['name'];
            $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
            $allowed_exts = ['jpg', 'jpeg', 'png', 'webp', 'gif'];
            
            if (in_array($file_ext, $allowed_exts)) {
                $upload_dir = '../uploads/';
                if (!is_dir($upload_dir)) mkdir($upload_dir, 0755, true);
                
                $new_file_name = time() . '_main_' . preg_replace('/[^a-z0-9\._\-]/i', '', $file_name);
                if (move_uploaded_file($file_tmp, $upload_dir . $new_file_name)) {
                    $image_url = 'uploads/' . $new_file_name;
                }
            } else {
                $msg_error = "ভুল ফাইল ফরম্যাট!";
            }
        }

        if (empty($msg_error)) {
            $conn->begin_transaction();
            try {
                // খ) বেস প্রোডাক্ট ডাটা সেভ
                $product_id = 0;
                if ($_POST['form_action'] === 'add_product') {
                    $stmt = $conn->prepare("INSERT INTO `{$prefix}services` (title, description, image_url, slug) VALUES (?, ?, ?, ?)");
                    $stmt->bind_param("ssss", $title, $description, $image_url, $slug);
                    $stmt->execute();
                    $product_id = $conn->insert_id;
                    $stmt->close();
                } elseif ($_POST['form_action'] === 'edit_product' && $edit_id > 0) {
                    $stmt = $conn->prepare("UPDATE `{$prefix}services` SET title = ?, description = ?, image_url = ?, slug = ? WHERE id = ?");
                    $stmt->bind_param("ssssi", $title, $description, $image_url, $slug, $edit_id);
                    $stmt->execute();
                    $stmt->close();
                    $product_id = $edit_id;
                }

                if ($product_id > 0) {
                    // গ) মাল্টিপল গ্যালারি ইমেজ আপলোড
                    if (isset($_FILES['gallery_files']) && !empty($_FILES['gallery_files']['name'][0])) {
                        $files = $_FILES['gallery_files'];
                        $upload_dir = '../uploads/';
                        if (!is_dir($upload_dir)) mkdir($upload_dir, 0755, true);

                        for ($i = 0; $i < count($files['name']); $i++) {
                            if ($files['error'][$i] === UPLOAD_ERR_OK) {
                                $file_tmp = $files['tmp_name'][$i];
                                $file_name = $files['name'][$i];
                                $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
                                
                                if (in_array($file_ext, ['jpg', 'jpeg', 'png', 'webp', 'gif'])) {
                                    $new_gal_name = time() . '_gal_' . $i . '_' . preg_replace('/[^a-z0-9\._\-]/i', '', $file_name);
                                    if (move_uploaded_file($file_tmp, $upload_dir . $new_gal_name)) {
                                        $gal_path = 'uploads/' . $new_gal_name;
                                        
                                        $stmt_gal = $conn->prepare("INSERT INTO `{$prefix}product_images` (product_id, image_url) VALUES (?, ?)");
                                        $stmt_gal->bind_param("is", $product_id, $gal_path);
                                        $stmt_gal->execute();
                                        $stmt_gal->close();
                                    }
                                }
                            }
                        }
                    }

                    // ঘ) ডাইনামিক স্পেসিফিকেশন ডাটা সেভ
                    // ডুপ্লিকেট এড়াতে পূর্বের স্পেক্স ডিলিট করা হচ্ছে
                    $stmt_spec_del = $conn->prepare("DELETE FROM `{$prefix}product_specs` WHERE product_id = ?");
                    $stmt_spec_del->bind_param("i", $product_id);
                    $stmt_spec_del->execute();
                    $stmt_spec_del->close();

                    if (isset($_POST['spec_keys']) && isset($_POST['spec_values'])) {
                        $spec_keys = $_POST['spec_keys'];
                        $spec_values = $_POST['spec_values'];

                        for ($i = 0; $i < count($spec_keys); $i++) {
                            $key = trim($spec_keys[$i]);
                            $val = trim($spec_values[$i]);

                            if (!empty($key) && !empty($val)) {
                                $stmt_spec = $conn->prepare("INSERT INTO `{$prefix}product_specs` (product_id, spec_key, spec_value) VALUES (?, ?, ?)");
                                $stmt_spec->bind_param("iss", $product_id, $key, $val);
                                $stmt_spec->execute();
                                $stmt_spec->close();
                            }
                        }
                    }

                    $conn->commit();
                    $msg_success = "প্রোডাক্ট, গ্যালারি ছবি এবং স্পেসিফিকেশন সফলভাবে সংরক্ষণ করা হয়েছে!";
                    $action = 'list';
                }
            } catch (Exception $e) {
                $conn->rollback();
                $msg_error = "ডাটা সংরক্ষণ করতে সমস্যা হয়েছে: " . $e->getMessage();
            }
        }
    }
}
?>

    <!-- Main Workspace -->
    <main class="flex-1 p-6 md:p-8 space-y-6">

        <!-- Top Navigation Header -->
        <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 border-b border-slate-800/80 pb-5">
            <div>
                <h1 class="text-2xl font-black text-white uppercase tracking-wider">Advanced Products Manager</h1>
                <p class="text-xs text-slate-400 mt-1">গ্যালারি ছবি ও ডাইনামিক স্পেসিফিকেশনসহ প্রোডাক্ট নিয়ন্ত্রণ করুন</p>
            </div>
            <?php if ($action === 'list'): ?>
                <a href="?action=add" class="bg-sky-500 hover:bg-sky-600 text-slate-950 font-black px-5 py-2.5 rounded-xl transition-all shadow-md text-xs uppercase flex items-center">
                    <i class="fa-solid fa-plus-circle mr-2 text-base"></i> Add New Product
                </a>
            <?php else: ?>
                <a href="services.php" class="bg-slate-800 hover:bg-slate-700 text-slate-300 px-5 py-2.5 rounded-xl transition-all text-xs uppercase flex items-center">
                    <i class="fa-solid fa-arrow-left mr-2"></i> Back to List
                </a>
            <?php endif; ?>
        </div>

        <!-- Alert notifications -->
        <?php if (!empty($msg_success)): ?>
            <div class="p-4 bg-emerald-950/40 border border-emerald-800 text-emerald-200 text-xs rounded-xl flex items-center shadow-lg">
                <i class="fa-solid fa-circle-check mr-3 text-base"></i>
                <?php echo htmlspecialchars($msg_success); ?>
            </div>
        <?php endif; ?>
        <?php if (!empty($msg_error)): ?>
            <div class="p-4 bg-red-950/40 border border-red-800 text-red-200 text-xs rounded-xl flex items-center shadow-lg">
                <i class="fa-solid fa-triangle-exclamation mr-3 text-base"></i>
                <?php echo htmlspecialchars($msg_error); ?>
            </div>
        <?php endif; ?>

        <!-- ========================================== -->
        <!-- VIEW: PRODUCT ADD / EDIT VIEW -->
        <!-- ========================================== -->
        <?php if ($action === 'add' || $action === 'edit'): 
            $form_title = "Add Dynamic Product & Solutions";
            $form_action = "add_product";
            $val_title = "";
            $val_description = "";
            $val_image = "";
            $existing_specs = [];
            $existing_gallery = [];

            if ($action === 'edit' && $edit_id > 0) {
                $form_title = "Edit Advanced Product Configuration";
                $form_action = "edit_product";
                
                // ১. বেস প্রোডাক্ট ডাটা সংগ্রহ
                $stmt = $conn->prepare("SELECT * FROM `{$prefix}services` WHERE id = ? LIMIT 1");
                $stmt->bind_param("i", $edit_id);
                $stmt->execute();
                $result = $stmt->get_result();
                if ($row = $result->fetch_assoc()) {
                    $val_title = $row['title'];
                    $val_description = $row['description'];
                    $val_image = $row['image_url'];
                }
                $stmt->close();

                // ২. গ্যালারি ডাটা সংগ্রহ
                $stmt_gal = $conn->prepare("SELECT * FROM `{$prefix}product_images` WHERE product_id = ?");
                $stmt_gal->bind_param("i", $edit_id);
                $stmt_gal->execute();
                $res_gal = $stmt_gal->get_result();
                while ($g_row = $res_gal->fetch_assoc()) {
                    $existing_gallery[] = $g_row;
                }
                $stmt_gal->close();

                // ৩. স্পেক্স ডাটা সংগ্রহ
                $stmt_sp = $conn->prepare("SELECT * FROM `{$prefix}product_specs` WHERE product_id = ?");
                $stmt_sp->bind_param("i", $edit_id);
                $stmt_sp->execute();
                $res_sp = $stmt_sp->get_result();
                while ($s_row = $res_sp->fetch_assoc()) {
                    $existing_specs[] = $s_row;
                }
                $stmt_sp->close();
            }
        ?>
            <div class="bg-slate-900 border border-slate-800/80 rounded-2xl p-6 shadow-sm">
                <h2 class="text-sm font-bold uppercase text-sky-400 tracking-wider flex items-center pb-3 border-b border-slate-800/80 mb-6">
                    <i class="fa-solid fa-pen-to-square mr-2 text-lg"></i> <?php echo $form_title; ?>
                </h2>

                <form method="post" action="" enctype="multipart/form-data" class="space-y-6">
                    <input type="hidden" name="form_action" value="<?php echo $form_action; ?>">

                    <!-- Product title and Main Image Grid -->
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div>
                            <label class="block text-xs font-bold uppercase text-slate-400 tracking-wide mb-2">Product/Service Title</label>
                            <input type="text" name="title" value="<?php echo htmlspecialchars($val_title); ?>" placeholder="E.g., Standby Power Generators" required class="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-3.5 text-sm focus:outline-none focus:ring-2 focus:ring-sky-500 transition-all text-slate-100">
                        </div>
                        
                        <div>
                            <label class="block text-xs font-bold uppercase text-slate-400 tracking-wide mb-2">Featured Cover Image Options</label>
                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                <div>
                                    <span class="block text-[10px] text-slate-500 font-bold uppercase mb-1">Option 1: Upload File</span>
                                    <input type="file" name="image_file" class="w-full bg-slate-950 border border-slate-800 rounded-xl px-2 py-2 text-xs text-slate-400 focus:outline-none focus:ring-1 focus:ring-sky-500 transition-all">
                                </div>
                                <div>
                                    <span class="block text-[10px] text-slate-500 font-bold uppercase mb-1">Option 2: Paste URL</span>
                                    <input type="url" name="image_url" value="<?php echo htmlspecialchars($val_image); ?>" placeholder="https://..." class="w-full bg-slate-950 border border-slate-800 rounded-xl px-3 py-2.5 text-xs focus:outline-none focus:ring-1 focus:ring-sky-500 transition-all text-slate-100">
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Multi Image Gallery Area -->
                    <div class="bg-slate-950/40 p-4 border border-slate-800 rounded-xl space-y-4">
                        <div>
                            <h3 class="text-xs font-black uppercase text-slate-300">Product Image Gallery</h3>
                            <p class="text-[10px] text-slate-500">আপনার পিসি থেকে এই প্রোডাক্টের সাথে যুক্ত একাধিক গ্যালারি ছবি একসাথে সিলেক্ট করে আপলোড করতে পারেন।</p>
                        </div>
                        
                        <input type="file" name="gallery_files[]" multiple class="w-full bg-slate-900 border border-slate-800 rounded-xl px-4 py-3 text-xs text-slate-400 focus:outline-none focus:ring-1 focus:ring-sky-500">

                        <!-- আপলোড করা গ্যালারি ছবিগুলোর ছোট প্রিভিউ ও ডিলিট অপশন -->
                        <?php if(!empty($existing_gallery)): ?>
                            <div class="pt-4 border-t border-slate-800/80">
                                <span class="block text-[10px] font-bold text-slate-500 uppercase mb-3">Currently Uploaded Gallery Photos:</span>
                                <div class="flex flex-wrap gap-4">
                                    <?php foreach($existing_gallery as $img): 
                                        $gal_img_src = $img['image_url'];
                                        if (strpos($gal_img_src, 'uploads/') === 0) { $gal_img_src = '../' . $gal_img_src; }
                                    ?>
                                        <div class="relative w-20 h-20 rounded-lg overflow-hidden border border-slate-700/80 group">
                                            <img class="w-full h-full object-cover" src="<?php echo htmlspecialchars($gal_img_src); ?>" alt="Gallery Image">
                                            <a href="?action=delete_image&image_id=<?php echo $img['id']; ?>&id=<?php echo $edit_id; ?>" onclick="return confirm('এই ছবিটি কি গ্যালারি থেকে মুছে ফেলবেন?');" class="absolute inset-0 bg-red-600/80 flex items-center justify-center text-white opacity-0 group-hover:opacity-100 transition-opacity">
                                                <i class="fa-solid fa-trash-can text-sm"></i>
                                            </a>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>

                    <!-- Dynamic Key-Value Specifications Area -->
                    <div class="bg-slate-950/40 p-5 border border-slate-800 rounded-xl space-y-4">
                        <div class="flex justify-between items-center">
                            <div>
                                <h3 class="text-xs font-black uppercase text-slate-300">Technical Specifications</h3>
                                <p class="text-[10px] text-slate-500">প্রোডাক্টের যাবতীয় তথ্য (যেমন- kVA, Capacity, Model, Lift Size) এখানে ডায়নামিকালি যুক্ত করুন।</p>
                            </div>
                            <button type="button" onclick="addSpecRow()" class="bg-slate-800 hover:bg-slate-700 text-sky-400 px-3 py-1.5 rounded-lg text-xs font-bold transition-all flex items-center">
                                <i class="fa-solid fa-circle-plus mr-1.5"></i> Add Specification Field
                            </button>
                        </div>

                        <!-- Specs Row Containers -->
                        <div id="specs-container" class="space-y-3">
                            <!-- Loop and display saved specifications if in edit mode -->
                            <?php if(!empty($existing_specs)): ?>
                                <?php foreach($existing_specs as $spec): ?>
                                    <div class="flex gap-4 items-center spec-row">
                                        <input type="text" name="spec_keys[]" value="<?php echo htmlspecialchars($spec['spec_key']); ?>" placeholder="E.g., Capacity / kVA" class="w-1/2 bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-xs text-slate-100 focus:outline-none focus:ring-1 focus:ring-sky-500">
                                        <input type="text" name="spec_values[]" value="<?php echo htmlspecialchars($spec['spec_value']); ?>" placeholder="E.g., 800 Kg / 150 kVA" class="w-1/2 bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-xs text-slate-100 focus:outline-none focus:ring-1 focus:ring-sky-500">
                                        <button type="button" onclick="this.parentElement.remove()" class="text-red-500 hover:text-red-400 p-2"><i class="fa-solid fa-trash"></i></button>
                                    </div>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </div>
                    </div>

                    <!-- Base Product Description -->
                    <div>
                        <label class="block text-xs font-bold uppercase text-slate-400 tracking-wide mb-2">Product Long Description</label>
                        <textarea name="description" rows="5" placeholder="Detailed product context..." required class="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-3.5 text-sm focus:outline-none focus:ring-2 focus:ring-sky-500 transition-all text-slate-100"><?php echo htmlspecialchars($val_description); ?></textarea>
                    </div>

                    <div class="flex justify-end pt-4">
                        <button type="submit" class="bg-sky-500 hover:bg-sky-600 text-slate-950 font-black px-8 py-3.5 rounded-xl transition-all shadow-md text-xs uppercase tracking-wider flex items-center">
                            <i class="fa-solid fa-circle-check mr-2 text-base"></i> Save Product Configuration
                        </button>
                    </div>
                </form>
            </div>

            <!-- JS for dynamic specs rendering -->
            <script>
                function addSpecRow(key = '', val = '') {
                    const container = document.getElementById('specs-container');
                    const row = document.createElement('div');
                    row.className = "flex gap-4 items-center spec-row animate-fade-in";
                    row.innerHTML = `
                        <input type="text" name="spec_keys[]" value="${key}" placeholder="E.g., Capacity / kVA / Engine" class="w-1/2 bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-xs text-slate-100 focus:outline-none focus:ring-1 focus:ring-sky-500">
                        <input type="text" name="spec_values[]" value="${val}" placeholder="E.g., 800 Kg / 150 kVA / Perkins" class="w-1/2 bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-xs text-slate-100 focus:outline-none focus:ring-1 focus:ring-sky-500">
                        <button type="button" onclick="this.parentElement.remove()" class="text-red-500 hover:text-red-400 p-2"><i class="fa-solid fa-trash"></i></button>
                    `;
                    container.appendChild(row);
                }

                // If empty screen, add one row by default for UX
                <?php if(empty($existing_specs)): ?>
                    document.addEventListener("DOMContentLoaded", () => { addSpecRow(); });
                <?php endif; ?>
            </script>

        <!-- ========================================== -->
        <!-- VIEW: PRODUCTS LIST -->
        <!-- ========================================== -->
        <?php else: 
            $sql = "SELECT * FROM `{$prefix}services` ORDER BY id DESC";
            $result = $conn->query($sql);
        ?>
            <div class="bg-slate-900 border border-slate-800/80 rounded-2xl shadow-sm overflow-hidden">
                <div class="px-6 py-4 border-b border-slate-800/80 flex items-center">
                    <h2 class="text-sm font-bold uppercase text-sky-400 tracking-wider"><i class="fa-solid fa-list-check mr-2"></i> Current Products</h2>
                </div>

                <div class="overflow-x-auto">
                    <table class="w-full text-left border-collapse text-sm">
                        <thead>
                            <tr class="bg-slate-950 text-slate-400 border-b border-slate-800 text-xs font-bold uppercase">
                                <th class="p-4 pl-6 w-24">Image</th>
                                <th class="p-4">Title & Slug</th>
                                <th class="p-4 hidden md:table-cell">Short Description</th>
                                <th class="p-4 text-right pr-6 w-40">Actions</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-slate-800">
                            <?php if ($result && $result->num_rows > 0): ?>
                                <?php while ($row = $result->fetch_assoc()): 
                                    $img_src = $row['image_url'];
                                    if (strpos($img_src, 'uploads/') === 0) { $img_src = '../' . $img_src; }
                                ?>
                                    <tr class="hover:bg-slate-800/30 transition-colors">
                                        <td class="p-4 pl-6">
                                            <img class="w-12 h-12 rounded-lg object-cover border border-slate-700 bg-slate-850" src="<?php echo htmlspecialchars($img_src); ?>" alt="Product">
                                        </td>
                                        <td class="p-4">
                                            <span class="block font-bold text-white"><?php echo htmlspecialchars($row['title']); ?></span>
                                            <span class="text-[10px] text-slate-500 font-mono mt-0.5 block">/<?php echo htmlspecialchars($row['slug']); ?></span>
                                        </td>
                                        <td class="p-4 text-xs text-slate-400 hidden md:table-cell">
                                            <p class="line-clamp-2 leading-relaxed max-w-sm"><?php echo htmlspecialchars($row['description']); ?></p>
                                        </td>
                                        <td class="p-4 text-right pr-6">
                                            <div class="inline-flex space-x-2">
                                                <a href="?action=edit&id=<?php echo $row['id']; ?>" class="p-2 bg-slate-800 hover:bg-sky-500 hover:text-slate-950 text-sky-400 rounded-lg transition-all text-xs" title="Edit Product Configuration"><i class="fa-solid fa-gear"></i></a>
                                                <a href="?action=delete&id=<?php echo $row['id']; ?>" onclick="return confirm('আপনি কি নিশ্চিতভাবে এই প্রোডাক্টটি চিরতরে মুছে ফেলতে চান?');" class="p-2 bg-slate-800 hover:bg-red-500 hover:text-white text-red-400 rounded-lg transition-all text-xs" title="Delete Product"><i class="fa-solid fa-trash-can"></i></a>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endwhile; ?>
                            <?php else: ?>
                                <tr>
                                    <td colspan="4" class="p-8 text-center text-slate-500 italic">ডাটাবেজে কোনো প্রোডাক্ট পাওয়া যায়নি।</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        <?php endif; ?>

    </main>

<?php
require_once 'layout-footer.php';
?>