'use client'; import React, { useState } from 'react'; import { toast } from 'react-hot-toast'; import { Camera, Check, RefreshCw, X, Image as ImageIcon, Sparkles, Hash, Layout, Layers, Package, ChevronDown } from 'lucide-react'; import { useAIExtraction } from '@/hooks/useAIExtraction'; import { ImageAdjustmentModal } from './ImageAdjustmentModal'; interface AIOnboardingProps { onCancel: () => void; onComplete: (itemData: any) => void; categories: any[]; inventory: any[]; } export default function AIOnboarding({ onCancel, onComplete, categories, inventory }: AIOnboardingProps) { const [showImageAdjustment, setShowImageAdjustment] = useState(false); const [adjustingItemIndex, setAdjustingItemIndex] = useState(null); const [pendingItemData, setPendingItemData] = useState(null); const { image, setImage, uploading, extractedItems, setExtractedItems, editingIndex, setEditingIndex, mode, setMode, isLive, videoRef, canvasRef, fileInputRef, existingTypes, existingBoxes, startLiveCamera, stopLiveCamera, captureSnapshot, processImage, confirmSingleItem: hookConfirmSingleItem, confirmAllItems: hookConfirmAllItems, updateEditingItem, handleFileChange } = useAIExtraction(inventory, onComplete); const confirmSingleItem = (index: number) => { if (!extractedItems[index]) return; const data = extractedItems[index]; const skipPhoto = data._skipPhoto === true; if (skipPhoto || !image) { hookConfirmSingleItem(index); return; } setPendingItemData({ index, data, skipPhoto }); setAdjustingItemIndex(index); setShowImageAdjustment(true); }; const handleImageAdjustmentConfirm = async (adjustments: { rotation: number; cropBounds: { x: number; y: number; width: number; height: number } } | null) => { if (!pendingItemData) return; const { index } = pendingItemData; if (adjustments && extractedItems[index]) { // Override AI-detected values with user adjustments const updatedItems = [...extractedItems]; updatedItems[index] = { ...updatedItems[index], image_processing: { ...updatedItems[index].image_processing, rotation_degrees: adjustments.rotation, crop_bounds: { x: Math.round(adjustments.cropBounds.x), y: Math.round(adjustments.cropBounds.y), width: Math.round(adjustments.cropBounds.width), height: Math.round(adjustments.cropBounds.height) }, user_adjusted: true } }; setExtractedItems(updatedItems); } // Now call the hook's confirm with the updated data hookConfirmSingleItem(index); setShowImageAdjustment(false); setAdjustingItemIndex(null); setPendingItemData(null); }; const handleImageAdjustmentCancel = () => { setShowImageAdjustment(false); setAdjustingItemIndex(null); setPendingItemData(null); }; const confirmAllItems = async () => { await hookConfirmAllItems(); onCancel(); // Close modal after bulk completion }; return (

AI Discovery

Powered by Gemini 2.0 Flash

{!image && !isLive ? (

{mode === 'box' ? 'Deep Box Analysis' : 'Multi-Item Extraction'}

{mode === 'box' ? 'Scan container labels to identify storage locations' : 'Identify multiple technical items from a single photo or label'}

) : isLive ? ( // LIVE VIEWFINDER MODE