<?php
/**
 * Agentic Square - Premium Seller Control Console: Product Asset Modification Engine
 * Path: seller/update-item.php
 */

// Inject Core Global Application Engine Paths
require_once __DIR__ . '/../config/config.php';

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

/**
 * STRICT SELLER SECURITY AUDIT GUARD
 */
if (!isset($_SESSION['user_id'])) {
    header('Location: ../login.php');
    exit;
}

// System notifications session bridge variables
$toast_success = $_SESSION['toast_success'] ?? '';
$toast_error = $_SESSION['toast_error'] ?? '';
unset($_SESSION['toast_success'], $_SESSION['toast_error']);

// Capture target resource identity criteria
$item_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if ($item_id <= 0) {
    header('Location: my-items.php');
    exit;
}

/**
 * IDENTITY MATCHING VERIFICATION QUERY
 */
$stmt = $pdo->prepare("
    SELECT i.*, s.id as seller_profile_id 
    FROM items i 
    LEFT JOIN sellers s ON i.seller_id = s.id 
    WHERE i.id = ? LIMIT 1
");
$stmt->execute([$item_id]);
$item = $stmt->fetch();

// CRITICAL SECURITY ENFORCEMENT: ONLY the authorized seller who owns this asset can view or update it
if (!$item || ((int)$item['user_id'] !== (int)$_SESSION['user_id'])) {
    header('Location: my-items.php?error=unauthorized_access');
    exit;
}

// Extract Category configurations
$categories = $pdo->query("SELECT * FROM categories ORDER BY category_name ASC")->fetchAll();

/**
 * ACTION ROUTER: SECURE ZIP ARTIFACT DETACHMENT ENGINE
 */
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_zip_file') {
    try {
        if (!empty($item['item_zip_file'])) {
            $zip_physical_path = __DIR__ . '/../' . $item['item_zip_file'];
            if (file_exists($zip_physical_path) && is_file($zip_physical_path)) {
                @unlink($zip_physical_path);
            }
            
            $wipeStmt = $pdo->prepare("UPDATE items SET item_zip_file = NULL, status = 'pending' WHERE id = ? AND user_id = ?");
            $wipeStmt->execute([$item_id, $_SESSION['user_id']]);
            
            $_SESSION['toast_success'] = "Software archive package (.ZIP) deleted from servers successfully.";
            header("Location: update-item.php?id=" . $item_id);
            exit;
        }
    } catch (Exception $e) {
        $_SESSION['toast_error'] = "File System Exception during asset detachment: " . $e->getMessage();
        header("Location: update-item.php?id=" . $item_id);
        exit;
    }
}

/**
 * VENDOR DATABASE MUTATION ENGINE PIPELINE
 */
