<?php
/**
 * Bizmart — Products admin page.
 *
 * @package Bizmart
 * @license GPL-2.0-or-later
 */
if (!defined('ABSPATH')) exit;

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals, WordPress.DB, WordPress.Security, WordPress.PHP.DevelopmentFunctions

// Guard: this admin page requires WooCommerce
if ( ! function_exists('wc_get_products') ) {
    echo '<div class="wrap"><div class="notice notice-error"><p><strong>Bizmart:</strong> WooCommerce is required for this page.</p></div></div>';
    return;
}

/**
 * Performance upgrade:
 * - Avoid loading the entire product catalog on every admin page load.
 * - Cache statistics for a short period.
 */
(static function() {
// --- Global Flags & State ---
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$is_edit = (isset($_GET['action']) && sanitize_key(wp_unslash($_GET['action'])) === 'edit' && !empty($_GET['id']));
$edit_name = '';

$stats_cache_key = 'bizmart_products_stats_v5_' . (int) get_current_blog_id();

// Manual refresh for debugging: /wp-admin/admin.php?page=bizmart-products&bizmart_refresh=1
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if (isset($_GET['bizmart_refresh']) && current_user_can('manage_woocommerce')) {
    bizmart_invalidate_product_metrics_cache(null, 'manual_refresh');
}

// Force refresh: delete metrics cache on every page load to ensure accuracy
// 21-23: Clean up transients (removed for performance)

$stats = get_transient($stats_cache_key);

if (!$stats || !is_array($stats)) {
    // Total products (all published products)
    global $wpdb;
    $total_products = (int) $wpdb->get_var(
        $wpdb->prepare(
            "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s",
            'product',
            'publish'
        )
    );

    // Products without/zero price (count via SQL)
    $missing_price_query = new WP_Query([
        'post_type'      => 'product',
        'post_status'    => 'publish',
        'fields'         => 'ids',
        'posts_per_page' => 1,
        'no_found_rows'  => false,
        'meta_query'     => [
            'relation' => 'OR',
            [
                'key'     => '_price',
                'compare' => 'NOT EXISTS',
            ],
            [
                'key'     => '_price',
                'value'   => '',
                'compare' => '=',
            ],
            [
                'key'     => '_price',
                'value'   => 0,
                'type'    => 'NUMERIC',
                'compare' => '<=',
            ],
        ],
    ]);
    $products_without_price = (int) $missing_price_query->found_posts;

    // Product type counts (cheap taxonomy counts)
    $type_counts = [
        'simple' => 0,
        'variable' => 0,
        'grouped' => 0,
        'external' => 0,
    ];
    foreach (array_keys($type_counts) as $slug) {
        $term = get_term_by('slug', $slug, 'product_type');
        $type_counts[$slug] = $term ? (int) $term->count : 0;
    }

    // Unified inventory totals (RULE A: manage_stock=yes only)
    $inv = function_exists('bizmart_metrics_get_inventory_totals')
        ? bizmart_metrics_get_inventory_totals(true)
        : ['stock_sales_value' => 0, 'stock_purchase_value' => 0, 'total_stock_qty' => 0];

    $stock_value = (float) ($inv['stock_sales_value'] ?? 0);
    $stock_purchase_value = (float) ($inv['stock_purchase_value'] ?? 0);
    $total_stock = (float) ($inv['total_stock_qty'] ?? 0);

    // Debug: show breakdown when ?bizmart_debug=1 is present (admin-only)
    // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    if (isset($_GET['bizmart_debug']) && current_user_can('manage_woocommerce')) {
        $rows = function_exists('bizmart_metrics_get_inventory_rows') ? bizmart_metrics_get_inventory_rows() : [];
        echo "<div style=\"padding:12px;background:#fff;border:1px solid #eee;margin:10px 0;\">";
        echo "<h3>Bizmart Inventory Debug</h3>";
        echo "<p><strong>Totals (fresh):</strong> " . esc_html(wp_json_encode(function_exists('bizmart_metrics_get_inventory_totals') ? bizmart_metrics_get_inventory_totals(false) : [])) . "</p>";
        echo "<pre style=\"max-height:300px;overflow:auto;\">" . esc_html(print_r(array_map(function($r){ return [(int)$r->product_id,$r->post_type,(float)$r->stock_qty,$r->sku,$r->title]; }, $rows), true)) . "</pre>";
        echo "</div>";
    }

$stats = compact('total_products', 'products_without_price', 'type_counts', 'stock_value', 'stock_purchase_value', 'total_stock');
    set_transient($stats_cache_key, $stats, HOUR_IN_SECONDS);
} else {
    $total_products = (int) ($stats['total_products'] ?? 0);
    $products_without_price = (int) ($stats['products_without_price'] ?? 0);
    $type_counts = (array) ($stats['type_counts'] ?? []);
    $stock_value = (float) ($stats['stock_value'] ?? 0);
    $stock_purchase_value = (float) ($stats['stock_purchase_value'] ?? 0);
    $total_stock = (float) ($stats['total_stock'] ?? 0);
}

// Get all product categories
$product_categories = get_terms([
    'taxonomy' => 'product_cat',
    'hide_empty' => false,
    'orderby' => 'name',
    'order' => 'ASC'
]);

// Get shipping classes
$shipping_classes = get_terms([
    'taxonomy' => 'product_shipping_class',
    'hide_empty' => false
]);

// Get recent products
$recent_products = wc_get_products([
    'limit' => 8,
    'orderby' => 'date',
    'order' => 'DESC',
    'status' => 'publish'
]);

// Grouped products selector can be huge; cap for performance (filterable)
$simple_limit = (int) apply_filters('bizmart_grouped_simple_products_limit', 500);
$simple_limit = $simple_limit > 0 ? $simple_limit : 500;

$simple_products = wc_get_products([
    'type'    => 'simple',
    'limit'   => $simple_limit,
    'status'  => 'publish',
    'orderby' => 'title',
    'order'   => 'ASC',
]);

// --- EDIT MODE DATA PREPARATION ---
$edit_data = null;
$edit_active_tab = 'simple';
if ($is_edit) {
    // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    $p_id = intval(wp_unslash($_GET['id']));
    $p = wc_get_product($p_id);
    if ($p) {
        $edit_name = $p->get_name();
        $type = $p->get_type();
        if ($type === 'variable') $edit_active_tab = 'variable';
        elseif ($type === 'grouped') $edit_active_tab = 'grouped';
        elseif ($type === 'external') $edit_active_tab = 'external';
        elseif ($p->is_downloadable()) $edit_active_tab = 'digital';
        
        $edit_data = [
            'id' => $p->get_id(),
            'type' => $type,
            'name' => $p->get_name(),
            'sku' => $p->get_sku(),
            'regular_price' => $p->get_regular_price(),
            'sale_price' => $p->get_sale_price(),
            'short_description' => $p->get_short_description(),
            'description' => $p->get_description(),
            'manage_stock' => $p->get_manage_stock(),
            'stock_quantity' => $p->get_stock_quantity(),
            'stock_status' => $p->get_stock_status(),
            'cost_price' => get_post_meta($p_id, '_purchase_price', true),
            'categories' => $p->get_category_ids(),
            'image_id' => $p->get_image_id(),
            'barcodes' => function_exists('bizmart_get_product_barcodes') ? bizmart_get_product_barcodes($p_id) : [],
            'gallery_ids' => $p->get_gallery_image_ids(),
        ];
        
        // Load tags
        $tags = wp_get_post_terms($p_id, 'product_tag', ['fields' => 'names']);
        $edit_data['tags'] = is_array($tags) ? $tags : [];
        
        // Load attributes and variations for variable products
        if ($type === 'variable') {
            $attributes = [];
            $product_attributes = $p->get_attributes();
            
            foreach ($product_attributes as $attribute) {
                $attr_data = [
                    'name' => $attribute->get_name(),
                    'options' => $attribute->get_options(),
                    'visible' => $attribute->get_visible(),
                    'variation' => $attribute->get_variation(),
                ];
                
                // Check if it's a taxonomy attribute
                if ($attribute->is_taxonomy()) {
                    $attr_data['is_taxonomy'] = true;
                    $attr_data['taxonomy'] = $attribute->get_name();
                    
                    // Get term names instead of IDs
                    $term_ids = $attribute->get_options();
                    $term_names = [];
                    foreach ($term_ids as $term_id) {
                        $term = get_term($term_id, $attribute->get_name());
                        if ($term && !is_wp_error($term)) {
                            $term_names[] = $term->name;
                        }
                    }
                    $attr_data['options'] = $term_names;
                    
                    // Get the label for display
                    $taxonomy = get_taxonomy($attribute->get_name());
                    if ($taxonomy) {
                        $attr_data['label'] = $taxonomy->labels->singular_name;
                    }
                } else {
                    $attr_data['is_taxonomy'] = false;
                    $attr_data['label'] = $attribute->get_name();
                }
                
                $attributes[] = $attr_data;
            }
            $edit_data['attributes'] = $attributes;
            
            // Load variations
            $variations = [];
            $variation_ids = $p->get_children();
            
            foreach ($variation_ids as $var_id) {
                $variation = wc_get_product($var_id);
                if (!$variation) continue;
                
                $var_attributes = [];
                $raw_attributes = $variation->get_attributes();
                
                foreach ($raw_attributes as $key => $value) {
                    // Remove 'attribute_' prefix and taxonomy prefix if present
                    $clean_key = str_replace('attribute_', '', $key);
                    $clean_key = str_replace('pa_', '', $clean_key);
                    
                    // Try to get proper attribute name
                    $attr_name = $clean_key;
                    foreach ($attributes as $parent_attr) {
                        $check_name = str_replace(' ', '-', strtolower($parent_attr['name']));
                        if ($check_name === $clean_key || $parent_attr['name'] === $clean_key) {
                            $attr_name = $parent_attr['label'];
                            break;
                        }
                    }
                    
                    $var_attributes[$attr_name] = $value;
                }
                
                // Get cost price from meta
                $cost_price = get_post_meta($var_id, '_purchase_price', true);
                
                $variations[] = [
                    'id' => $var_id,
                    'sku' => $variation->get_sku(),
                    'regular_price' => $variation->get_regular_price(),
                    'sale_price' => $variation->get_sale_price(),
                    'cost_price' => $cost_price ? floatval($cost_price) : '',
                    'stock_quantity' => $variation->get_stock_quantity(),
                    'attributes' => $var_attributes,
                    'barcodes' => function_exists('bizmart_get_product_barcodes') ? bizmart_get_product_barcodes($var_id) : [],
                ];
            }
            $edit_data['variations'] = $variations;
        }
    }
}
?>
<?php
wp_enqueue_script('bizmart-products-edit-js', BIZMART_CORE_URL . 'assets/products-edit.js', ['jquery', 'bizmart-products-js'], BIZMART_CORE_VERSION, true);
wp_localize_script('bizmart-products-edit-js', 'BizmartEditConfig', [
    'isEdit' => $is_edit,
    'editData' => $is_edit ? $edit_data : null,
    'activeTab' => $is_edit ? $edit_active_tab : '',
]);
wp_localize_script('bizmart-products-js', 'BizmartProductsData', [
    'adminLang' => bizmart_admin_lang(),
    'ajaxUrl'   => admin_url('admin-ajax.php'),
    'nonce'      => wp_create_nonce('bizmart-ajax-nonce'),
]);
?>
<!-- Dead style block removed -->

    <?php
    $current_view = isset($_GET['view']) ? sanitize_text_field(wp_unslash($_GET['view'])) : 'list';
    // Ensure valid view
    if (!in_array($current_view, ['create', 'list', 'alerts'])) {
        $current_view = 'list';
    }
    if ($is_edit) {
        $current_view = 'create';
    }
    
    // Tab URLs
    $base_url   = remove_query_arg(['view', 'paged', 's', 'action', 'id']);
    $create_url = add_query_arg('view', 'create', $base_url);
    $list_url   = add_query_arg('view', 'list', $base_url);
    $alerts_url = add_query_arg('view', 'alerts', $base_url);
    ?>

    <div class="wrap" style="padding: 20px 40px; box-sizing: border-box;">
    <?php if (!empty($edit_data) && !empty($edit_data['id'])) : ?>
        <input type="hidden" id="bizmart-edit-product-id" value="<?php echo esc_attr((int)$edit_data['id']); ?>">
        <input type="hidden" id="bizmart-edit-product-type" value="<?php echo esc_attr($edit_data['type'] ?? ''); ?>">
    <?php endif; ?>

    <div class="biz-products-container" style="flex-direction: column; gap: 0;">
        <!-- Header Tabs -->
        <div style="display: flex; gap: 20px; border-bottom: 2px solid #e5e7eb; padding-bottom: 0px; margin-bottom: 30px;">
            <a href="<?php echo esc_url($list_url); ?>" 
               style="text-decoration: none; padding: 10px 20px; font-weight: 600; font-size: 16px; border-bottom: 3px solid <?php echo esc_attr($current_view === 'list' ? '#4f46e5' : 'transparent'); ?>; color: <?php echo esc_attr($current_view === 'list' ? '#4f46e5' : '#6b7280'); ?>; transition: all 0.2s; margin-bottom: -2px;">
                📦 <?php echo esc_html(bizmart_text('Product List', 'Liste Produits', 'قائمة المنتجات')); ?>
            </a>
            <a href="<?php echo esc_url($alerts_url); ?>" 
               style="text-decoration: none; padding: 10px 20px; font-weight: 600; font-size: 16px; border-bottom: 3px solid <?php echo esc_attr($current_view === 'alerts' ? '#4f46e5' : 'transparent'); ?>; color: <?php echo esc_attr($current_view === 'alerts' ? '#4f46e5' : '#6b7280'); ?>; transition: all 0.2s; margin-bottom: -2px;">
                ⚠️ <?php echo esc_html(bizmart_text('Stock Alerts', 'Alertes Stock', 'تنبيهات المخزون')); ?>
            </a>
            <a href="<?php echo esc_url($create_url); ?>" 
               style="text-decoration: none; padding: 10px 20px; font-weight: 600; font-size: 16px; border-bottom: 3px solid <?php echo esc_attr($current_view === 'create' ? '#4f46e5' : 'transparent'); ?>; color: <?php echo esc_attr($current_view === 'create' ? '#4f46e5' : '#6b7280'); ?>; transition: all 0.2s; margin-bottom: -2px;">
                <?php if ($is_edit) : ?>
                    ✏️ <?php echo esc_html(bizmart_text('Edit Product', 'Modifier Produit', 'تعديل المنتج')); ?>
                <?php else : ?>
                    🚀 <?php echo esc_html(bizmart_text('Create Product', 'Créer un produit', 'إنشاء منتج')); ?>
                <?php endif; ?>
            </a>
        </div>

        <div class="biz-stats-grid">
            <div class="biz-stat-card" title="<?php echo esc_attr(bizmart_text('Total number of published products', 'Nombre total de produits publiés', 'العدد الإجمالي للمنتجات المنشورة')); ?>">
                <div class="biz-stat-value"><?php echo intval($total_products); ?></div>
                <div class="biz-stat-label"><?php echo esc_html(bizmart_text('Total Products', 'Total Produits', 'إجمالي المنتجات')); ?></div>
            </div>
            <div class="biz-stat-card neutral" title="<?php echo esc_attr(bizmart_text('Stock Value Details', 'Détails Valeur Stock', 'تفاصيل قيمة المخزون')); ?>">
                <div class="biz-stat-label">
                    <div style="font-weight: 700; text-transform: uppercase; font-size: 13px; margin-bottom: 6px; letter-spacing: 0.5px;"><?php echo esc_html(bizmart_text('Stock Value', 'Valeur du Stock', 'قيمة المخزون')); ?></div>
                    <div><?php echo esc_html(bizmart_text('Vente:', 'Vente :', 'البيع:')); ?> <strong><?php echo wp_kses_post(wc_price($stock_value)); ?></strong></div>
                    <div><?php echo esc_html(bizmart_text('Achat:', 'Achat :', 'الشراء:')); ?> <strong><?php echo wp_kses_post(wc_price($stock_purchase_value)); ?></strong></div>
                </div>
            </div>
            <div class="biz-stat-card" style="background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);" title="<?php echo esc_attr(bizmart_text('Total items currently in stock (published)', 'Total d\'articles actuellement en stock (publiés)', 'إجمالي العناصر المتوفرة حالياً (المنشورة)')); ?>">
                <div class="biz-stat-value"><?php echo number_format($total_stock, 0); ?></div>
                <div class="biz-stat-label"><?php echo esc_html(bizmart_text('Items in Stock', 'Articles en Stock', 'عناصر في المخزون')); ?></div>
            </div>
            <div class="biz-stat-card positive">
                <div class="biz-stat-value"><?php echo intval($type_counts['variable']); ?></div>
                <div class="biz-stat-label"><?php echo esc_html(bizmart_text('Variable', 'Variables', 'متغير')); ?></div>
            </div>
        </div>

        <?php if ($current_view === 'list') : ?>
            <div class="biz-products-main" style="width: 100%;">
                <?php include plugin_dir_path(__FILE__) . 'products-list.php'; ?>
            </div>
        <?php elseif ($current_view === 'alerts') : ?>
            <div class="biz-products-main" style="width: 100%;">
                <?php
                // stock-alerts.php is a core feature
                $alerts_file = BIZMART_CORE_DIR . 'admin/stock-alerts.php';
                if (file_exists($alerts_file)) {
                    include $alerts_file;
                }
                ?>
            </div>
        <?php else : ?>

        <?php if ($is_edit) : ?>
            <div style="margin-bottom: 24px; padding: 15px 20px; background: #f0f9ff; border-radius: 12px; border-left: 4px solid #0ea5e9;">
                <h3 style="margin:0; color:#0369a1; font-size: 16px;">✏️ <?php echo wp_kses_post(sprintf(bizmart_text('Editing: %s', 'Modification de : %s', 'تعديل: %s'), '<strong>' . esc_html($edit_name) . '</strong>')); ?></h3>
            </div>
        <?php endif; ?>

        <!-- Original Product Creation Content Starts Here -->
        <div style="display: flex; gap: 30px;">
            <div class="biz-products-main">
                <div class="biz-card">
                    <h1 style="margin: 0 0 24px 0; color: #1f2937;">
                        <?php if ($is_edit) : ?>
                            ✏️ <?php echo esc_html(bizmart_text('Edit Product', 'Modifier Produit', 'تعديل المنتج')); ?>
                        <?php else : ?>
                            🚀 <?php echo esc_html(bizmart_text('Create Product', 'Créer un produit', 'إنشاء منتج')); ?>
                        <?php endif; ?>
                    </h1>
                <div style="display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:30px;">
                    <p style="color: #6b7280; margin:0;">
                        <?php if ($is_edit) : ?>
                            <?php echo esc_html(bizmart_text('Update the selected product without leaving the product workspace.', 'Mettez à jour le produit sélectionné sans quitter l\'espace produit.', 'حدّث المنتج المحدد دون مغادرة مساحة المنتجات.')); ?>
                        <?php else : ?>
                            <?php echo esc_html(bizmart_text('Create complete products with all WooCommerce features', 'Créez des produits complets avec toutes les fonctionnalités WooCommerce', 'أنشئ منتجات كاملة بجميع ميزات WooCommerce')); ?>
                        <?php endif; ?>
                    </p>
                    <div>
                        <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" style="display:inline-block;margin:0;">
                            <?php wp_nonce_field('bizmart_export_products_nonce','bizmart_export_products_nonce_field'); ?>
                            <input type="hidden" name="action" value="bizmart_export_products">
                            <button type="submit" class="biz-btn biz-btn-secondary">📤 <?php echo esc_html(bizmart_text('Export data', 'Exporter Données', 'تصدير البيانات')); ?></button>
                        </form>
                    </div>
                </div>
                

                
                <!-- Tabs -->
                <!-- Dead script block removed -->
                <div class="biz-tabs">
                    <div class="biz-tab active" data-tab="simple" onclick="BizProducts.switchTab('simple')">📦 <?php echo esc_html(bizmart_text('Simple', 'Simple', 'بسيط')); ?></div>
                    <div class="biz-tab" data-tab="variable" onclick="BizProducts.switchTab('variable')">🎯 <?php echo esc_html(bizmart_text('Variable', 'Variable', 'متغير')); ?></div>
                    <div class="biz-tab" data-tab="grouped" onclick="BizProducts.switchTab('grouped')">📦 <?php echo esc_html(bizmart_text('Grouped', 'Groupé', 'مجمّع')); ?></div>
                    <div class="biz-tab" data-tab="external" onclick="BizProducts.switchTab('external')">🔗 <?php echo esc_html(bizmart_text('External', 'Externe', 'خارجي')); ?></div>
                    <div class="biz-tab" data-tab="digital" onclick="BizProducts.switchTab('digital')">💾 <?php echo esc_html(bizmart_text('Digital', 'Digital', 'رقمي')); ?></div>
                </div>
                
                <!-- Simple Product Tab -->
                <div id="biz-tab-simple" class="biz-tab-content active">
                    <form id="biz-form-simple">
                        <div class="biz-workspace-layout">
                            <!-- Left Column: Main Content (70%) -->
                            <div class="biz-workspace-main">
                                <!-- Basic Information -->
                                <div class="biz-section">
                                    <h3 class="biz-section-title">📋 <?php echo esc_html(bizmart_text('Basic Information', 'Informations de Base', 'المعلومات الأساسية')); ?></h3>
                                    <div class="biz-form-row-name-sku">
                                        <div class="biz-form-group">
                                            <label class="required"><?php echo esc_html(bizmart_text('Product Name', 'Nom du produit', 'اسم المنتج')); ?></label>
                                            <input type="text" id="biz-simple-name" class="biz-input" placeholder="<?php echo esc_attr(bizmart_text('Descriptive product name', 'Nom descriptif du produit', 'اسم المنتج الوصفي')); ?>" required>
                                        </div>
                                        <div class="biz-form-group">
                                            <label class="required"><?php echo esc_html(bizmart_text('SKU', 'SKU', 'رمز المنتج')); ?></label>
                                            <input type="text" id="biz-simple-sku" class="biz-input" placeholder="<?php echo esc_attr(bizmart_text('Unique reference', 'Référence unique', 'مرجع فريد')); ?>" required>
                                        </div>
                                    </div>
                                    
                                    <div class="biz-form-grid-3">
                                        <div class="biz-form-group">
                                            <label class="required"><?php echo esc_html(bizmart_text('Regular Price', 'Prix régulier', 'السعر العادي')); ?></label>
                                            <div class="biz-input-prefix-wrapper">
                                                <span class="biz-input-prefix">$</span>
                                                <input type="number" step="0.01" min="0" id="biz-simple-regular-price" class="biz-input biz-price-input" placeholder="0.00" required>
                                            </div>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Sale Price', 'Prix promotionnel', 'سعر التخفيض')); ?></label>
                                            <div class="biz-input-prefix-wrapper">
                                                <span class="biz-input-prefix">$</span>
                                                <input type="number" step="0.01" min="0" id="biz-simple-sale-price" class="biz-input biz-price-input" placeholder="0.00">
                                            </div>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Cost Price', "Prix d'achat (coût)", 'سعر التكلفة')); ?></label>
                                            <div class="biz-input-prefix-wrapper">
                                                <span class="biz-input-prefix">$</span>
                                                <input type="number" step="0.01" min="0" id="biz-simple-cost-price" class="biz-input biz-price-input" placeholder="0.00">
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Profit Calculator Intel (instant feedback) -->
                                    <div id="biz-simple-profit-intel" style="display: none; padding: 15px 20px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; margin-top: 10px;">
                                        <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
                                            <span style="font-weight: 600; font-size: 13px; color: #475569; text-transform: uppercase; letter-spacing: 0.5px;">Profit Intel</span>
                                            <span id="biz-simple-profit-status" style="font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 9999px;"></span>
                                        </div>
                                        <div class="biz-form-grid-3" style="gap: 12px;">
                                            <div>
                                                <div style="font-size: 12px; color: #64748b;">Net Profit</div>
                                                <div id="biz-simple-profit-val" style="font-size: 16px; font-weight: 700; color: #1e293b;">0.00</div>
                                            </div>
                                            <div>
                                                <div style="font-size: 12px; color: #64748b;">Profit Margin</div>
                                                <div id="biz-simple-margin-val" style="font-size: 16px; font-weight: 700; color: #1e293b;">0.0%</div>
                                            </div>
                                            <div>
                                                <div style="font-size: 12px; color: #64748b;">Markup</div>
                                                <div id="biz-simple-markup-val" style="font-size: 16px; font-weight: 700; color: #1e293b;">0.0%</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!-- Description -->
                                <div class="biz-section">
                                    <h3 class="biz-section-title">📝 <?php echo esc_html(bizmart_text('Description', 'Description', 'الوصف')); ?></h3>
                                    <div class="biz-form-grid-2">
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Short Description', 'Description courte', 'وصف قصير')); ?></label>
                                            <textarea id="biz-simple-short-description" class="biz-textarea biz-textarea-variable-desc" placeholder="<?php echo esc_attr(bizmart_text('Short description shown in lists...', 'Description concise affichée dans les listes...', 'وصف قصير يظهر في القوائم...')); ?>"></textarea>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Full Description', 'Description complète', 'الوصف الكامل')); ?></label>
                                            <textarea id="biz-simple-description" class="biz-textarea biz-textarea-variable-desc" placeholder="<?php echo esc_attr(bizmart_text('Full product description...', 'Description détaillée du produit...', 'الوصف الكامل للمنتج...')); ?>"></textarea>
                                        </div>
                                    </div>
                                </div>

                                <!-- Categories & Tags -->
                                <div class="biz-section">
                                    <h3 class="biz-section-title">🏷️ <?php echo esc_html(bizmart_text('Categories & tags', 'Catégories & Étiquettes', 'الفئات والعلامات')); ?></h3>
                                    <div class="biz-form-grid-2">
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Categories', 'Catégories', 'الفئات')); ?></label>
                                            <select id="biz-simple-categories" class="biz-multiselect biz-multiselect-compact" multiple>
                                                <?php foreach ($product_categories as $category): ?>
                                                    <option value="<?php echo intval($category->term_id); ?>"><?php echo esc_html($category->name); ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                            <div class="biz-category-creator-inline">
                                                <input type="text" id="biz-simple-new-category" placeholder="<?php echo esc_attr(bizmart_text('New category', 'Nouvelle catégorie', 'فئة جديدة')); ?>">
                                                <button type="button" onclick="BizProducts.createCategory('simple')">+ <?php echo esc_html(bizmart_text('Add', 'Ajouter', 'إضافة')); ?></button>
                                            </div>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Tags', 'Étiquettes', 'العلامات')); ?></label>
                                            <div class="biz-tag-input" id="biz-simple-tags-container">
                                                <input type="text" id="biz-simple-tags-input" placeholder="<?php echo esc_attr(bizmart_text('Add tag & press Enter', 'Ajouter & Entrée', 'أضف علامة واضغط Enter')); ?>">
                                            </div>
                                            <input type="hidden" id="biz-simple-tags">
                                        </div>
                                    </div>
                                </div>

                                <!-- Inventory & Identification (Barcodes) -->
                                <div class="biz-section">
                                    <h3 class="biz-section-title">📦 <?php echo esc_html(bizmart_text('Inventory & Identification', 'Stock & Identification', 'المخزون والتعريف')); ?></h3>
                                    
                                    <!-- Manage Stock Toggle Inline with label -->
                                    <div class="biz-form-group">
                                        <label style="display: flex; align-items: center; cursor: pointer; margin-bottom: 0;">
                                            <span class="biz-switch">
                                                <input type="checkbox" id="biz-simple-manage-stock">
                                                <span class="biz-slider"></span>
                                            </span>
                                            <?php echo esc_html(bizmart_text('Manage stock', 'Gérer le stock', 'إدارة المخزون')); ?>
                                        </label>
                                    </div>

                                    <!-- Stock quantity hidden by default -->
                                    <div class="biz-form-group" id="biz-simple-stock-quantity-group" style="display: none;">
                                        <label><?php echo esc_html(bizmart_text('Stock quantity', 'Quantité en stock', 'كمية المخزون')); ?></label>
                                        <input type="number" min="0" step="1" inputmode="numeric" pattern="[0-9]*" id="biz-simple-stock-quantity" class="biz-input" placeholder="0">
                                    </div>

                                    <!-- Stock Status and Purchase Limit side by side -->
                                    <div class="biz-form-grid-2">
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Stock status', 'Statut du stock', 'حالة المخزون')); ?></label>
                                            <select id="biz-simple-stock-status" class="biz-select">
                                                <option value="instock"><?php echo esc_html(bizmart_text('In stock', 'En stock', 'متوفر')); ?></option>
                                                <option value="outofstock"><?php echo esc_html(bizmart_text('Out of stock', 'Rupture de stock', 'نفد من المخزون')); ?></option>
                                                <option value="onbackorder"><?php echo esc_html(bizmart_text('On backorder', 'Sur commande', 'طلب مسبق')); ?></option>
                                            </select>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Purchase limit', 'Limite par commande', 'حد الشراء')); ?></label>
                                            <input type="number" min="0" id="biz-simple-purchase-limit" class="biz-input" placeholder="<?php echo esc_attr(bizmart_text('Unlimited', 'Illimité', 'غير محدود')); ?>">
                                        </div>
                                    </div>

                                    <!-- Allow Backorders and Sold Individually side by side -->
                                    <div class="biz-form-grid-2">
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Allow backorders?', 'Permettre les précommandes?', 'السماح بالطلبات المسبقة؟')); ?></label>
                                            <select id="biz-simple-backorders" class="biz-select">
                                                <option value="no"><?php echo esc_html(bizmart_text('No', 'Non', 'لا')); ?></option>
                                                <option value="notify"><?php echo esc_html(bizmart_text('Allow, notify customer', 'Autoriser, notifier', 'السماح، إخطار العميل')); ?></option>
                                                <option value="yes"><?php echo esc_html(bizmart_text('Allow', 'Autoriser', 'السماح')); ?></option>
                                            </select>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Sold individually?', 'Vendu individuellement?', 'يُباع بشكل فردي؟')); ?></label>
                                            <select id="biz-simple-sold-individually" class="biz-select">
                                                <option value="no"><?php echo esc_html(bizmart_text('No', 'Non', 'لا')); ?></option>
                                                <option value="yes"><?php echo esc_html(bizmart_text('Yes', 'Oui', 'نعم')); ?></option>
                                            </select>
                                        </div>
                                    </div>

                                    <!-- Barcodes Subdivision inside Inventory section -->
                                    <div style="border-top: 1px solid #f1f5f9; padding-top: 20px; margin-top: 20px;">
                                        <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;">
                                            <label style="font-weight: 600; font-size: 14px; color: #1e293b;">🏷️ <?php echo esc_html(bizmart_text('EAN-13 Product Barcodes', 'Barcodes du Produit', 'باركود المنتج')); ?></label>
                                            <div style="display: flex; gap: 8px;">
                                                <button type="button" class="biz-btn biz-btn-secondary add-barcode-btn" data-product-type="simple" style="padding: 6px 12px; font-size: 12px;">
                                                    ➕ <?php echo esc_html(bizmart_text('Add Barcode', 'Ajouter', 'إضافة باركود')); ?>
                                                </button>
                                                <button type="button" class="biz-btn biz-btn-secondary generate-barcode-btn" data-product-type="simple" style="padding: 6px 12px; font-size: 12px;">
                                                    ⚡ <?php echo esc_html(bizmart_text('Generate EAN-13', 'Générer EAN-13', 'توليد EAN-13')); ?>
                                                </button>
                                            </div>
                                        </div>
                                        
                                        <!-- Card Grid -->
                                        <div class="biz-barcodes-grid biz-barcodes-tbody" data-product-type="simple">
                                            <div class="biz-no-barcodes-placeholder" style="text-align: center; color: #9ca3af; padding: 20px 0; grid-column: 1 / -1;">
                                                <?php echo esc_html(bizmart_text('No barcodes added yet.', 'Aucun code-barres ajouté.', 'لم يتم إضافة باركود بعد.')); ?>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Virtual product toggle inline at the bottom of this section -->
                                    <div style="border-top: 1px solid #f1f5f9; padding-top: 20px; margin-top: 20px;">
                                        <div class="biz-form-group" style="margin-bottom: 0;">
                                            <label style="display: flex; align-items: center; cursor: pointer; margin-bottom: 0;">
                                                <span class="biz-switch">
                                                    <input type="checkbox" id="biz-simple-virtual" onchange="BizProducts.toggleShippingSection(this.checked)">
                                                    <span class="biz-slider"></span>
                                                </span>
                                                <?php echo esc_html(bizmart_text('Virtual product (no shipping)', 'Produit virtuel (pas de livraison)', 'منتج افتراضي (بدون شحن)')); ?>
                                            </label>
                                        </div>
                                    </div>

                                    <!-- Shipping dimensions inline inside Inventory card -->
                                    <div class="biz-shipping-section" id="biz-simple-shipping-section" style="margin-top: 15px;">
                                        <h4 style="margin: 15px 0 10px; color: #374151; font-size: 14px; font-weight: 600;">🚚 <?php echo esc_html(bizmart_text('Shipping Dimensions', 'Dimensions de livraison', 'أبعاد الشحن')); ?></h4>
                                        <div class="biz-form-grid-4">
                                            <div class="biz-form-group">
                                                <label><?php echo esc_html(bizmart_text('Weight (kg)', 'Poids (kg)', 'الوزن (كجم)')); ?></label>
                                                <input type="number" step="0.001" min="0" id="biz-simple-weight" class="biz-input" placeholder="0.00">
                                            </div>
                                            <div class="biz-form-group">
                                                <label><?php echo esc_html(bizmart_text('Length (cm)', 'Longueur (cm)', 'الطول (سم)')); ?></label>
                                                <input type="number" step="0.1" min="0" id="biz-simple-length" class="biz-input" placeholder="0.0">
                                            </div>
                                            <div class="biz-form-group">
                                                <label><?php echo esc_html(bizmart_text('Width (cm)', 'Largeur (cm)', 'العرض (سم)')); ?></label>
                                                <input type="number" step="0.1" min="0" id="biz-simple-width" class="biz-input" placeholder="0.0">
                                            </div>
                                            <div class="biz-form-group">
                                                <label><?php echo esc_html(bizmart_text('Height (cm)', 'Hauteur (cm)', 'الارتفاع (سم)')); ?></label>
                                                <input type="number" step="0.1" min="0" id="biz-simple-height" class="biz-input" placeholder="0.0">
                                            </div>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Shipping Class', 'Classe de livraison', 'فئة الشحن')); ?></label>
                                            <select id="biz-simple-shipping-class" class="biz-select">
                                                <option value=""><?php echo esc_html(bizmart_text('Default', 'Par défaut', 'افتراضي')); ?></option>
                                                <?php foreach ($shipping_classes as $class): ?>
                                                    <option value="<?php echo esc_attr($class->term_id); ?>"><?php echo esc_html($class->name); ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <!-- Linked Products -->
                                <div class="biz-section">
                                    <h3 class="biz-section-title">🔗 <?php echo esc_html(bizmart_text('Linked Products', 'Produits Liés', 'منتجات مرتبطة')); ?></h3>
                                    <div class="biz-form-grid-2">
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Cross-sells', 'Ventes croisées (Cross-sells)', 'بيع متقاطع')); ?></label>
                                            <input type="text" id="biz-simple-cross-sells" class="biz-input" placeholder="<?php echo esc_attr(bizmart_text('SKUs separated by commas', 'SKUs séparés par des virgules', 'رموز SKU مفصولة بفواصل')); ?>">
                                            <small style="color: #6b7280;"><?php echo esc_html(bizmart_text('Frequently bought together', 'Produits fréquemment achetés ensemble', 'يُشترى معًا كثيرًا')); ?></small>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Upsells', 'Ventes incitatives (Upsells)', 'بيع إضافي')); ?></label>
                                            <input type="text" id="biz-simple-upsells" class="biz-input" placeholder="<?php echo esc_attr(bizmart_text('SKUs separated by commas', 'SKUs séparés par des virgules', 'رموز SKU مفصولة بفواصل')); ?>">
                                            <small style="color: #6b7280;"><?php echo esc_html(bizmart_text('Higher quality alternatives', 'Produits similaires de meilleure qualité', 'بدائل ذات جودة أعلى')); ?></small>
                                        </div>
                                    </div>
                                </div>

                                <!-- Advanced Settings -->
                                <div class="biz-section">
                                    <div class="biz-toggle-section" onclick="BizProducts.toggleSection('biz-simple-advanced')">
                                        <h3 class="biz-section-title" style="margin: 0;">⚙️ <?php echo esc_html(bizmart_text('Advanced Settings', 'Paramètres Avancés', 'إعدادات متقدمة')); ?></h3>
                                        <span>▼</span>
                                    </div>
                                    <div id="biz-simple-advanced" class="biz-collapsible-content">
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Purchase note', "Note d'achat", 'ملاحظة الشراء')); ?></label>
                                            <textarea id="biz-simple-purchase-note" class="biz-textarea biz-textarea-small" placeholder="<?php echo esc_attr(bizmart_text('Message after purchase...', 'Message après achat...', 'رسالة بعد الشراء...')); ?>"></textarea>
                                        </div>
                                        <div class="biz-form-grid-2">
                                            <div class="biz-form-group">
                                                <label><?php echo esc_html(bizmart_text('Menu order', 'Ordre de menu', 'ترتيب القائمة')); ?></label>
                                                <input type="number" id="biz-simple-menu-order" class="biz-input" placeholder="0">
                                            </div>
                                            <div class="biz-form-group">
                                                <label><?php echo esc_html(bizmart_text('Reviews', 'Commentaires', 'التقييمات')); ?></label>
                                                <select id="biz-simple-reviews" class="biz-select">
                                                    <option value="open"><?php echo esc_html(bizmart_text('Enable', 'Autoriser', 'تفعيل')); ?></option>
                                                    <option value="closed"><?php echo esc_html(bizmart_text('Disable', 'Fermer', 'تعطيل')); ?></option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="biz-workspace-sidebar">
                                <!-- Status Card -->
                                <div class="biz-section">
                                    <h3 class="biz-section-title">📊 <?php echo esc_html(bizmart_text('Status & Visibility', 'Statut & Visibilité', 'الحالة والظهور')); ?></h3>
                                    <div class="biz-form-group">
                                        <label><?php echo esc_html(bizmart_text('Status', 'Statut', 'الحالة')); ?></label>
                                        <select id="biz-simple-status" class="biz-select">
                                            <option value="publish"><?php echo esc_html(bizmart_text('Publish', 'Publié', 'نشر')); ?></option>
                                            <option value="draft"><?php echo esc_html(bizmart_text('Draft', 'Brouillon', 'مسودة')); ?></option>
                                        </select>
                                    </div>
                                </div>

                                <!-- Images -->
                                <div class="biz-section">
                                    <h3 class="biz-section-title">🖼️ <?php echo esc_html(bizmart_text('Product Images', 'Images du Produit', 'صور المنتج')); ?></h3>
                                    <div class="biz-form-grid-2">
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Main image', 'Image principale', 'الصورة الرئيسية')); ?></label>
                                            <div class="biz-image-upload-area-compact" onclick="BizProducts.openMediaUploader('biz-simple-image-id', 'biz-simple-image-preview')">
                                                <div class="biz-upload-icon">📷</div>
                                                <p class="biz-upload-label"><?php echo esc_html(bizmart_text('Click to upload', 'Cliquez pour télécharger', 'انقر للرفع')); ?></p>
                                            </div>
                                            <input type="hidden" id="biz-simple-image-id">
                                            <img id="biz-simple-image-preview" class="biz-image-preview">
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Image gallery', "Galerie d'images", 'معرض الصور')); ?></label>
                                            <div class="biz-image-upload-area-compact" onclick="BizProducts.openGalleryUploader('simple')">
                                                <div class="biz-upload-icon">🖼️</div>
                                                <p class="biz-upload-label"><?php echo esc_html(bizmart_text('Click to add', 'Cliquez pour ajouter', 'انقر للإضافة')); ?></p>
                                            </div>
                                            <div class="biz-gallery-images" id="biz-simple-gallery"></div>
                                            <input type="hidden" id="biz-simple-gallery-ids">
                                        </div>
                                    </div>
                                </div>


                            </div>
                        </div>

                        <!-- Sticky Save/Actions Bar -->
                        <div class="biz-sticky-save-bar">
                            <div style="display: flex; gap: 12px;">
                                <button type="button" class="biz-btn biz-btn-secondary" onclick="BizProducts.resetForm('simple')">
                                    ↻ <?php echo esc_html(bizmart_text('Reset', 'Réinitialiser', 'إعادة تعيين')); ?>
                                </button>
                                <button type="button" class="biz-btn biz-btn-secondary" onclick="BizProducts.saveProduct('simple','draft', this)">
                                    💾 <?php echo esc_html(bizmart_text('Save draft', 'Enregistrer brouillon', 'حفظ كمسودة')); ?>
                                </button>
                            </div>
                            <div>
                                <button type="button" class="biz-btn biz-btn-success" onclick="BizProducts.createSimpleProduct(this)">
                                    <span style="font-size: 16px; margin-right: 6px;">✅</span>
                                    <?php echo esc_html((!empty($edit_data) && ($edit_data['type'] ?? '')==='simple') ? bizmart_text('Update product', 'Mettre à jour le produit', 'تحديث المنتج') : bizmart_text('Create product', 'Créer le produit', 'إنشاء المنتج')); ?>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                
                <!-- Variable Product Tab -->
                <div id="biz-tab-variable" class="biz-tab-content">
                    <form id="biz-form-variable">
                        <!-- Basic Information -->
                        <div class="biz-section">
                            <h3 class="biz-section-title">📋 <?php echo esc_html(bizmart_text('Basic information', 'Informations de Base', 'المعلومات الأساسية')); ?></h3>
                            <div class="biz-form-row-name-sku">
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('Product name', 'Nom du produit', 'اسم المنتج')); ?></label>
                                    <input type="text" id="biz-variable-name" class="biz-input" placeholder="<?php echo esc_attr(bizmart_text('Product line name', 'Nom de la gamme', 'اسم خط المنتج')); ?>" required>
                                </div>
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('Parent SKU', 'SKU parent', 'SKU الرئيسي')); ?></label>
                                    <input type="text" id="biz-variable-sku" class="biz-input" placeholder="<?php echo esc_attr(bizmart_text('Line SKU', 'SKU de la gamme', 'SKU الخط')); ?>" required>
                                </div>
                            </div>
                            
                            <div class="biz-form-grid-2">
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Short description', 'Description courte', 'وصف مختصر')); ?></label>
                                    <textarea id="biz-variable-short-description" class="biz-textarea biz-textarea-variable-desc" placeholder="<?php echo esc_attr(bizmart_text('Short description...', 'Description concise...', 'وصف مختصر...')); ?>"></textarea>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Full description', 'Description complète', 'الوصف الكامل')); ?></label>
                                    <textarea id="biz-variable-description" class="biz-textarea biz-textarea-variable-desc" placeholder="<?php echo esc_attr(bizmart_text('Detailed description...', 'Description détaillée...', 'وصف تفصيلي...')); ?>"></textarea>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Categories & Tags -->
                        <div class="biz-section" style="padding: 12px 20px !important;">
                            <h3 class="biz-section-title">🏷️ <?php echo esc_html(bizmart_text('Categories & tags', 'Catégories & Étiquettes', 'الفئات والعلامات')); ?></h3>
                            <div class="biz-form-grid-2">
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Categories', 'Catégories', 'الفئات')); ?></label>
                                    <select id="biz-variable-categories" class="biz-multiselect biz-multiselect-compact" multiple>
                                        <?php foreach ($product_categories as $category): ?>
                                            <option value="<?php echo intval($category->term_id); ?>"><?php echo esc_html($category->name); ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                    <div class="biz-category-creator-inline">
                                        <input type="text" id="biz-variable-new-category" placeholder="<?php echo esc_attr(bizmart_text('New category', 'Nouvelle catégorie', 'فئة جديدة')); ?>">
                                        <button type="button" onclick="BizProducts.createCategory('variable')">+ <?php echo esc_html(bizmart_text('Add', 'Ajouter', 'إضافة')); ?></button>
                                    </div>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Tags', 'Étiquettes (Tags)', 'العلامات')); ?></label>
                                    <div class="biz-tag-input" id="biz-variable-tags-container">
                                        <input type="text" id="biz-variable-tags-input" placeholder="<?php echo esc_attr(bizmart_text('Add a tag, press Enter', 'Ajouter une étiquette, appuyez sur Entrée', 'أضف علامة، اضغط Enter')); ?>">
                                    </div>
                                    <input type="hidden" id="biz-variable-tags">
                                </div>
                            </div>
                        </div>
                        
                        <!-- Attributes -->
                        <div class="biz-section">
                            <h3 class="biz-section-title">🎨 <?php echo esc_html(bizmart_text('Attributes', 'Attributs', 'السمات')); ?></h3>
                            <div id="biz-variable-attributes">
                                <?php
                                // Get all product attributes
                                $attribute_taxonomies = wc_get_attribute_taxonomies();
                                ?>
                                <div class="biz-attribute-row" data-id="1">
                                    <div class="biz-form-grid-2">
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Select an existing attribute', 'Sélectionner un attribut existant', 'اختر سمة موجودة')); ?></label>
                                            <select class="biz-select existing-attribute-select" onchange="BizProducts.onExistingAttributeSelect(this)">
                                                <option value="">-- <?php echo esc_html(bizmart_text('Choose an existing attribute', 'Choisir un attribut existant', 'اختر سمة موجودة')); ?> --</option>
                                                <?php foreach ($attribute_taxonomies as $tax): ?>
                                                    <option value="<?php echo esc_attr($tax->attribute_name); ?>" data-label="<?php echo esc_attr($tax->attribute_label); ?>">
                                                        <?php echo esc_html($tax->attribute_label); ?>
                                                    </option>
                                                <?php endforeach; ?>
                                                <option value="new">+ <?php echo esc_html(bizmart_text('Create a new attribute', 'Créer un nouvel attribut', 'إنشاء سمة جديدة')); ?></option>
                                            </select>
                                        </div>
                                        <div class="biz-form-group">
                                            <label><?php echo esc_html(bizmart_text('Or create a new attribute', 'Ou créer un nouvel attribut', 'أو أنشئ سمة جديدة')); ?></label>
                                            <input type="text" class="biz-input attribute-name" placeholder="<?php echo esc_attr(bizmart_text('Attribute name (e.g. Color, Size)', "Nom de l'attribut (ex: Couleur, Taille)", 'اسم السمة (مثال: اللون، المقاس)')); ?>" style="display: none;">
                                        </div>
                                    </div>
                                    
                                    <div class="biz-form-group" style="margin-top: 10px; width: 100%;">
                                        <label><?php echo esc_html(bizmart_text('Attribute values', "Valeurs de l'attribut", 'قيم السمة')); ?></label>
                                        <div class="biz-tag-input" id="biz-attribute-values-1">
                                            <input type="text" class="biz-attribute-values-input" placeholder="<?php echo esc_attr(bizmart_text('Add a value, press Enter (Separate with commas)', 'Ajouter une valeur, Entrée (Séparer par des virgules)', 'أضف قيمة، اضغط Enter (افصل بفواصل)')); ?>">
                                        </div>
                                        <input type="hidden" class="attribute-values" id="biz-attribute-values-hidden-1">
                                    </div>

                                    <div class="biz-attr-inline-row">
                                        <div class="biz-attr-inline-left">
                                            <label style="display: flex; align-items: center; cursor: pointer; gap: 8px; font-size: 12px; margin: 0;">
                                                <span class="biz-switch">
                                                    <input type="checkbox" class="attribute-visible" checked>
                                                    <span class="biz-slider"></span>
                                                </span>
                                                <?php echo esc_html(bizmart_text('Visible on product page', 'Visible sur la page produit', 'مرئي على صفحة المنتج')); ?>
                                             </label>
                                             <label style="display: flex; align-items: center; cursor: pointer; gap: 8px; font-size: 12px; margin: 0;">
                                                 <span class="biz-switch">
                                                     <input type="checkbox" class="attribute-variation" checked>
                                                     <span class="biz-slider"></span>
                                                 </span>
                                                 <?php echo esc_html(bizmart_text('Used for variations', 'Utilisé pour les variations', 'مستخدم للتنويعات')); ?>
                                            </label>
                                        </div>
                                        <div class="biz-attr-inline-right">
                                            <button type="button" class="biz-attr-add-btn" onclick="BizProducts.addAttribute()">+ <?php echo esc_html(bizmart_text('Add another attribute', 'Ajouter un autre attribut', 'إضافة سمة أخرى')); ?></button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Variations Section -->
                        <div class="biz-section">
                            <div class="biz-toggle-section" onclick="BizProducts.toggleSection('biz-variations-section')">
                                <h3 class="biz-section-title">🎯 <?php echo esc_html(bizmart_text('Variations', 'Variations', 'التنويعات')); ?></h3>
                                <span>▼</span>
                            </div>
                            <div id="biz-variations-section" class="biz-collapsible-content">
                                <div style="margin-bottom: 20px;">
                                    <button type="button" class="biz-btn" onclick="BizProducts.generateVariations()">
                                        <span style="font-size: 18px;">⚡</span>
                                        <?php echo esc_html(bizmart_text('Generate automatically', 'Générer automatiquement', 'إنشاء تلقائي')); ?>
                                    </button>
                                    <button type="button" class="biz-btn biz-btn-secondary" onclick="BizProducts.addVariation()">
                                        <span style="font-size: 18px;">+</span>
                                        <?php echo esc_html(bizmart_text('Add manually', 'Ajouter manuellement', 'إضافة يدوياً')); ?>
                                    </button>
                                </div>
                                
                                <div id="biz-variations-container">
                                    <!-- Variations will be added here -->
                                </div>
                            </div>
                        </div>
                        
                        <!-- Images -->
                        <div class="biz-section">
                            <h3 class="biz-section-title">🖼️ <?php echo esc_html(bizmart_text('Product images', 'Images du Produit', 'صور المنتج')); ?></h3>
                            <div class="biz-form-group">
                                <label><?php echo esc_html(bizmart_text('Main image', 'Image principale', 'الصورة الرئيسية')); ?></label>
                                <div class="biz-image-upload-area-compact" onclick="BizProducts.openMediaUploader('biz-variable-image-id', 'biz-variable-image-preview')">
                                    <div class="biz-upload-icon">📷</div>
                                    <p class="biz-upload-label"><?php echo esc_html(bizmart_text('Click to upload', 'Cliquez pour télécharger', 'انقر للرفع')); ?></p>
                                </div>
                                <input type="hidden" id="biz-variable-image-id">
                                <img id="biz-variable-image-preview" class="biz-image-preview">
                            </div>
                        </div>
                        
                        <!-- Pricing -->
                        <div class="biz-section">
                            <h3 class="biz-section-title">💰 <?php echo esc_html(bizmart_text('Base pricing', 'Prix de Base', 'التسعير الأساسي')); ?></h3>
                            <div class="biz-form-grid-3">
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Base regular price', 'Prix régulier de base', 'السعر العادي الأساسي')); ?></label>
                                    <div class="biz-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-variable-base-regular" class="biz-input" placeholder="0.00">
                                    </div>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Base sale price', 'Prix promotionnel de base', 'سعر التخفيض الأساسي')); ?></label>
                                    <div class="biz-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-variable-base-sale" class="biz-input" placeholder="0.00">
                                    </div>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Base cost price', "Prix d'achat de base", 'سعر التكلفة الأساسي')); ?></label>
                                    <div class="biz-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-variable-base-cost" class="biz-input" placeholder="0.00">
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Submit -->
                        <div class="biz-sticky-save-bar" style="display: flex; gap: 12px; margin-top: 20px; align-items: center; border-top: 1px solid var(--biz-border); padding-top: 16px;">
                            <button type="button" class="biz-btn biz-btn-success" onclick="BizProducts.createVariableProduct(this)">
                                <span style="font-size: 16px;">🎯</span>
                                <?php echo esc_html(bizmart_text('Create variable product', 'Créer produit variable', 'إنشاء منتج متغير')); ?>
                            </button>
                            <button type="button" class="biz-btn biz-btn-ghost" onclick="BizProducts.resetForm('variable')">
                                ↻ <?php echo esc_html(bizmart_text('Reset', 'Réinitialiser', 'إعادة تعيين')); ?>
                            </button>
                        </div>
                    </form>
                </div>
                
                <!-- Grouped Product Tab -->
                <div id="biz-tab-grouped" class="biz-tab-content">
                    <form id="biz-form-grouped">
                        <div class="biz-section">
                            <h3 class="biz-section-title">📦 <?php echo esc_html(bizmart_text('Grouped product', 'Produit Groupé', 'منتج مجمّع')); ?></h3>
                            <p style="color: #6b7280; margin-bottom: 12px; font-size: 12px; margin-top: 0;"><?php echo esc_html(bizmart_text('Create a grouped product that contains multiple simple products', 'Créez un produit groupé qui contient plusieurs produits simples', 'أنشئ منتجاً مجمّعاً يحتوي على عدة منتجات بسيطة')); ?></p>
                            
                            <div class="biz-form-row-name-sku" style="gap: 12px;">
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('Group name', 'Nom du groupe', 'اسم المجموعة')); ?></label>
                                    <input type="text" id="biz-grouped-name" class="biz-input" placeholder="<?php echo esc_attr(bizmart_text('Bundle/kit name', 'Nom du pack/kit', 'اسم الحزمة/الطقم')); ?>" required>
                                </div>
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('Group SKU', 'SKU du groupe', 'SKU المجموعة')); ?></label>
                                    <input type="text" id="biz-grouped-sku" class="biz-input" placeholder="SKU-GROUPE" required>
                                </div>
                            </div>
                            
                            <div class="biz-form-group">
                                <label><?php echo esc_html(bizmart_text('Description', 'Description', 'الوصف')); ?></label>
                                <textarea id="biz-grouped-description" class="biz-textarea biz-textarea-variable-desc" placeholder="<?php echo esc_attr(bizmart_text('Bundle description...', 'Description du pack...', 'وصف الحزمة...')); ?>"></textarea>
                            </div>
                            
                            <div class="biz-form-group">
                                <label><?php echo esc_html(bizmart_text('Products to include', 'Produits à inclure', 'المنتجات المطلوب تضمينها')); ?></label>
                                <select id="biz-grouped-products" class="biz-multiselect" multiple data-placeholder="<?php echo esc_attr(bizmart_text('Select the simple products to include in this group', 'Sélectionnez les produits simples à inclure dans ce groupe', 'اختر المنتجات البسيطة لتضمينها في المجموعة')); ?>">
                                    <?php foreach ($simple_products as $product): ?>
                                        <option value="<?php echo esc_attr($product->get_id()); ?>">
                                            <?php echo esc_html($product->get_name()); ?> (<?php echo esc_html($product->get_sku()); ?>)
                                        </option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            
                            <!-- Categories -->
                            <div class="biz-form-group">
                                <label><?php echo esc_html(bizmart_text('Categories', 'Catégories', 'الفئات')); ?></label>
                                <select id="biz-grouped-categories" class="biz-multiselect biz-multiselect-compact" multiple>
                                    <?php foreach ($product_categories as $category): ?>
                                        <option value="<?php echo intval($category->term_id); ?>"><?php echo esc_html($category->name); ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            
                            <!-- Image -->
                            <div class="biz-form-group">
                                <label><?php echo esc_html(bizmart_text('Group image', 'Image du groupe', 'صورة المجموعة')); ?></label>
                                <div class="biz-image-upload-area-compact" onclick="BizProducts.openMediaUploader('biz-grouped-image-id', 'biz-grouped-image-preview')">
                                    <div class="biz-upload-icon">📷</div>
                                    <p class="biz-upload-label"><?php echo esc_html(bizmart_text('Click to upload', 'Cliquez pour télécharger', 'انقر للرفع')); ?></p>
                                </div>
                                <input type="hidden" id="biz-grouped-image-id">
                                <img id="biz-grouped-image-preview" class="biz-image-preview">
                            </div>
                            
                            <div class="biz-sticky-save-bar" style="display: flex; gap: 12px; margin-top: 20px; align-items: center; border-top: 1px solid var(--biz-border); padding-top: 16px;">
                                <button type="button" class="biz-btn biz-btn-success" onclick="BizProducts.createGroupedProduct(this)">
                                    <span style="font-size: 16px;">📦</span>
                                    <?php echo esc_html(bizmart_text('Create grouped product', 'Créer produit groupé', 'إنشاء منتج مجمّع')); ?>
                                </button>
                                <button type="button" class="biz-btn biz-btn-ghost" onclick="BizProducts.resetForm('grouped')">
                                    ↻ <?php echo esc_html(bizmart_text('Reset', 'Réinitialiser', 'إعادة تعيين')); ?>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                
                <!-- External/Affiliate Product Tab -->
                <div id="biz-tab-external" class="biz-tab-content">
                    <form id="biz-form-external">
                        <div class="biz-zw-section">
                            <h3 class="biz-section-title">🔗 <?php echo esc_html(bizmart_text('External/Affiliate product', 'Produit Externe/Affilié', 'منتج خارجي/تابع')); ?></h3>
                            <p style="color: #6b7280; margin-bottom: 10px; font-size: 11px; margin-top: 0; line-height: 1.3;"><?php echo esc_html(bizmart_text('Product sold on another site (Amazon, etc.)', 'Produit vendu sur un autre site (Amazon, etc.)', 'منتج يُباع على موقع آخر (أمازون، إلخ.)')); ?></p>
                            
                            <div class="biz-zw-grid-2-2" style="margin-bottom: 10px;">
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('Product name', 'Nom du produit', 'اسم المنتج')); ?></label>
                                    <input type="text" id="biz-external-name" class="biz-input biz-zw-input" placeholder="<?php echo esc_attr(bizmart_text('Product name', 'Nom du produit', 'اسم المنتج')); ?>" required>
                                </div>
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('SKU', 'SKU', 'SKU')); ?></label>
                                    <input type="text" id="biz-external-sku" class="biz-input biz-zw-input" placeholder="<?php echo esc_attr(bizmart_text('Reference', 'Référence', 'المرجع')); ?>" required>
                                </div>
                            </div>
                            
                            <div class="biz-zw-grid-2-2" style="margin-bottom: 10px;">
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('Product URL', 'URL du produit', 'رابط المنتج')); ?></label>
                                    <input type="url" id="biz-external-url" class="biz-input biz-zw-input" placeholder="https://" required>
                                </div>
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('Button text', 'Bouton texte', 'نص الزر')); ?></label>
                                    <input type="text" id="biz-external-button" class="biz-input biz-zw-input" placeholder="<?php echo esc_attr(bizmart_text('e.g. Buy on Amazon', 'ex: Acheter sur Amazon', 'مثال: اشترِ من أمازون')); ?>" value="<?php echo esc_attr(bizmart_text('Buy now', 'Acheter maintenant', 'اشترِ الآن')); ?>" required>
                                </div>
                            </div>
                            
                            <div class="biz-zw-grid-3" style="margin-bottom: 10px;">
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Price', 'Prix', 'السعر')); ?></label>
                                    <div class="biz-zw-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-external-price" class="biz-input biz-zw-input" placeholder="0.00">
                                    </div>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Sale price', 'Prix promotionnel', 'سعر التخفيض')); ?></label>
                                    <div class="biz-zw-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-external-sale-price" class="biz-input biz-zw-input" placeholder="0.00">
                                    </div>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Cost price', "Prix d'achat", 'سعر التكلفة')); ?></label>
                                    <div class="biz-zw-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-external-cost-price" class="biz-input biz-zw-input" placeholder="0.00">
                                    </div>
                                </div>
                            </div>
                            
                            <div class="biz-zw-grid-2" style="margin-bottom: 10px;">
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Categories', 'Catégories', 'الفئات')); ?></label>
                                    <select id="biz-external-categories" class="biz-multiselect biz-zw-multiselect" multiple>
                                        <?php foreach ($product_categories as $category): ?>
                                            <option value="<?php echo intval($category->term_id); ?>"><?php echo esc_html($category->name); ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Description', 'Description', 'الوصف')); ?></label>
                                    <textarea id="biz-external-description" class="biz-textarea biz-zw-textarea" placeholder="<?php echo esc_attr(bizmart_text('Product description...', 'Description du produit...', 'وصف المنتج...')); ?>"></textarea>
                                </div>
                            </div>
                            
                            <div class="biz-form-group" style="margin-bottom: 10px;">
                                <label><?php echo esc_html(bizmart_text('Product image', 'Image du produit', 'صورة المنتج')); ?></label>
                                <div class="biz-zw-upload-area" onclick="BizProducts.openMediaUploader('biz-external-image-id', 'biz-external-image-preview')">
                                    <div class="biz-upload-icon">📷</div>
                                    <p class="biz-upload-label"><?php echo esc_html(bizmart_text('Click to upload', 'Cliquez pour télécharger', 'انقر للرفع')); ?></p>
                                </div>
                                <input type="hidden" id="biz-external-image-id">
                                <img id="biz-external-image-preview" class="biz-image-preview" style="margin-top: 6px; max-height: 48px; width: auto; object-fit: contain;">
                            </div>
                            
                            <div class="biz-sticky-save-bar" style="display: flex; gap: 12px; margin-top: 10px; align-items: center; border-top: 1px solid var(--biz-border); padding-top: 10px;">
                                <button type="button" class="biz-btn biz-btn-success" style="height: 32px !important; font-size: 13px !important;" onclick="BizProducts.createExternalProduct(this)">
                                    <span style="font-size: 15px;">🔗</span>
                                    <?php echo esc_html(bizmart_text('Create external product', 'Créer produit externe', 'إنشاء منتج خارجي')); ?>
                                </button>
                                <button type="button" class="biz-btn biz-btn-ghost" style="height: 32px !important; font-size: 13px !important;" onclick="BizProducts.resetForm('external')">
                                    ↻ <?php echo esc_html(bizmart_text('Reset', 'Réinitialiser', 'إعادة تعيين')); ?>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                
                <!-- Digital Product Tab -->
                <div id="biz-tab-digital" class="biz-tab-content">
                    <form id="biz-form-digital">
                        <div class="biz-zw-section">
                            <h3 class="biz-section-title">💾 <?php echo esc_html(bizmart_text('Digital/Downloadable product', 'Produit Digital/Téléchargeable', 'منتج رقمي/قابل للتحميل')); ?></h3>
                            <p style="color: #6b7280; margin-bottom: 10px; font-size: 11px; margin-top: 0; line-height: 1.3;"><?php echo esc_html(bizmart_text('Virtual products with downloadable files', 'Produits virtuels avec fichiers téléchargeables', 'منتجات افتراضية مع ملفات قابلة للتحميل')); ?></p>
                            
                            <div class="biz-zw-grid-2-2" style="margin-bottom: 10px;">
                                <div class="biz-form-group">
                                    <label class="required"><?php echo esc_html(bizmart_text('Product name', 'Nom du produit', 'اسم المنتج')); ?></label>
                                    <input type="text" id="biz-digital-name" class="biz-input biz-zw-input" placeholder="<?php echo esc_attr(bizmart_text('File/eBook name', 'Nom du fichier/ebook', 'اسم الملف/الكتاب الإلكتروني')); ?>" required>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('SKU', 'SKU', 'SKU')); ?></label>
                                    <input type="text" id="biz-digital-sku" class="biz-input biz-zw-input" placeholder="DIGITAL-">
                                </div>
                            </div>
                            
                            <div class="biz-zw-grid-3" style="margin-bottom: 10px;">
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Price', 'Prix', 'السعر')); ?></label>
                                    <div class="biz-zw-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-digital-price" class="biz-input biz-zw-input" placeholder="0.00">
                                    </div>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Sale price', 'Prix promotionnel', 'سعر التخفيض')); ?></label>
                                    <div class="biz-zw-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-digital-sale-price" class="biz-input biz-zw-input" placeholder="0.00">
                                    </div>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Cost price', "Prix d'achat", 'سعر التكلفة')); ?></label>
                                    <div class="biz-zw-input-prefix-wrapper">
                                        <span class="biz-input-prefix">$</span>
                                        <input type="number" step="0.01" min="0" id="biz-digital-cost-price" class="biz-input biz-zw-input" placeholder="0.00">
                                    </div>
                                </div>
                            </div>
                            
                            <div class="biz-form-group" style="margin-bottom: 10px;">
                                <label><?php echo esc_html(bizmart_text('Downloadable files', 'Fichiers téléchargeables', 'ملفات قابلة للتحميل')); ?></label>
                                <div class="biz-zw-upload-area" onclick="BizProducts.openFileUploader()">
                                    <div class="biz-upload-icon">📎</div>
                                    <p class="biz-upload-label"><?php echo esc_html(bizmart_text('Click to add files · PDF, ZIP, MP3, etc.', 'Cliquez pour ajouter des fichiers · PDF, ZIP, MP3, etc.', 'انقر لإضافة ملفات · PDF، ZIP، MP3، إلخ.')); ?></p>
                                </div>
                                <div id="biz-digital-files-list" class="biz-file-list" style="margin-top: 6px;"></div>
                                <input type="hidden" id="biz-digital-files">
                            </div>
                            
                            <div class="biz-zw-grid-2" style="margin-bottom: 10px;">
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Download limit', 'Limite de téléchargement', 'حد التحميل')); ?></label>
                                    <input type="number" min="0" id="biz-digital-download-limit" class="biz-input biz-zw-input" placeholder="<?php echo esc_attr(bizmart_text('Unlimited', 'Illimité', 'غير محدود')); ?> (<?php echo esc_attr(bizmart_text('Max downloads per customer', 'Nombre max de téléchargements par client', 'أقصى عدد تحميلات لكل عميل')); ?>)">
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Expiry (days)', 'Expiration (jours)', 'الانتهاء (أيام)')); ?></label>
                                    <input type="number" min="0" id="biz-digital-download-expiry" class="biz-input biz-zw-input" placeholder="<?php echo esc_attr(bizmart_text('Never', 'Jamais', 'أبداً')); ?> (<?php echo esc_attr(bizmart_text('Days until link expires', 'Jours avant expiration du lien', 'أيام قبل انتهاء الرابط')); ?>)">
                                </div>
                            </div>
                            
                            <div class="biz-zw-grid-2" style="margin-bottom: 10px;">
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Categories', 'Catégories', 'الفئات')); ?></label>
                                    <select id="biz-digital-categories" class="biz-multiselect biz-zw-multiselect" multiple>
                                        <?php foreach ($product_categories as $category): ?>
                                            <option value="<?php echo intval($category->term_id); ?>"><?php echo esc_html($category->name); ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                                <div class="biz-form-group">
                                    <label><?php echo esc_html(bizmart_text('Description', 'Description', 'الوصف')); ?></label>
                                    <textarea id="biz-digital-description" class="biz-textarea biz-zw-textarea" placeholder="<?php echo esc_attr(bizmart_text('Digital product description...', 'Description du produit digital...', 'وصف المنتج الرقمي...')); ?>"></textarea>
                                </div>
                            </div>
                            
                            <div class="biz-form-group" style="margin-bottom: 10px;">
                                <label><?php echo esc_html(bizmart_text('Image', 'Image', 'صورة')); ?></label>
                                <div class="biz-zw-upload-area" onclick="BizProducts.openMediaUploader('biz-digital-image-id', 'biz-digital-image-preview')">
                                    <div class="biz-upload-icon">📷</div>
                                    <p class="biz-upload-label"><?php echo esc_html(bizmart_text('Click to upload', 'Cliquez pour télécharger', 'انقر للرفع')); ?></p>
                                </div>
                                <input type="hidden" id="biz-digital-image-id">
                                <img id="biz-digital-image-preview" class="biz-image-preview" style="margin-top: 6px; max-height: 48px; width: auto; object-fit: contain;">
                            </div>
                            
                            <div class="biz-sticky-save-bar" style="display: flex; gap: 12px; margin-top: 10px; align-items: center; border-top: 1px solid var(--biz-border); padding-top: 10px;">
                                <button type="button" class="biz-btn biz-btn-success" style="height: 32px !important; font-size: 13px !important;" onclick="BizProducts.createDigitalProduct(this)">
                                    <span style="font-size: 15px;">💾</span>
                                    <?php echo esc_html(bizmart_text('Create digital product', 'Créer produit digital', 'إنشاء منتج رقمي')); ?>
                                </button>
                                <button type="button" class="biz-btn biz-btn-ghost" style="height: 32px !important; font-size: 13px !important;" onclick="BizProducts.resetForm('digital')">
                                    ↻ <?php echo esc_html(bizmart_text('Reset', 'Réinitialiser', 'إعادة تعيين')); ?>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
        <div class="biz-products-sidebar">
            <div class="biz-card">
                <h3 style="margin: 0 0 16px 0; color: #374151;">💡 <?php echo esc_html(bizmart_text('Quick tips', 'Astuces rapides', 'نصائح سريعة')); ?></h3>
                <div style="color: #6b7280; font-size: 14px; line-height: 1.6;">
                    <p><strong>📦 <?php echo esc_html(bizmart_text('Simple product', 'Produit Simple', 'منتج بسيط')); ?>:</strong> <?php echo esc_html(bizmart_text('Standard physical or digital items', 'Articles physiques ou digitaux standards', 'عناصر مادية أو رقمية قياسية')); ?></p>
                    <p><strong>🎯 <?php echo esc_html(bizmart_text('Variable product', 'Produit Variable', 'منتج متغير')); ?>:</strong> <?php echo esc_html(bizmart_text('Products with options (size, color)', 'Produits avec options (taille, couleur)', 'منتجات مع خيارات (مقاس، لون)')); ?></p>
                    <p><strong>📦 <?php echo esc_html(bizmart_text('Grouped product', 'Produit Groupé', 'منتج مجمّع')); ?>:</strong> <?php echo esc_html(bizmart_text('Bundles/sets of products', 'Packs/ensembles de produits', 'حزم/مجموعات من المنتجات')); ?></p>
                    <p><strong>🔗 <?php echo esc_html(bizmart_text('External product', 'Produit Externe', 'منتج خارجي')); ?>:</strong> <?php echo esc_html(bizmart_text('Products sold on other sites', "Produits vendus sur d'autres sites", 'منتجات تُباع على مواقع أخرى')); ?></p>
                    <p><strong>💾 <?php echo esc_html(bizmart_text('Digital product', 'Produit Digital', 'منتج رقمي')); ?>:</strong> <?php echo esc_html(bizmart_text('eBooks, music, software', 'eBooks, musique, logiciels', 'كتب إلكترونية، موسيقى، برامج')); ?></p>
                    <p><strong>📊 <?php echo esc_html(bizmart_text('Sync', 'Synchronisation', 'المزامنة')); ?>:</strong> <?php echo esc_html(bizmart_text('All products automatically sync with WooCommerce', 'Tous les produits sont automatiquement synchronisés avec WooCommerce', 'جميع المنتجات تتم مزامنتها تلقائياً مع WooCommerce')); ?></p>
                </div>
            </div>
            
            <!-- Quick Actions -->
            <div class="biz-card">
                <h3 style="margin: 0 0 16px 0; color: #374151;">⚡ <?php echo esc_html(bizmart_text('Quick actions', 'Actions rapides', 'إجراءات سريعة')); ?></h3>
                <div style="display: flex; flex-direction: column; gap: 12px;">
                    <?php if (defined('BIZMART_ADDON_VERSION')) : ?>
                    <a href="?page=bizmart-invoices" class="biz-btn" style="text-align: center;">
                        🧾 <?php echo esc_html(bizmart_text('New invoice', 'Nouvelle Facture', 'فاتورة جديدة')); ?>
                    </a>
                    <?php endif; ?>
                    <a href="<?php echo esc_url(admin_url('edit.php?post_type=product')); ?>" class="biz-btn biz-btn-secondary" style="text-align: center;">
                        📋 <?php echo esc_html(bizmart_text('All products', 'Tous les Produits', 'جميع المنتجات')); ?>
                    </a>
                    <a href="<?php echo esc_url(admin_url('admin.php?page=wc-settings&tab=products')); ?>" class="biz-btn biz-btn-secondary" style="text-align: center;">
                        ⚙️ <?php echo esc_html(bizmart_text('Product settings', 'Paramètres Produits', 'إعدادات المنتجات')); ?>
                    </a>
                </div>
            </div>
            
            <!-- Status -->
            <div class="biz-card">
                <h3 style="margin: 0 0 16px 0; color: #374151;">📊 <?php echo esc_html(bizmart_text('Sync', 'Synchronisation', 'المزامنة')); ?></h3>
                <div id="biz-sync-status" style="color: #10b981; font-size: 14px;">
                    ✅ <?php echo esc_html(bizmart_text('Connected to WooCommerce', 'Connecté à WooCommerce', 'متصل بـ WooCommerce')); ?> (<?php echo (int) $total_products; ?> <?php echo esc_html(bizmart_text('products', 'produits', 'منتجات')); ?>)
                </div>
                <div style="margin-top: 12px; font-size: 12px; color: #6b7280;">
                    <p><?php echo esc_html(bizmart_text('Supported features:', 'Fonctionnalités supportées:', 'الميزات المدعومة:')); ?></p>
                    <ul style="margin: 8px 0; padding-left: 20px;">
                        <li>✅ <?php echo esc_html(bizmart_text('All product types', 'Tous les types de produits', 'جميع أنواع المنتجات')); ?></li>
                        <li>✅ <?php echo esc_html(bizmart_text('Categories & tags', 'Catégories & étiquettes', 'الفئات والعلامات')); ?></li>
                        <li>✅ <?php echo esc_html(bizmart_text('Advanced stock management', 'Gestion du stock avancée', 'إدارة المخزون المتقدمة')); ?></li>
                        <li>✅ <?php echo esc_html(bizmart_text('Images & galleries', 'Images & galeries', 'الصور والمعارض')); ?></li>
                        <li>✅ <?php echo esc_html(bizmart_text('Shipping & dimensions', 'Livraison & dimensions', 'الشحن والأبعاد')); ?></li>
                        <li>✅ <?php echo esc_html(bizmart_text('Linked products', 'Produits liés', 'منتجات مرتبطة')); ?></li>
                        <li>✅ <?php echo esc_html(bizmart_text('Attributes & variations', 'Attributs & variations', 'السمات والتنويعات')); ?></li>
                        <li>✅ <?php echo esc_html(bizmart_text('Digital products', 'Produits digitaux', 'المنتجات الرقمية')); ?></li>
                    </ul>
                </div>
            </div>
            
            <!-- Product Types Stats -->
            <div class="biz-card">
                <h3 style="margin: 0 0 16px 0; color: #374151;">📊 <?php echo esc_html(bizmart_text('Product types', 'Types de Produits', 'أنواع المنتجات')); ?></h3>
                <div style="font-size: 13px;">
                    <?php
                    $product_types_labels = [
                        'simple' => bizmart_text('Simple', 'Simple', 'بسيط'),
                        'variable' => bizmart_text('Variable', 'Variable', 'متغير'),
                        'grouped' => bizmart_text('Grouped', 'Groupé', 'مجمّع'),
                        'external' => bizmart_text('External', 'Externe', 'خارجي')
                    ];
                    
                    foreach ($product_types_labels as $type => $label) {
                        $count = $type_counts[$type] ?? 0;
                        echo wp_kses_post(sprintf(
                            '<div style="display: flex; justify-content: space-between; margin-bottom: 8px; padding: 6px 0; border-bottom: 1px solid #f3f4f6;">
                                <span>%s</span>
                                <span style="font-weight: 600;">%d</span>
                              </div>',
                            esc_html($label),
                            absint($count)
                        ));
                    }
                    ?>
                </div>
            </div>

            <!-- Recent Products (Refined SaaS Feed Style) -->
            <div class="biz-card biz-recent-products">
                <h3 class="biz-section-title">🕐 <?php echo esc_html(bizmart_text('Recently created products', 'Produits récemments créés', 'المنتجات المنشأة مؤخراً')); ?></h3>
                <div id="biz-recent-products-list" style="display: flex; flex-direction: column; gap: 8px;">
                    <?php foreach ($recent_products as $product): ?>
                        <a href="<?php echo esc_url(get_edit_post_link($product->get_id())); ?>" target="_blank" rel="noopener" class="biz-product-item">
                            <div class="biz-product-icon">
                                <?php 
                                if ($product->is_type('variable')) echo '🎯';
                                elseif ($product->is_type('grouped')) echo '📦';
                                elseif ($product->is_type('external')) echo '🔗';
                                elseif ($product->is_downloadable()) echo '💾';
                                else echo '📦';
                                ?>
                            </div>
                            <div class="biz-product-info">
                                <p class="biz-product-name"><?php echo esc_html($product->get_name()); ?></p>
                                <div style="display:flex;gap:8px;align-items:center;font-size:10px;color:#6b7280;margin-top:2px;">
                                    <div><?php echo $product->get_sku() ? esc_html($product->get_sku()) : esc_html(bizmart_text('No SKU', 'Pas de SKU', 'بدون SKU')); ?></div>
                                    <div style="color:#10b981;font-weight:600"><?php echo $product->is_in_stock() ? esc_html(bizmart_text('In stock','En stock', 'متوفر')) : esc_html(bizmart_text('Out of stock','Rupture', 'غير متوفر')); ?></div>
                                </div>
                            </div>
                            <div class="biz-product-price">
                                <?php echo wp_kses_post(wc_price($product->get_price())); ?>
                            </div>
                        </a>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        </div>
        </div> <!-- End biz-products-container-inner -->
    <?php endif; ?>
    </div>
</div>



<?php if (false) : // Extracted to assets/products.js (enqueued on bizmart-products) ?>
<!-- Active duplicate script block moved to assets/products.js -->
    </div><!-- .biz-products-container -->
    </div><!-- .wrap -->
<?php endif; ?>
<?php })(); ?>
