{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "wholesale-b2b-quick-order",
  "title": "Wholesale B2b Quick Order",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-react/blocks/wholesale-b2b-quick-order/WholesaleB2bQuickOrder.tsx",
      "content": "'use client'\n\nimport * as React from 'react'\nimport { useState, useMemo, useCallback } from 'react'\nimport {\n  AlertCircle,\n  Bookmark,\n  Building2,\n  CheckCircle2,\n  Download,\n  FileSpreadsheet,\n  Minus,\n  Package,\n  Plus,\n  RefreshCw,\n  Send,\n  Layers,\n  Trash2,\n  TrendingDown,\n  Truck,\n  Upload,\n  X,\n} from 'lucide-react'\nimport { cn } from '@/lib/utils'\nimport { Badge } from '@/components/ui/badge'\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'\nimport { Input } from '@/components/ui/input'\nimport { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'\nimport { Textarea } from '@/components/ui/textarea'\n\nexport interface WholesaleProduct {\n  id: string\n  sku: string\n  name: string\n  variant: string\n  casePack: number\n  msrpUnitPrice: number\n  wholesaleUnitPrice: number\n  cases: number\n  availableCases: number\n  image: string\n  category: string\n}\n\nexport interface WholesaleB2bQuickOrderProps {\n  poNumber?: string\n  accountName?: string\n  accountTier?: string\n  tierDiscountPercent?: number\n  paymentTerms?: string\n  freeFreightThreshold?: number\n  initialProducts?: WholesaleProduct[]\n  className?: string\n  onSubmitOrder?: (payload: {\n    poNumber: string\n    items: WholesaleProduct[]\n    subtotal: number\n    totalUnits: number\n    totalCases: number\n    savings: number\n  }) => void\n  onSaveTemplate?: (items: WholesaleProduct[]) => void\n  onExportCsv?: (items: WholesaleProduct[]) => void\n}\n\nexport const DEFAULT_WHOLESALE_PRODUCTS: WholesaleProduct[] = [\n  {\n    id: 'prod-1',\n    sku: 'SKU-84920',\n    name: 'Pro Studio Headphones',\n    variant: 'Matte Black · Pro Series',\n    casePack: 12,\n    msrpUnitPrice: 299.0,\n    wholesaleUnitPrice: 194.35,\n    cases: 4,\n    availableCases: 450,\n    image: 'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=300&auto=format&fit=crop&q=80',\n    category: 'Audio & Acoustics',\n  },\n  {\n    id: 'prod-2',\n    sku: 'SKU-49102',\n    name: 'Aero Minimalist Runner',\n    variant: 'Arctic White · US 10-12 Assorted',\n    casePack: 10,\n    msrpUnitPrice: 140.0,\n    wholesaleUnitPrice: 91.0,\n    cases: 3,\n    availableCases: 180,\n    image: 'https://images.unsplash.com/photo-1542291026-7eec264c27ff?w=300&auto=format&fit=crop&q=80',\n    category: 'Footwear',\n  },\n  {\n    id: 'prod-3',\n    sku: 'SKU-77215',\n    name: 'Technical Shell Parka',\n    variant: 'Mineral Gray · Waterproof 3L',\n    casePack: 8,\n    msrpUnitPrice: 220.0,\n    wholesaleUnitPrice: 143.0,\n    cases: 2,\n    availableCases: 95,\n    image: 'https://images.unsplash.com/photo-1591047139829-d91aecb6caea?w=300&auto=format&fit=crop&q=80',\n    category: 'Outerwear',\n  },\n  {\n    id: 'prod-4',\n    sku: 'SKU-10934',\n    name: 'Braided USB-C Cable',\n    variant: 'Space Gray · 2m 240W EPR',\n    casePack: 24,\n    msrpUnitPrice: 25.0,\n    wholesaleUnitPrice: 16.25,\n    cases: 2,\n    availableCases: 620,\n    image: 'https://images.unsplash.com/photo-1583863788434-e58a36330cf0?w=300&auto=format&fit=crop&q=80',\n    category: 'Hardware & Cables',\n  },\n  {\n    id: 'prod-5',\n    sku: 'SKU-63821',\n    name: 'Leather Cardholder',\n    variant: 'Saddle Brown · Full-Grain Veg-Tan',\n    casePack: 20,\n    msrpUnitPrice: 50.0,\n    wholesaleUnitPrice: 32.5,\n    cases: 1,\n    availableCases: 24,\n    image: 'https://images.unsplash.com/photo-1627123424574-724758594e93?w=300&auto=format&fit=crop&q=80',\n    category: 'Leather Goods',\n  },\n]\n\nconst formatCurrency = (val: number) => {\n  return new Intl.NumberFormat('en-US', {\n    style: 'currency',\n    currency: 'USD',\n    minimumFractionDigits: 2,\n    maximumFractionDigits: 2,\n  }).format(val)\n}\n\nconst formatNumber = (val: number) => {\n  return new Intl.NumberFormat('en-US').format(val)\n}\n\nexport function WholesaleB2bQuickOrder({\n  poNumber = 'PO-2026-8841B',\n  accountName = 'Northwind Retailers',\n  accountTier = 'Tier 3 Wholesale Partner',\n  tierDiscountPercent = 35,\n  paymentTerms = 'Net 30 Invoicing',\n  freeFreightThreshold = 10000,\n  initialProducts,\n  className,\n  onSubmitOrder,\n  onSaveTemplate,\n  onExportCsv,\n}: WholesaleB2bQuickOrderProps) {\n  const [products, setProducts] = useState<WholesaleProduct[]>(() =>\n    initialProducts\n      ? JSON.parse(JSON.stringify(initialProducts))\n      : JSON.parse(JSON.stringify(DEFAULT_WHOLESALE_PRODUCTS)),\n  )\n\n  const [poRef] = useState(poNumber)\n  const [showCsvBox, setShowCsvBox] = useState(false)\n  const [csvPasteText, setCsvPasteText] = useState('')\n  const [pasteFeedback, setPasteFeedback] = useState<{ type: 'success' | 'error'; message: string } | null>(null)\n  const [templateSaved, setTemplateSaved] = useState(false)\n  const [orderSubmitted, setOrderSubmitted] = useState(false)\n  const [isSubmitting, setIsSubmitting] = useState(false)\n\n  // Computations\n  const totalCases = useMemo(() => products.reduce((acc, p) => acc + (Number(p.cases) || 0), 0), [products])\n  const totalUnits = useMemo(\n    () => products.reduce((acc, p) => acc + (Number(p.cases) || 0) * p.casePack, 0),\n    [products],\n  )\n  const wholesaleSubtotal = useMemo(\n    () => products.reduce((acc, p) => acc + (Number(p.cases) || 0) * p.casePack * p.wholesaleUnitPrice, 0),\n    [products],\n  )\n  const msrpTotal = useMemo(\n    () => products.reduce((acc, p) => acc + (Number(p.cases) || 0) * p.casePack * p.msrpUnitPrice, 0),\n    [products],\n  )\n  const totalSavings = useMemo(() => Math.max(0, msrpTotal - wholesaleSubtotal), [msrpTotal, wholesaleSubtotal])\n  const savingsPercent = useMemo(() => {\n    if (msrpTotal <= 0) return tierDiscountPercent\n    return Math.round((totalSavings / msrpTotal) * 100)\n  }, [msrpTotal, totalSavings, tierDiscountPercent])\n\n  const isFreeFreight = wholesaleSubtotal >= freeFreightThreshold\n  const freightAmount = isFreeFreight ? 0 : 250\n  const grandTotal = wholesaleSubtotal + freightAmount\n\n  const nextTierTarget = 50000\n  const nextTierRemaining = Math.max(0, nextTierTarget - wholesaleSubtotal)\n  const tierProgressPercent = Math.min(100, Math.round((wholesaleSubtotal / nextTierTarget) * 100))\n\n  // Actions\n  const updateCases = useCallback((id: string, delta: number) => {\n    setProducts((prev) =>\n      prev.map((p) => {\n        if (p.id === id) {\n          const current = Number(p.cases) || 0\n          const next = Math.max(0, Math.min(p.availableCases, current + delta))\n          return { ...p, cases: next }\n        }\n        return p\n      }),\n    )\n  }, [])\n\n  const setCases = useCallback((id: string, val: string | number) => {\n    setProducts((prev) =>\n      prev.map((p) => {\n        if (p.id === id) {\n          const parsed = parseInt(String(val), 10)\n          const next = isNaN(parsed) || parsed < 0 ? 0 : Math.min(p.availableCases, parsed)\n          return { ...p, cases: next }\n        }\n        return p\n      }),\n    )\n  }, [])\n\n  const clearLine = useCallback((id: string) => {\n    setProducts((prev) => prev.map((p) => (p.id === id ? { ...p, cases: 0 } : p)))\n  }, [])\n\n  const resetAllCases = useCallback(() => {\n    setProducts((prev) => prev.map((p) => ({ ...p, cases: 0 })))\n    setPasteFeedback(null)\n  }, [])\n\n  const restoreDefaultCases = useCallback(() => {\n    setProducts(JSON.parse(JSON.stringify(DEFAULT_WHOLESALE_PRODUCTS)))\n    setPasteFeedback(null)\n  }, [])\n\n  const applyCsvPaste = useCallback(() => {\n    setPasteFeedback(null)\n    if (!csvPasteText.trim()) {\n      setPasteFeedback({\n        type: 'error',\n        message: 'Please paste SKU and case quantity rows to parse.',\n      })\n      return\n    }\n\n    const lines = csvPasteText.split(/\\r?\\n/)\n    let updatedCount = 0\n    const unknownSkus: string[] = []\n\n    setProducts((prev) => {\n      const cloned = prev.map((p) => ({ ...p }))\n      for (const rawLine of lines) {\n        const line = rawLine.trim()\n        if (!line || line.startsWith('#') || line.toLowerCase().startsWith('sku')) continue\n\n        const parts = line.split(/[,;\\t]+/).map((s) => s.trim())\n        if (parts.length >= 2) {\n          const skuQuery = parts[0].toUpperCase()\n          const qty = parseInt(parts[1], 10)\n\n          if (!isNaN(qty)) {\n            const product = cloned.find(\n              (p) => p.sku.toUpperCase() === skuQuery || p.sku.toUpperCase().includes(skuQuery),\n            )\n            if (product) {\n              product.cases = Math.max(0, Math.min(product.availableCases, qty))\n              updatedCount++\n            } else {\n              unknownSkus.push(parts[0])\n            }\n          }\n        }\n      }\n      return cloned\n    })\n\n    if (updatedCount > 0) {\n      setPasteFeedback({\n        type: 'success',\n        message: `Successfully updated ${updatedCount} SKU line items in bulk matrix.${\n          unknownSkus.length > 0\n            ? ` Note: ${unknownSkus.length} SKU(s) not found in catalog (${unknownSkus.slice(0, 3).join(', ')}).`\n            : ''\n        }`,\n      })\n    } else {\n      setPasteFeedback({\n        type: 'error',\n        message: 'No matching catalog SKUs found. Verify format: SKU-84920, 10',\n      })\n    }\n  }, [csvPasteText])\n\n  const loadSampleCsv = useCallback(() => {\n    const sample = `SKU-84920, 8\\nSKU-49102, 5\\nSKU-77215, 4\\nSKU-10934, 12\\nSKU-63821, 6`\n    setCsvPasteText(sample)\n\n    // Parse sample directly\n    const lines = sample.split(/\\r?\\n/)\n    setProducts((prev) => {\n      const cloned = prev.map((p) => ({ ...p }))\n      let count = 0\n      for (const rawLine of lines) {\n        const parts = rawLine.split(/[,;\\t]+/).map((s) => s.trim())\n        if (parts.length >= 2) {\n          const skuQuery = parts[0].toUpperCase()\n          const qty = parseInt(parts[1], 10)\n          const product = cloned.find((p) => p.sku.toUpperCase() === skuQuery)\n          if (product && !isNaN(qty)) {\n            product.cases = Math.max(0, Math.min(product.availableCases, qty))\n            count++\n          }\n        }\n      }\n      return cloned\n    })\n    setPasteFeedback({\n      type: 'success',\n      message: 'Sample manifest loaded and applied to matrix (5 SKUs updated).',\n    })\n  }, [])\n\n  const handleSaveTemplate = useCallback(() => {\n    setTemplateSaved(true)\n    onSaveTemplate?.(products)\n    setTimeout(() => {\n      setTemplateSaved(false)\n    }, 4000)\n  }, [products, onSaveTemplate])\n\n  const handleSubmitOrder = useCallback(() => {\n    if (totalCases === 0) return\n    setIsSubmitting(true)\n    setTimeout(() => {\n      setIsSubmitting(false)\n      setOrderSubmitted(true)\n      onSubmitOrder?.({\n        poNumber: poRef,\n        items: products.filter((p) => p.cases > 0),\n        subtotal: wholesaleSubtotal,\n        totalUnits,\n        totalCases,\n        savings: totalSavings,\n      })\n    }, 600)\n  }, [totalCases, poRef, products, wholesaleSubtotal, totalUnits, totalSavings, onSubmitOrder])\n\n  const handleExportCsv = useCallback(() => {\n    onExportCsv?.(products)\n    const header =\n      'SKU,Product Name,Variant,Case Pack Multiplier,Cases Ordered,Total Units,Wholesale Unit Price,Line Total\\n'\n    const rows = products\n      .filter((p) => p.cases > 0)\n      .map(\n        (p) =>\n          `\"${p.sku}\",\"${p.name}\",\"${p.variant}\",${p.casePack},${p.cases},${p.cases * p.casePack},${p.wholesaleUnitPrice},${(p.cases * p.casePack * p.wholesaleUnitPrice).toFixed(2)}`,\n      )\n      .join('\\n')\n    const csvContent = 'data:text/csv;charset=utf-8,' + encodeURIComponent(header + rows)\n    const downloadLink = document.createElement('a')\n    downloadLink.setAttribute('href', csvContent)\n    downloadLink.setAttribute('download', `${poRef}-order-matrix.csv`)\n    document.body.appendChild(downloadLink)\n    downloadLink.click()\n    document.body.removeChild(downloadLink)\n  }, [products, onExportCsv, poRef])\n\n  return (\n    <div\n      data-slot=\"wholesale-b2b-quick-order\"\n      className={cn('bg-background text-foreground w-full space-y-6', className)}\n    >\n      {/* Header & Account Info */}\n      <Card className=\"border-border bg-card shadow-xs\">\n        <CardHeader className=\"pb-4\">\n          <div className=\"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between\">\n            <div className=\"space-y-1.5\">\n              <div className=\"flex flex-wrap items-center gap-2\">\n                <div className=\"text-muted-foreground flex items-center gap-1.5 text-xs font-medium\">\n                  <Building2 className=\"size-3.5\" />\n                  <span>{accountName}</span>\n                  <span>·</span>\n                  <span>{accountTier}</span>\n                </div>\n                <Badge variant=\"outline\" className=\"border-success/30 bg-success/10 text-success font-medium\">\n                  <Layers className=\"mr-1 size-3\" />\n                  {tierDiscountPercent}% Off MSRP Wholesale Tier\n                </Badge>\n              </div>\n              <CardTitle className=\"text-xl font-bold tracking-tight sm:text-2xl\">\n                Wholesale & B2B Bulk Order Matrix\n              </CardTitle>\n              <CardDescription className=\"text-muted-foreground text-xs sm:text-sm\">\n                Build your purchase order by entering case quantities below or pasting bulk SKU manifests with automated\n                case multipliers.\n              </CardDescription>\n            </div>\n\n            {/* Header Action Buttons */}\n            <div className=\"flex flex-wrap items-center gap-2\">\n              <Button\n                aria-label=\"Close CSV paste\"\n                variant=\"outline\"\n                size=\"sm\"\n                className=\"gap-1.5 text-xs font-medium\"\n                onClick={() => setShowCsvBox(!showCsvBox)}\n              >\n                <FileSpreadsheet className=\"size-3.5\" />\n                <span>{showCsvBox ? 'Hide CSV Paste' : 'Upload CSV Order'}</span>\n              </Button>\n              <Button variant=\"outline\" size=\"sm\" className=\"gap-1.5 text-xs font-medium\" onClick={handleSaveTemplate}>\n                <Bookmark className=\"size-3.5\" />\n                <span>Save Order Template</span>\n              </Button>\n            </div>\n          </div>\n        </CardHeader>\n\n        <CardContent className=\"pt-0\">\n          {/* Account Terms & Partner Meta Strip */}\n          <div className=\"bg-muted/40 border-border grid grid-cols-2 gap-3 rounded-lg border p-3 sm:grid-cols-4 sm:gap-4\">\n            <div className=\"space-y-0.5\">\n              <div className=\"text-muted-foreground text-xs font-medium\">PO Reference</div>\n              <div className=\"font-mono text-sm font-semibold\">{poRef}</div>\n            </div>\n            <div className=\"space-y-0.5\">\n              <div className=\"text-muted-foreground text-xs font-medium\">Payment Terms</div>\n              <div className=\"text-foreground flex items-center gap-1 text-sm font-semibold\">\n                <CheckCircle2 className=\"text-success size-3.5\" />\n                <span>{paymentTerms}</span>\n              </div>\n            </div>\n            <div className=\"space-y-0.5\">\n              <div className=\"text-muted-foreground text-xs font-medium\">Freight Status</div>\n              <div\n                className={cn('text-sm font-semibold tabular-nums', isFreeFreight ? 'text-success' : 'text-foreground')}\n              >\n                {isFreeFreight ? 'Free Ground Freight' : '$250 Standard Freight'}\n              </div>\n            </div>\n            <div className=\"space-y-0.5\">\n              <div className=\"text-muted-foreground text-xs font-medium\">Volume Tier Status</div>\n              <div className=\"text-foreground text-sm font-semibold\">\n                Tier 3 <span className=\"text-muted-foreground font-normal\">({tierDiscountPercent}% Margin)</span>\n              </div>\n            </div>\n          </div>\n\n          {/* Volume Tier Margin Incentive Banner */}\n          <div className=\"border-border bg-card/60 mt-3 rounded-lg border p-3\">\n            <div className=\"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between\">\n              <div className=\"flex items-center gap-2\">\n                <TrendingDown className=\"text-success size-4 shrink-0\" />\n                <div className=\"text-xs\">\n                  <span className=\"text-foreground font-semibold\">Tier 4 Milestone ($50,000):</span>\n                  <span className=\"text-muted-foreground ml-1\">\n                    {nextTierRemaining > 0\n                      ? `Add ${formatCurrency(nextTierRemaining)} more to unlock 42% Tier 4 Enterprise Margin.`\n                      : 'Tier 4 Enterprise Margin (42%) Unlocked!'}\n                  </span>\n                </div>\n              </div>\n              <div className=\"text-muted-foreground flex items-center gap-2 text-xs\">\n                <span>{tierProgressPercent}% to Tier 4</span>\n                <div className=\"bg-muted border-border h-2 w-24 overflow-hidden rounded-full border\">\n                  <div\n                    className=\"bg-success h-full transition-[width] duration-300\"\n                    style={{ width: `${tierProgressPercent}%` }}\n                  />\n                </div>\n              </div>\n            </div>\n          </div>\n        </CardContent>\n      </Card>\n\n      {/* Template Saved Alert */}\n      {templateSaved && (\n        <div className=\"border-success/30 bg-success/10 text-success text-success flex items-center justify-between rounded-lg border p-3 text-xs sm:text-sm\">\n          <div className=\"flex items-center gap-2\">\n            <Bookmark className=\"text-success size-4 shrink-0\" />\n            <span>Order matrix saved as your primary template. You can re-populate this draft at any time.</span>\n          </div>\n          <Button\n            variant=\"ghost\"\n            size=\"xs\"\n            className=\"text-success hover:text-success\"\n            aria-label=\"Dismiss notification\"\n            onClick={() => setTemplateSaved(false)}\n          >\n            <X className=\"size-3.5\" />\n          </Button>\n        </div>\n      )}\n\n      {/* Order Submitted Success Alert */}\n      {orderSubmitted && (\n        <div className=\"border-success/30 bg-success/10 text-success dark:text-foreground rounded-xl border p-4 sm:p-5\">\n          <div className=\"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between\">\n            <div className=\"flex items-start gap-3\">\n              <CheckCircle2 className=\"text-success mt-0.5 size-5 shrink-0\" />\n              <div className=\"space-y-1\">\n                <h3 className=\"text-sm font-semibold sm:text-base\">Purchase Order {poRef} Submitted Successfully!</h3>\n                <p className=\"text-muted-foreground text-xs sm:text-sm\">\n                  Your bulk order of{' '}\n                  <strong className=\"text-foreground\">\n                    {totalCases} cases ({totalUnits} units)\n                  </strong>{' '}\n                  totaling <strong className=\"text-foreground\">{formatCurrency(grandTotal)}</strong> has been queued for\n                  warehouse dispatch under {paymentTerms}.\n                </p>\n              </div>\n            </div>\n            <div className=\"flex items-center gap-2\">\n              <Button\n                aria-label=\"Download attachment\"\n                variant=\"outline\"\n                size=\"sm\"\n                className=\"text-xs\"\n                onClick={handleExportCsv}\n              >\n                <Download className=\"mr-1.5 size-3.5\" />\n                Download PO PDF\n              </Button>\n              <Button size=\"sm\" className=\"text-xs\" onClick={() => setOrderSubmitted(false)}>\n                Start New Order\n              </Button>\n            </div>\n          </div>\n        </div>\n      )}\n\n      {/* Quick SKU & Quantity CSV Paste Box */}\n      {showCsvBox && (\n        <Card className=\"border-border bg-card shadow-xs transition-colors duration-200\">\n          <CardHeader className=\"pb-3\">\n            <div className=\"flex items-center justify-between\">\n              <div className=\"flex items-center gap-2\">\n                <FileSpreadsheet className=\"text-primary size-4\" />\n                <CardTitle className=\"text-sm font-semibold sm:text-base\">\n                  Quick Paste SKU & Quantity Manifest\n                </CardTitle>\n              </div>\n              <Button\n                aria-label=\"Close CSV paste\"\n                variant=\"ghost\"\n                size=\"xs\"\n                className=\"text-muted-foreground hover:text-foreground\"\n                onClick={() => setShowCsvBox(false)}\n              >\n                <X className=\"size-4\" />\n              </Button>\n            </div>\n            <CardDescription className=\"text-muted-foreground text-xs\">\n              Paste CSV rows with SKU identifier and case quantity (one item per line, e.g.{' '}\n              <code className=\"bg-muted rounded px-1 font-mono\">SKU-84920, 10</code>) to auto-populate matrix.\n            </CardDescription>\n          </CardHeader>\n\n          <CardContent className=\"space-y-3\">\n            <Textarea\n              value={csvPasteText}\n              onValueChange={(val) => setCsvPasteText(val)}\n              placeholder={'SKU-84920, 8\\nSKU-49102, 5\\nSKU-77215, 4\\nSKU-10934, 12\\nSKU-63821, 6'}\n              rows={4}\n              className=\"font-mono text-xs\"\n            />\n\n            <div className=\"flex flex-wrap items-center justify-between gap-2\">\n              <div className=\"flex flex-wrap items-center gap-2\">\n                <Button size=\"sm\" className=\"text-xs font-medium\" onClick={applyCsvPaste}>\n                  <Upload className=\"mr-1.5 size-3.5\" />\n                  Apply SKU List to Matrix\n                </Button>\n                <Button variant=\"outline\" size=\"sm\" className=\"text-xs font-medium\" onClick={loadSampleCsv}>\n                  Load Sample Data\n                </Button>\n                {csvPasteText && (\n                  <Button\n                    variant=\"ghost\"\n                    size=\"sm\"\n                    className=\"text-muted-foreground text-xs\"\n                    onClick={() => setCsvPasteText('')}\n                  >\n                    Clear Input\n                  </Button>\n                )}\n              </div>\n              <div className=\"text-muted-foreground text-xs\">Supports comma, tab, and semicolon delimited lines</div>\n            </div>\n\n            {/* Parse Feedback Alert */}\n            {pasteFeedback && (\n              <div\n                className={cn(\n                  'flex items-center gap-2 rounded-lg border p-2.5 text-xs',\n                  pasteFeedback.type === 'success'\n                    ? 'border-success/30 bg-success/10 text-success'\n                    : 'border-destructive/30 bg-destructive/10 text-destructive',\n                )}\n              >\n                {pasteFeedback.type === 'success' ? (\n                  <CheckCircle2 className=\"text-success size-4 shrink-0\" />\n                ) : (\n                  <AlertCircle className=\"size-4 shrink-0\" />\n                )}\n                <span>{pasteFeedback.message}</span>\n              </div>\n            )}\n          </CardContent>\n        </Card>\n      )}\n\n      {/* Bulk SKU Matrix Table Card */}\n      <Card className=\"border-border bg-card shadow-xs\">\n        <CardHeader className=\"border-border border-b pb-3\">\n          <div className=\"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between\">\n            <div>\n              <CardTitle className=\"text-base font-semibold\">Bulk SKU Order Matrix</CardTitle>\n              <CardDescription className=\"text-muted-foreground text-xs\">\n                {products.length} wholesale catalog items available with active case multipliers.\n              </CardDescription>\n            </div>\n            <div className=\"flex items-center gap-2\">\n              <Button\n                variant=\"outline\"\n                size=\"xs\"\n                className=\"text-muted-foreground text-xs\"\n                onClick={restoreDefaultCases}\n              >\n                <RefreshCw className=\"mr-1 size-3\" />\n                Reset Defaults\n              </Button>\n              <Button variant=\"outline\" size=\"xs\" className=\"text-muted-foreground text-xs\" onClick={resetAllCases}>\n                <Trash2 className=\"mr-1 size-3\" />\n                Zero All\n              </Button>\n            </div>\n          </div>\n        </CardHeader>\n\n        <CardContent className=\"p-0\">\n          <div className=\"overflow-x-auto\">\n            <Table className=\"w-full max-w-[760px] min-w-full\">\n              <TableHeader>\n                <TableRow className=\"bg-muted/30\">\n                  <TableHead className=\"w-[300px] text-xs font-semibold\">Product & SKU Identifier</TableHead>\n                  <TableHead className=\"text-xs font-semibold\">Case Multiplier</TableHead>\n                  <TableHead className=\"text-xs font-semibold\">Unit Price</TableHead>\n                  <TableHead className=\"text-xs font-semibold\">Case Quantity</TableHead>\n                  <TableHead className=\"text-xs font-semibold\">Availability</TableHead>\n                  <TableHead className=\"text-right text-xs font-semibold\">Line Total</TableHead>\n                  <TableHead className=\"w-[50px]\">\n                    <span className=\"sr-only\">Actions</span>\n                  </TableHead>\n                </TableRow>\n              </TableHeader>\n              <TableBody>\n                {products.map((product) => (\n                  <TableRow\n                    key={product.id}\n                    className={cn('transition-colors', product.cases > 0 && 'bg-primary/5 dark:bg-primary/5')}\n                  >\n                    {/* Product Thumbnail & Details */}\n                    <TableCell className=\"py-3.5\">\n                      <div className=\"flex items-center gap-3\">\n                        <img\n                          src={product.image}\n                          alt={product.name}\n                          className=\"border-border bg-muted/40 size-12 shrink-0 rounded-lg border object-cover\"\n                          loading=\"lazy\"\n                        />\n                        <div className=\"min-w-0 space-y-0.5\">\n                          <div className=\"text-foreground truncate text-sm font-medium\">{product.name}</div>\n                          <div className=\"text-muted-foreground flex items-center gap-1.5 text-xs\">\n                            <span className=\"font-mono\">{product.sku}</span>\n                            <span>·</span>\n                            <span className=\"truncate\">{product.variant}</span>\n                          </div>\n                        </div>\n                      </div>\n                    </TableCell>\n\n                    {/* Case Pack Multiplier */}\n                    <TableCell className=\"py-3.5\">\n                      <div className=\"flex items-center gap-1.5\">\n                        <Package className=\"text-muted-foreground size-3.5\" />\n                        <span className=\"text-foreground font-mono text-xs font-medium tabular-nums\">\n                          {product.casePack} units / case\n                        </span>\n                      </div>\n                    </TableCell>\n\n                    {/* Pricing (MSRP vs Wholesale) */}\n                    <TableCell className=\"py-3.5\">\n                      <div className=\"space-y-0.5\">\n                        <div className=\"text-foreground text-sm font-semibold tabular-nums\">\n                          {formatCurrency(product.wholesaleUnitPrice)}\n                          <span className=\"text-muted-foreground text-xs font-normal\"> wholesale</span>\n                        </div>\n                        <div className=\"text-muted-foreground flex items-center gap-1.5 text-xs\">\n                          <span className=\"tabular-nums line-through\">\n                            {formatCurrency(product.msrpUnitPrice)} MSRP\n                          </span>\n                          <span className=\"text-success font-medium\">\n                            -\n                            {Math.round(\n                              ((product.msrpUnitPrice - product.wholesaleUnitPrice) / product.msrpUnitPrice) * 100,\n                            )}\n                            %\n                          </span>\n                        </div>\n                      </div>\n                    </TableCell>\n\n                    {/* Quantity Stepper Input */}\n                    <TableCell className=\"py-3.5\">\n                      <div className=\"space-y-1\">\n                        <div className=\"flex items-center gap-1\">\n                          <Button\n                            aria-label=\"Decrease cases\"\n                            variant=\"outline\"\n                            size=\"xs\"\n                            className=\"size-7 p-0\"\n                            disabled={product.cases <= 0}\n                            onClick={() => updateCases(product.id, -1)}\n                          >\n                            <Minus className=\"size-3\" />\n                          </Button>\n                          <Input\n                            value={product.cases}\n                            type=\"number\"\n                            min={0}\n                            max={product.availableCases}\n                            className=\"h-7 w-16 text-center font-mono text-xs tabular-nums\"\n                            onChange={(e) => setCases(product.id, e.target.value)}\n                          />\n                          <Button\n                            aria-label=\"Increase cases\"\n                            variant=\"outline\"\n                            size=\"xs\"\n                            className=\"size-7 p-0\"\n                            disabled={product.cases >= product.availableCases}\n                            onClick={() => updateCases(product.id, 1)}\n                          >\n                            <Plus className=\"size-3\" />\n                          </Button>\n                        </div>\n                        <div className=\"text-muted-foreground font-mono text-xs tabular-nums\">\n                          {product.cases} {product.cases === 1 ? 'case' : 'cases'} ={' '}\n                          <strong className=\"text-foreground\">{product.cases * product.casePack}</strong> units\n                        </div>\n                      </div>\n                    </TableCell>\n\n                    {/* Stock Status */}\n                    <TableCell className=\"py-3.5\">\n                      {product.availableCases > 50 ? (\n                        <Badge\n                          variant=\"outline\"\n                          className=\"border-success/30 bg-success/10 text-success text-xs font-medium\"\n                        >\n                          In Stock · {formatNumber(product.availableCases)} cases\n                        </Badge>\n                      ) : (\n                        <Badge\n                          variant=\"outline\"\n                          className=\"border-warning/30 bg-warning/10 text-warning text-xs font-medium\"\n                        >\n                          Low Stock · {product.availableCases} cases\n                        </Badge>\n                      )}\n                    </TableCell>\n\n                    {/* Line Total */}\n                    <TableCell className=\"py-3.5 text-right\">\n                      <div className=\"space-y-0.5\">\n                        <div className=\"text-foreground font-mono text-sm font-bold tabular-nums\">\n                          {formatCurrency(product.cases * product.casePack * product.wholesaleUnitPrice)}\n                        </div>\n                        {product.cases > 0 ? (\n                          <div className=\"text-success text-success font-mono text-xs tabular-nums\">\n                            Save{' '}\n                            {formatCurrency(\n                              product.cases * product.casePack * (product.msrpUnitPrice - product.wholesaleUnitPrice),\n                            )}\n                          </div>\n                        ) : (\n                          <div className=\"text-muted-foreground text-xs\">0 units</div>\n                        )}\n                      </div>\n                    </TableCell>\n\n                    {/* Row Clear Action */}\n                    <TableCell className=\"py-3.5 text-center\">\n                      {product.cases > 0 && (\n                        <Button\n                          variant=\"ghost\"\n                          size=\"xs\"\n                          className=\"text-muted-foreground hover:text-destructive size-7 p-0\"\n                          title=\"Clear row quantity\"\n                          onClick={() => clearLine(product.id)}\n                        >\n                          <Trash2 className=\"size-3.5\" />\n                        </Button>\n                      )}\n                    </TableCell>\n                  </TableRow>\n                ))}\n              </TableBody>\n            </Table>\n          </div>\n        </CardContent>\n      </Card>\n\n      {/* Sticky Order Summary Footer */}\n      <div className=\"bg-card/95 border-border sticky bottom-4 z-20 rounded-xl border p-4 shadow-lg backdrop-blur-md transition-colors sm:p-5\">\n        <div className=\"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between\">\n          {/* Summary Totals Metrics */}\n          <div className=\"grid grid-cols-2 gap-3 sm:grid-cols-4 sm:gap-6\">\n            {/* Total Units */}\n            <div className=\"space-y-0.5\">\n              <div className=\"text-muted-foreground text-xs font-medium\">Total Units</div>\n              <div className=\"font-mono text-base font-bold tabular-nums sm:text-lg\">\n                {formatNumber(totalUnits)} Units\n              </div>\n              <div className=\"text-muted-foreground font-mono text-xs tabular-nums\">{totalCases} Cases ordered</div>\n            </div>\n\n            {/* Wholesale Subtotal */}\n            <div className=\"space-y-0.5\">\n              <div className=\"text-muted-foreground text-xs font-medium\">Wholesale Subtotal</div>\n              <div className=\"font-mono text-base font-bold tabular-nums sm:text-lg\">\n                {formatCurrency(wholesaleSubtotal)}\n              </div>\n              <div className=\"text-muted-foreground text-xs\">MSRP {formatCurrency(msrpTotal)}</div>\n            </div>\n\n            {/* Tier Savings */}\n            <div className=\"space-y-0.5\">\n              <div className=\"text-muted-foreground text-xs font-medium\">Tier Volume Savings</div>\n              <div className=\"text-success text-success font-mono text-base font-bold tabular-nums sm:text-lg\">\n                -{formatCurrency(totalSavings)}\n              </div>\n              <div className=\"text-success text-xs font-medium\">{savingsPercent}% Margin Savings</div>\n            </div>\n\n            {/* Freight & Terms */}\n            <div className=\"space-y-0.5\">\n              <div className=\"text-muted-foreground text-xs font-medium\">Freight & Terms</div>\n              <div className=\"text-foreground flex items-center gap-1.5 text-xs font-semibold\">\n                <Truck className=\"text-primary size-3.5 shrink-0\" />\n                <span>{isFreeFreight ? 'Free Freight (>$10k)' : '$250 Ground'}</span>\n              </div>\n              <div className=\"text-muted-foreground text-xs\">{paymentTerms}</div>\n            </div>\n          </div>\n\n          {/* Submit & Secondary Actions */}\n          <div className=\"flex flex-wrap items-center gap-2.5 pt-2 lg:pt-0\">\n            <Button\n              aria-label=\"Download attachment\"\n              variant=\"outline\"\n              size=\"sm\"\n              className=\"text-xs font-medium\"\n              disabled={totalCases === 0}\n              onClick={handleExportCsv}\n            >\n              <Download className=\"mr-1.5 size-3.5\" />\n              Export CSV\n            </Button>\n\n            <Button\n              size=\"default\"\n              className=\"gap-2 text-xs font-semibold sm:text-sm\"\n              disabled={totalCases === 0 || isSubmitting}\n              onClick={handleSubmitOrder}\n            >\n              {!isSubmitting ? <Send className=\"size-4\" /> : <RefreshCw className=\"size-4 animate-spin\" />}\n              <span>{isSubmitting ? 'Processing PO...' : 'Submit Wholesale Purchase Order'}</span>\n            </Button>\n          </div>\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport default WholesaleB2bQuickOrder\n",
      "type": "registry:block",
      "target": "~/components/blocks/WholesaleB2bQuickOrder.tsx"
    }
  ],
  "dependencies": [
    "lucide-react"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://uipkge.dev/r/react/badge.json",
    "https://uipkge.dev/r/react/button.json",
    "https://uipkge.dev/r/react/card.json",
    "https://uipkge.dev/r/react/input.json",
    "https://uipkge.dev/r/react/table.json",
    "https://uipkge.dev/r/react/textarea.json"
  ],
  "description": "B2B wholesale bulk order matrix with volume tier pricing, case pack multipliers, and CSV SKU paste input.",
  "categories": [
    "commerce",
    "ecommerce"
  ]
}