if ($_SERVER['REQUEST_METHOD'] === 'POST' && (!isset($_POST['action']) || $_POST['action'] !== 'delete_zip_file')) {
    
    // Detects if the total post request size broke your PHP threshold limits entirely
    if (empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
        $_SESSION['toast_error'] = "The system blocked your payload. Your ZIP file is larger than the server's post_max_size limit.";
        header("Location: update-item.php?id=" . $item_id);
        exit;
    }

    // Collect vendor text input variables securely
    $item_name      = trim($_POST['item_name'] ?? '');
    $item_slug      = trim($_POST['item_slug'] ?? '');
    $category_id    = (int)($_POST['category_id'] ?? 0);
    $amount         = (float)($_POST['amount'] ?? 0.00);
    $item_details   = trim($_POST['item_details'] ?? '');
    $video_url      = trim($_POST['video_url'] ?? '');
    $demo_url       = trim($_POST['demo_url'] ?? '');
    $files_included = trim($_POST['files_included'] ?? '');
    $ai_brain_used  = trim($_POST['ai_brain_used'] ?? '');
    $support_days   = (int)($_POST['support_days'] ?? 0);
    
    // SAFETY RULE FOR SELLER EDITS: Force asset visibility flag back to "pending" for review
    $status = 'pending';

    if (empty($item_name) || empty($item_slug) || $category_id <= 0 || $amount < 0) {
        $_SESSION['toast_error'] = "Required settings missing. Please verify title, price, and category selections.";
        header("Location: update-item.php?id=" . $item_id);
        exit;
    } else {
        // Safe tracking collection structures map fields array 
        $images = [
            'feature_image' => $item['feature_image'],
            'screenshot_2'  => $item['screenshot_2'],
            'screenshot_3'  => $item['screenshot_3']
        ];
        
        $item_zip_file = $item['item_zip_file'] ?? null;

        $upload_dir = __DIR__ . '/../uploads/';
        if (!is_dir($upload_dir)) {
            mkdir($upload_dir, 0755, true);
        }

        // Process Standard Graphics Attachments Asset Media Matrices
        foreach (['feature_image', 'screenshot_2', 'screenshot_3'] as $file_input) {
            if (isset($_FILES[$file_input]) && $_FILES[$file_input]['error'] === UPLOAD_ERR_OK) {
                $file_tmp   = $_FILES[$file_input]['tmp_name'];
                $file_name  = time() . '_seller_' . bin2hex(random_bytes(4)) . '_' . basename($_FILES[$file_input]['name']);
                $target_file = $upload_dir . $file_name;

                if (move_uploaded_file($file_tmp, $target_file)) {
                    $images[$file_input] = 'uploads/' . $file_name;
                }
            }
        }
        
        // --- UNIFIED INLINE ZIP VALIDATION HANDLING LOOP ---
        if (isset($_FILES['item_zip_file']) && $_FILES['item_zip_file']['error'] === UPLOAD_ERR_OK) {
            $zip_ext = strtolower(pathinfo($_FILES['item_zip_file']['name'], PATHINFO_EXTENSION));
            
            if ($zip_ext !== 'zip') {
                $_SESSION['toast_error'] = "Invalid file type. Asset package MUST use a compressed .zip container matrix format.";
                header("Location: update-item.php?id=" . $item_id);
                exit;
            } else {
                // Point dynamically back to your working admin folder pipeline paths
                $zipDir = __DIR__ . '/../uploads/products/zips/';
                if (!is_dir($zipDir)) {
                    mkdir($zipDir, 0755, true);
                }

                // Delete old archive package to preserve host partition disk space allocations
                if (!empty($item_zip_file)) {
                    $oldZip = __DIR__ . '/../' . $item_zip_file;
                    if (file_exists($oldZip) && is_file($oldZip)) {
                        @unlink($oldZip);
                    }
                }

                $zipName = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $_FILES['item_zip_file']['name']);
                
                if (move_uploaded_file($_FILES['item_zip_file']['tmp_name'], $zipDir . $zipName)) {
                    $item_zip_file = 'uploads/products/zips/' . $zipName;
                } else {
                    $_SESSION['toast_error'] = "The server failed to write files into your uploads directory. Verify directory write permissions.";
                    header("Location: update-item.php?id=" . $item_id);
                    exit;
                }
            }
        }

        try {
            // Secure parameterized transaction modification matrix update loop
            $updateStmt = $pdo->prepare("
                UPDATE items SET 
                    item_name = ?, 
                    item_slug = ?, 
                    category_id = ?, 
                    amount = ?, 
                    item_details = ?, 
                    feature_image = ?, 
                    screenshot_2 = ?, 
                    screenshot_3 = ?, 
                    item_zip_file = ?,
                    video_url = ?, 
                    demo_url = ?, 
                    files_included = ?, 
                    ai_brain_used = ?, 
                    support_days = ?, 
                    status = ? 
                WHERE id = ? AND user_id = ?
            ");

            $updateStmt->execute([
                $item_name,
                $item_slug,
                $category_id,
                $amount,
                $item_details,
                $images['feature_image'],
                $images['screenshot_2'],
                $images['screenshot_3'],
                $item_zip_file,
                $video_url,
                $demo_url,
                $files_included,
                $ai_brain_used,
                $support_days,
                $status,
                $item_id,
                $_SESSION['user_id']
            ]);

            $_SESSION['toast_success'] = "Platform inventory item configuration registry records synchronized successfully.";
            header("Location: update-item.php?id=" . $item_id);
            exit;

        } catch (Exception $e) {
            $_SESSION['toast_error'] = "System Processing Core Sync Exception: " . $e->getMessage();
            header("Location: update-item.php?id=" . $item_id);
            exit;
        }
    }
}

// Inject standard secure UI Header layout component
require_once __DIR__ . '/../sections/header.php';
?>

