/* global React */
// Shared icons + helpers for PaulosGarage.com

const Icon = {
  Car: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M8 28l3-10a4 4 0 0 1 4-3h18a4 4 0 0 1 4 3l3 10" />
      <rect x="5" y="28" width="38" height="10" rx="2" />
      <circle cx="14" cy="38" r="3.5" fill="#fff" />
      <circle cx="34" cy="38" r="3.5" fill="#fff" />
      <path d="M13 28h22" />
    </svg>
  ),
  Wrench: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M30 6a10 10 0 0 0-8.5 15.2L6 36.7 11.3 42l15.5-15.5A10 10 0 1 0 30 6z" />
      <circle cx="30" cy="16" r="3.2" />
    </svg>
  ),
  Piston: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinejoin="round" strokeLinecap="round" {...p}>
      <rect x="12" y="6" width="24" height="18" rx="1" />
      <path d="M12 10h24M12 14h24M12 18h24" />
      <path d="M20 24v8M28 24v8" />
      <rect x="16" y="32" width="16" height="4" rx="1" />
      <path d="M24 36v6" />
    </svg>
  ),
  Spring: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M16 6h16" />
      <path d="M12 10h24M12 16h24M12 22h24M12 28h24M12 34h24" />
      <path d="M16 42h16" />
    </svg>
  ),
  Brake: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="24" cy="24" r="16" />
      <circle cx="24" cy="24" r="6" />
      <path d="M24 8v6M24 34v6M8 24h6M34 24h6M13 13l4 4M31 31l4 4M35 13l-4 4M17 31l-4 4" />
    </svg>
  ),
  Bolt: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M26 4L10 26h10l-4 18 18-24H22l4-16z" />
    </svg>
  ),
  Paint: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="8" y="6" width="32" height="12" rx="1" />
      <path d="M14 18v6h20v-6" />
      <rect x="18" y="24" width="12" height="10" />
      <path d="M24 34v8" />
    </svg>
  ),
  Bulb: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M24 6a12 12 0 0 0-7 21.5c1.5 1.3 2 2.5 2 4V34h10v-2.5c0-1.5.5-2.7 2-4A12 12 0 0 0 24 6z" />
      <path d="M19 38h10M20 42h8" />
    </svg>
  ),
  Chat: (p) => (
    <svg viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M8 10h32v22H20l-8 8v-8H8z" />
    </svg>
  ),
  Search: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="11" cy="11" r="7" />
      <path d="M16 16l5 5" />
    </svg>
  ),
};

// Format numbers in Portuguese
const fmtViews = (n) => {
  n = Number(n) || 0;
  if (n >= 1000000) return (n / 1000000).toFixed(1).replace('.', ',') + ' mi';
  if (n >= 1000) return (n / 1000).toFixed(n >= 10000 ? 0 : 1).replace('.', ',') + ' mil';
  return String(n);
};
const fmtDate = (iso) => {
  if (!iso) return '';
  const d = new Date(iso);
  const mo = ['JAN','FEV','MAR','ABR','MAI','JUN','JUL','AGO','SET','OUT','NOV','DEZ'];
  return `${String(d.getDate()).padStart(2,'0')} ${mo[d.getMonth()]} ${d.getFullYear()}`;
};
const ytThumb = (id) => `https://i.ytimg.com/vi/${id}/hqdefault.jpg`;

// Shared car definitions
const CARS = [
  { id: 'gol',      name: 'VW GOL',         spec: '2003 · Motor AP 1.6',          count: 319 },
  { id: 'brasilia', name: 'VW BRASÍLIA',    spec: '1979 · Motor 1.6 Aircooled',   count: 142 },
  { id: 'ka',       name: 'FORD KA',        spec: '1998 · Motor Endura',          count: 97  },
  { id: 's10',      name: 'GM S10',         spec: '1996 · Motor 2.2 EFI',         count: 88  },
  { id: 'fit',      name: 'HONDA FIT',      spec: '2004 · Motor 1.4 CVT',         count: 71  },
  { id: 'crv',      name: 'HONDA CR-V',     spec: '2009 · Motor 2.0',             count: 54  },
];

const TOPICS = [
  { id: 'motor',     label: 'MOTOR',              count: 287, ico: Icon.Piston },
  { id: 'freios',    label: 'FREIOS',             count: 64,  ico: Icon.Brake  },
  { id: 'suspensao', label: 'SUSPENSÃO',          count: 79,  ico: Icon.Spring },
  { id: 'eletrica',  label: 'ELÉTRICA',           count: 103, ico: Icon.Bolt   },
  { id: 'funilaria', label: 'FUNILARIA & PINTURA',count: 42,  ico: Icon.Paint  },
  { id: 'dicas',     label: 'DICAS GERAIS',       count: 176, ico: Icon.Bulb   },
];

Object.assign(window, { Icon, fmtViews, fmtDate, ytThumb, CARS, TOPICS });
