import { Badge } from '@astryxdesign/core/Badge';

// ==============================|| STATUS CHIP ||============================== //
// Soft-filled status chips used across orders, deliveries, riders, invoices.

const MAP = {
  // orders / deliveries
  pending: { variant: 'warning', label: 'Pending' },
  created: { variant: 'info', label: 'Created' },
  assigned: { variant: 'info', label: 'Assigned' },
  accepted: { variant: 'info', label: 'Accepted' },
  arrived: { variant: 'info', label: 'Arrived' },
  picked: { variant: 'red', label: 'Picked' },
  'in-transit': { variant: 'info', label: 'In Transit' },
  active: { variant: 'red', label: 'Active' },
  delivered: { variant: 'success', label: 'Delivered' },
  completed: { variant: 'success', label: 'Completed' },
  skipped: { variant: 'warning', label: 'Skipped' },
  failed: { variant: 'error', label: 'Failed' },
  cancelled: { variant: 'error', label: 'Cancelled' },
  'miler-assigned': { variant: 'info', label: 'Miler Assigned' },
  'pending-pickup': { variant: 'warning', label: 'Pending Pickup' },
  // clients (doormile_clients)
  newclient: { variant: 'info', label: 'New Client' },
  contacted: { variant: 'warning', label: 'Contacted' },
  onboarded: { variant: 'success', label: 'Onboarded' },
  lost: { variant: 'error', label: 'Lost' },
  // team users (doormile_auth)
  admin: { variant: 'red', label: 'Admin' },
  rep: { variant: 'info', label: 'Rep' },
  manager: { variant: 'success', label: 'Manager' },
  support: { variant: 'warning', label: 'Support' },
  // riders / tenants
  online: { variant: 'success', label: 'Online' },
  offline: { variant: 'neutral', label: 'Offline' },
  'on-delivery': { variant: 'info', label: 'On Delivery' },
  inactive: { variant: 'neutral', label: 'Inactive' },
  // invoices
  paid: { variant: 'success', label: 'Paid' },
  open: { variant: 'info', label: 'Open' },
  overdue: { variant: 'error', label: 'Overdue' },
  prepaid: { variant: 'success', label: 'Prepaid' },
  cod: { variant: 'warning', label: 'COD' }
};

export default function StatusChip({ status, label }) {
  const key = String(status || '').toLowerCase().replace(/\s+/g, '-');
  const humanized = String(status || '').replace(/[_-]+/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
  const cfg = MAP[key] || { variant: 'neutral', label: humanized || status };
  return (
    <Badge
      variant={cfg.variant}
      label={label || cfg.label}
    />
  );
}
