import React, { useState } from 'react'; import '../styles/OrderStatus.scss'; import { Truck, FileText, HelpCircle, MessageSquare, Calendar, Download } from 'lucide-react'; const OrderStatus = ({ order, onAction, conversationId }) => { if (!order || typeof order !== 'object') { return null; } const [noteText, setNoteText] = useState(''); const [noteError, setNoteError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [showNotesForm, setShowNotesForm] = useState(false); const [successMessage, setSuccessMessage] = useState(''); const { order_number = '', status = 'unknown', date_created, total, shipping_method, shipping_address, tracking_number, items = [] } = order; const formatDate = (dateString) => { if (!dateString) return ''; return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }); }; const getStatusEmoji = (status) => { const emojis = { 'pending': '⏳', 'processing': '🏭', 'on-hold': '⏸️', 'completed': 'βœ…', 'cancelled': '❌', 'refunded': 'πŸ’°', 'failed': '⚠️', 'shipping': '🚚' }; return emojis[status?.toLowerCase()] || 'πŸ“¦'; }; const getAvailableActions = () => { const actions = []; actions.push({ id: 'download_invoice', label: 'Download Invoice', icon: Download, description: 'Get a copy of your order invoice' }); //if (tracking_number) { actions.push({ id: 'track_order', label: 'Track Order', icon: Truck, description: 'View shipping status and location' }); //} return actions; }; const handleAction = (actionId) => { if (onAction) { onAction({ type: actionId, order_number: order_number }); } }; const handleNoteSubmit = async () => { if (!noteText.trim()) { setNoteError('Please enter your question or issue'); setSuccessMessage(''); return; } setIsSubmitting(true); try { const response = await fetch(`${AiskData.apiUrl}/submit-inquiry`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ order_number: order_number, conversation_id: conversationId, note: noteText }) }); if (response.ok) { setNoteText(''); setNoteError(''); setSuccessMessage('βœ… Inquiry submitted successfully!'); setTimeout(() => { setShowNotesForm(false); setSuccessMessage(''); // Clear success message }, 3000); onAction({ type: 'inquiry_submitted' }); } else { throw new Error('Failed to submit inquiry'); } } catch (error) { setNoteError('Failed to submit inquiry. Please try again.'); setSuccessMessage(''); } finally { setIsSubmitting(false); } }; const actions = getAvailableActions(); return (
{/* Order Header */}

Order #{order_number}

{getStatusEmoji(status)} {status.toString().toUpperCase()}
{/* Action Buttons */} {/*
{actions.map((action) => ( ))}
*/} {/* Order Details */}
πŸ“… Date: {formatDate(date_created)}
πŸ’° Total: {total}
{shipping_method && (
🚚 Shipping: {shipping_method}
)} {shipping_address && (
πŸ“ Address: {shipping_address}
)} {tracking_number && (
πŸ“¦ Tracking: {tracking_number}
)}
{/* Order Items */} {Array.isArray(items) && items.length > 0 && (

πŸ›οΈ Order Items

{items.map((item, index) => (
{item.image && (
{item.name}
)}
{item.name || 'Unknown Item'}
x{item.quantity || 1} {item.total || ''}
))}
)} {/* Support Section */}
{!showNotesForm ? (
) : (

How can we help you?