<body class="bg-nftDark text-white antialiased overflow-x-hidden">

    <?php include_once __DIR__ . '/seller-sidebar.php'; ?>

    <?php if (!empty($toast_success)): ?>
        <div id="toastNotification" class="fixed top-6 right-6 z-50 transform transition-all duration-300 ease-out translate-y-0 opacity-100 max-w-sm w-full bg-slate-900 border-l-4 border-emerald-500 rounded-xl shadow-2xl p-4 flex items-start space-x-3 backdrop-blur-md">
            <div class="p-1 bg-emerald-500/10 rounded-lg text-emerald-400">
                <i class="fa-solid fa-circle-check text-lg"></i>
            </div>
            <div class="flex-1">
                <p class="text-xs font-bold text-white uppercase tracking-wider">Configuration Synchronized</p>
                <p class="text-[11px] text-slate-400 mt-0.5 leading-relaxed"><?php echo htmlspecialchars($toast_success); ?></p>
            </div>
            <button onclick="dismissToast()" class="text-slate-500 hover:text-white transition-colors text-xs p-0.5"><i class="fa-solid fa-xmark"></i></button>
        </div>
    <?php endif; ?>

    <?php if (!empty($toast_error)): ?>
        <div id="toastNotification" class="fixed top-6 right-6 z-50 transform transition-all duration-300 ease-out translate-y-0 opacity-100 max-w-sm w-full bg-slate-900 border-l-4 border-rose-500 rounded-xl shadow-2xl p-4 flex items-start space-x-3 backdrop-blur-md">
            <div class="p-1 bg-rose-500/10 rounded-lg text-rose-400">
                <i class="fa-solid fa-triangle-exclamation text-lg"></i>
            </div>
            <div class="flex-1">
                <p class="text-xs font-bold text-white uppercase tracking-wider">Sync Interrupted Fault</p>
                <p class="text-[11px] text-rose-400 font-mono mt-0.5 leading-relaxed"><?php echo htmlspecialchars($toast_error); ?></p>
            </div>
            <button onclick="dismissToast()" class="text-slate-500 hover:text-white transition-colors text-xs p-0.5"><i class="fa-solid fa-xmark"></i></button>
        </div>
    <?php endif; ?>

    <main class="lg:ml-64 min-h-screen pt-24 lg:pt-10 pb-16 px-4 sm:px-6 lg:px-8">
        <div class="max-w-5xl mx-auto space-y-8">
            
            <div class="flex items-center space-x-2 text-xs font-bold uppercase tracking-widest text-nftTextGray">
                <a href="my-items.php" class="hover:text-nftAccentCyan transition-colors">My Inventory</a>
                <span>/</span>
                <span class="text-nftAccentPurple">Update Product Listing</span>
            </div>

            <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between border-b border-slate-900/60 pb-6 gap-4">
                <div>
                    <h1 class="text-3xl font-extrabold tracking-tight text-white">Modify Product Configuration</h1>
                    <p class="text-sm text-nftTextGray mt-1">Update your digital asset metadata, media interfaces, source archives, and pricing parameters.</p>
                </div>
                
                <div class="flex items-center gap-2">
                    <span class="text-[10px] text-slate-500 font-bold uppercase tracking-wider font-mono">Current Status:</span>
                    <?php 
                    $itemStatus = $item['status'] ?? 'pending';
                    $badgeClass = ($itemStatus === 'active') ? 'bg-emerald-500/10 border-emerald-500/20 text-emerald-400' : 'bg-amber-500/10 border-amber-500/20 text-amber-400';
                    if($itemStatus === 'suspended') $badgeClass = 'bg-rose-500/10 border-rose-500/20 text-rose-400';
                    ?>
                    <span class="<?php echo $badgeClass; ?> border px-2.5 py-1 rounded-md text-[9px] font-bold uppercase font-mono tracking-wider"><?php echo $itemStatus; ?></span>
                </div>
            </div>

            <form method="POST" enctype="multipart/form-data" class="grid grid-cols-1 md:grid-cols-3 gap-6">
                
                <div class="md:col-span-2 space-y-6">
                    <div class="glass-card p-6 rounded-2xl border border-slate-800/80 space-y-5 shadow-lg">
                        <h3 class="text-sm font-bold uppercase text-nftAccentCyan tracking-wider border-b border-slate-900 pb-3">// Product Meta Specifications</h3>
                        
                        <div class="space-y-2">
                            <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Listing Title Name</label>
                            <input type="text" name="item_name" value="<?php echo htmlspecialchars($item['item_name']); ?>" class="w-full bg-slate-950 border border-slate-900 focus:border-nftAccentCyan focus:outline-none rounded-xl px-4 py-3 text-xs font-medium transition-colors" required>
                        </div>

                        <div class="space-y-2">
                            <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Custom URL Parameter Slug Link</label>
                            <input type="text" name="item_slug" value="<?php echo htmlspecialchars($item['item_slug']); ?>" class="w-full bg-slate-950 border border-slate-900 focus:border-nftAccentCyan focus:outline-none rounded-xl px-4 py-3 text-xs font-mono transition-colors" required>
                        </div>

                        <div class="space-y-2">
                            <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Full Product Feature Overview Description</label>
                            <textarea name="item_details" rows="10" class="w-full bg-slate-950 border border-slate-900 focus:border-nftAccentCyan focus:outline-none rounded-xl px-4 py-3 text-xs font-medium transition-colors leading-relaxed" required><?php echo htmlspecialchars($item['item_details']); ?></textarea>
                        </div>
                    </div>

                    <div class="glass-card p-6 rounded-2xl border border-slate-800/80 space-y-5 shadow-lg">
                        <h3 class="text-sm font-bold uppercase text-nftAccentPurple tracking-wider border-b border-slate-900 pb-3">// Technical Product Properties Endpoints</h3>
                        
                        <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                            <div class="space-y-2">
                                <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Live Environment View Sandbox URL</label>
                                <input type="url" name="demo_url" value="<?php echo htmlspecialchars($item['demo_url'] ?? ''); ?>" class="w-full bg-slate-950 border border-slate-900 focus:border-nftAccentCyan focus:outline-none rounded-xl px-4 py-3 text-xs transition-colors font-mono" placeholder="https://">
                            </div>
                            <div class="space-y-2">
                                <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Demonstration Video Preview Track URL</label>
                                <input type="url" name="video_url" value="<?php echo htmlspecialchars($item['video_url'] ?? ''); ?>" class="w-full bg-slate-950 border border-slate-900 focus:border-nftAccentCyan focus:outline-none rounded-xl px-4 py-3 text-xs transition-colors font-mono" placeholder="https://">
                            </div>
                        </div>

                        <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                            <div class="space-y-2">
                                <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Software Source Packaging Files Included</label>
                                <input type="text" name="files_included" value="<?php echo htmlspecialchars($item['files_included'] ?? ''); ?>" class="w-full bg-slate-950 border border-slate-900 focus:border-nftAccentCyan focus:outline-none rounded-xl px-4 py-3 text-xs transition-colors" placeholder="PHP, JavaScript, SQL">
                            </div>
                            <div class="space-y-2">
                                <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">AI Core Brain Architecture Engine Used</label>
                                <input type="text" name="ai_brain_used" value="<?php echo htmlspecialchars($item['ai_brain_used'] ?? ''); ?>" class="w-full bg-slate-950 border border-slate-900 focus:border-nftAccentCyan focus:outline-none rounded-xl px-4 py-3 text-xs transition-colors" placeholder="GPT-4o, Claude 3.5 Node">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="space-y-6">
                    
                    <div class="glass-card p-6 rounded-2xl border border-slate-800/80 space-y-4 shadow-lg bg-gradient-to-b from-slate-950/40 to-slate-950/90">
                        <h3 class="text-sm font-bold uppercase text-emerald-400 tracking-wider border-b border-slate-900 pb-3">// Listing Pricing & Marketplace Routing</h3>
                        
                        <div class="space-y-2">
                            <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Standard License Commercial Fee (<?php echo htmlspecialchars(get_site_currency(), ENT_QUOTES, 'UTF-8'); ?>)</label>
                            <div class="relative rounded-xl shadow-sm">
                                <span class="absolute inset-y-0 left-0 flex items-center pl-4 font-mono text-emerald-500 text-xs font-bold"><?php echo htmlspecialchars(currency_symbol(), ENT_QUOTES, 'UTF-8'); ?></span>
                                <input type="number" step="0.01" min="0.00" name="amount" value="<?php echo htmlspecialchars($item['amount']); ?>" class="w-full bg-slate-950 text-white font-mono font-bold text-xs pl-8 pr-4 py-3.5 rounded-xl border border-slate-900 focus:outline-none focus:border-emerald-500 transition-colors" required>
                            </div>
                        </div>

                        <div class="space-y-2">
                            <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Marketplace Classification Node Selection</label>
                            <select name="category_id" class="w-full bg-slate-950 text-white font-medium text-xs px-4 py-3 rounded-xl border border-slate-900 focus:outline-none focus:border-nftAccentCyan transition-all" required>
                                <option value="">-- Choose Category Group --</option>
                                <?php foreach ($categories as $cat): ?>
                                    <option value="<?php echo $cat['id']; ?>" <?php echo ((int)$item['category_id'] === (int)$cat['id']) ? 'selected' : ''; ?>>
                                        <?php echo htmlspecialchars($cat['category_name']); ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                        </div>

                        <div class="space-y-2">
                            <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Maintenance Support Coverage Length</label>
                            <div class="relative rounded-xl shadow-sm">
                                <input type="number" min="0" name="support_days" value="<?php echo htmlspecialchars($item['support_days']); ?>" class="w-full bg-slate-950 text-white font-mono font-bold text-xs px-4 py-3 rounded-xl border border-slate-900 focus:outline-none focus:border-nftAccentCyan transition-colors" required>
                                <span class="absolute inset-y-0 right-0 flex items-center pr-4 font-sans text-slate-600 text-[10px] font-bold uppercase tracking-wider pointer-events-none">Days Length</span>
                            </div>
                        </div>
                    </div>

                    <div class="glass-card p-6 rounded-2xl border border-slate-800/80 space-y-4 shadow-lg bg-gradient-to-b from-slate-950/20 to-slate-950/70">
                        <h3 class="text-sm font-bold uppercase text-nftAccentCyan tracking-wider border-b border-slate-900 pb-3">// Core Deliverable Source Package</h3>
                        
                        <div class="space-y-3">
                            <label class="text-xs font-bold text-slate-400 uppercase tracking-wider block">Software Codebase Archive (.ZIP)</label>
                            
                            <?php if (!empty($item['item_zip_file'])): ?>
                                <div class="p-3 bg-slate-900/60 border border-slate-800 rounded-xl space-y-2.5">
                                    <div class="flex items-center justify-between gap-4">
                                        <div class="flex items-center space-x-2 truncate">
                                            <i class="fa-solid fa-file-zipper text-lg text-amber-500 shrink-0"></i>
                                            <div class="truncate">
                                                <p class="text-[11px] font-mono font-bold text-slate-200 truncate"><?php echo basename($item['item_zip_file']); ?></p>
                                                <p class="text-[9px] text-emerald-400 font-sans tracking-wide font-medium uppercase">// Active Registered Package</p>
                                            </div>
                                        </div>
                                        <button type="button" onclick="confirmZipDeletion()" class="text-rose-400 hover:text-rose-300 text-xs p-1.5 bg-rose-500/10 hover:bg-rose-500/20 border border-rose-500/20 rounded-md transition-colors shadow-sm" title="Delete file from repository">
                                            <i class="fa-solid fa-trash-can text-[11px]"></i>
                                        </button>
                                    </div>
                                </div>
                                <div class="pt-1">
                                    <span class="text-[10px] font-bold text-slate-500 uppercase tracking-wider block mb-1.5">Upload to Replace File</span>
                                    <input type="file" name="item_zip_file" accept=".zip" class="text-[11px] font-mono text-slate-500 file:mr-3 file:py-1 file:px-2 file:rounded file:border-0 file:bg-slate-900 file:text-nftAccentCyan file:font-bold hover:file:bg-slate-800 cursor-pointer w-full">
                                </div>
                            <?php else: ?>
                                <div class="border border-dashed border-slate-800 p-4 rounded-xl text-center space-y-2 bg-slate-950/30">
                                    <i class="fa-solid fa-file-circle-plus text-2xl text-slate-700 block"></i>
                                    <span class="text-[10px] font-medium text-slate-500 block">No codebase zip package uploaded yet.</span>
                                    <input type="file" name="item_zip_file" accept=".zip" class="text-[11px] font-mono text-slate-500 file:mr-3 file:py-1 file:px-2 file:rounded file:border-0 file:bg-slate-900 file:text-nftAccentCyan file:font-bold hover:file:bg-slate-800 cursor-pointer w-full">
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="glass-card p-6 rounded-2xl border border-slate-800/80 space-y-4 shadow-lg">
                        <h3 class="text-sm font-bold uppercase text-slate-400 tracking-wider border-b border-slate-900 pb-3">// Asset Cover & Gallery Screenshots</h3>
                        
                        <div class="space-y-1.5 p-3 bg-slate-950/40 border border-slate-900 rounded-xl space-y-3">
                            <div class="flex items-center gap-3">
                                <div class="w-14 h-11 bg-slate-900 rounded border border-slate-800 overflow-hidden shrink-0">
                                    <img src="<?php echo !empty($item['feature_image']) ? '../' . $item['feature_image'] : '../assets/img/placeholder.png'; ?>" class="w-full h-full object-cover">
                                </div>
                                <span class="text-[10px] font-bold text-slate-500 uppercase tracking-wider">Item Cover Thumbnail</span>
                            </div>
                            <input type="file" name="feature_image" class="text-[11px] font-mono text-slate-500 file:mr-3 file:py-1 file:px-2 file:rounded file:border-0 file:bg-slate-900 file:text-nftAccentCyan file:font-bold hover:file:bg-slate-800 cursor-pointer w-full">
                        </div>

                        <div class="space-y-1.5 p-3 bg-slate-950/40 border border-slate-900 rounded-xl space-y-3">
                            <div class="flex items-center gap-3">
                                <div class="w-14 h-11 bg-slate-900 rounded border border-slate-800 overflow-hidden shrink-0">
                                    <img src="<?php echo !empty($item['screenshot_2']) ? '../' . $item['screenshot_2'] : '../assets/img/placeholder.png'; ?>" class="w-full h-full object-cover">
                                </div>
                                <span class="text-[10px] font-bold text-slate-500 uppercase tracking-wider">Screenshot View Panel 2</span>
                            </div>
                            <input type="file" name="screenshot_2" class="text-[11px] font-mono text-slate-500 file:mr-3 file:py-1 file:px-2 file:rounded file:border-0 file:bg-slate-900 file:text-nftAccentCyan file:font-bold hover:file:bg-slate-800 cursor-pointer w-full">
                        </div>

                        <div class="space-y-1.5 p-3 bg-slate-950/40 border border-slate-900 rounded-xl space-y-3">
                            <div class="flex items-center gap-3">
                                <div class="w-14 h-11 bg-slate-900 rounded border border-slate-800 overflow-hidden shrink-0">
                                    <img src="<?php echo !empty($item['screenshot_3']) ? '../' . $item['screenshot_3'] : '../assets/img/placeholder.png'; ?>" class="w-full h-full object-cover">
                                </div>
                                <span class="text-[10px] font-bold text-slate-500 uppercase tracking-wider">Screenshot View Panel 3</span>
                            </div>
                            <input type="file" name="screenshot_3" class="text-[11px] font-mono text-slate-500 file:mr-3 file:py-1 file:px-2 file:rounded file:border-0 file:bg-slate-900 file:text-nftAccentCyan file:font-bold hover:file:bg-slate-800 cursor-pointer w-full">
                        </div>
                    </div>

                    <div class="space-y-3">
                        <button type="submit" class="w-full btn-gradient py-4 px-4 rounded-xl text-xs font-bold uppercase tracking-widest text-white transition-all shadow-md active:scale-[0.98]">
                            <i class="fa-solid fa-cloud-arrow-up mr-2"></i> Save Changes & Resubmit
                        </button>
                        
                        <a href="my-items.php" class="w-full inline-flex items-center justify-center bg-slate-950 hover:bg-slate-900 border border-slate-900 text-slate-500 hover:text-white py-3 px-4 rounded-xl text-xs font-bold uppercase tracking-widest transition-all">
                            Cancel Modification
                        </a>
                    </div>

                </div>
            </form>

            <form id="zipDeletionStandaloneRouter" method="POST" action="update-item.php?id=<?php echo $item_id; ?>">
                <input type="hidden" name="action" value="delete_zip_file">
            </form>

        </div>
    </main>

    <script>
        function confirmZipDeletion() {
            if (confirm("🚨 WARNING: Permanently delete this .ZIP file package? This resets product listing status to pending review.")) {
                document.getElementById('zipDeletionStandaloneRouter').submit();
            }
        }

        // Auto-dismiss script for structural layout Toasts
        function dismissToast() {
            const toast = document.getElementById('toastNotification');
            if (toast) {
                toast.style.transform = 'translateY(-20px)';
                toast.style.opacity = '0';
                setTimeout(() => toast.remove(), 300);
            }
        }
        
        // Self destruct notifications smoothly after 4.5 seconds
        if (document.getElementById('toastNotification')) {
            setTimeout(dismissToast, 4500);
        }
    </script>
</body>
</html>
