const Icon = {
  Hall: ({ size=26, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 10 12 3l9 7"/><path d="M5 9v11h5v-6h4v6h5V9"/>
    </svg>
  ),
  Schedule: ({ size=26, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="5" width="18" height="16" rx="2"/><path d="M8 3v4M16 3v4M3 10h18"/>
    </svg>
  ),
  Crown: ({ size=26, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 8l4 4 5-6 5 6 4-4v9H3z"/><path d="M3 19h18"/>
    </svg>
  ),
  Wallet: ({ size=26, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="6" width="18" height="14" rx="2"/><path d="M3 10h18"/><circle cx="16.5" cy="15.5" r="1" fill={color}/>
    </svg>
  ),
  Person: ({ size=26, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 3.6-6 8-6s8 2 8 6"/>
    </svg>
  ),
  Bell: ({ size=24, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M6 10a6 6 0 1 1 12 0c0 5 2 6 2 6H4s2-1 2-6"/><path d="M10 20a2 2 0 0 0 4 0"/>
    </svg>
  ),
  ChevronR: ({ size=16, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="m9 6 6 6-6 6"/></svg>
  ),
  ChevronL: ({ size=16, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="m15 6-6 6 6 6"/></svg>
  ),
  ChevronD: ({ size=16, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="m6 9 6 6 6-6"/></svg>
  ),
  Phone: ({ size=18, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.1 4.2 2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1 1 .4 2 .7 2.9a2 2 0 0 1-.5 2.1L8.1 10a16 16 0 0 0 6 6l1.3-1.3a2 2 0 0 1 2.1-.5c.9.3 1.9.6 2.9.7a2 2 0 0 1 1.6 2z"/>
    </svg>
  ),
  Pin: ({ size=16, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0z"/><circle cx="12" cy="10" r="3"/></svg>
  ),
  Car: ({ size=16, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M5 11l1.5-4.5A2 2 0 0 1 8.4 5h7.2a2 2 0 0 1 1.9 1.5L19 11"/><rect x="3" y="11" width="18" height="6" rx="2"/><circle cx="7.5" cy="17" r="1.5"/><circle cx="16.5" cy="17" r="1.5"/>
    </svg>
  ),
  Close: ({ size=18, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2.2" strokeLinecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>
  ),
  Check: ({ size=20, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="m4 12 5 5L20 7"/></svg>
  ),
  Search: ({ size=18, color }) => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2" strokeLinecap="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3-3"/></svg>
  ),
};

function BottomNav({ tab, onChange, dark, unread }) {
  const th = useTheme(dark);
  const tabs = [
    { key:'hall', label:'接單', Icon:Icon.Hall },
    { key:'schedule', label:'行程', Icon:Icon.Schedule },
    { key:'premium', label:'會員', Icon:Icon.Crown },
    { key:'finance', label:'帳務', Icon:Icon.Wallet },
    { key:'profile', label:'個人', Icon:Icon.Person },
  ];
  return (
    <div style={{
      display:'flex', background:th.surface, borderTop:`1px solid ${th.border}`,
      paddingTop:10, paddingBottom:'max(env(safe-area-inset-bottom,0px),8px)',
      zIndex:20, position:'relative',
    }}>
      {tabs.map(t => {
        const active = tab === t.key;
        return (
          <button key={t.key} onClick={() => onChange(t.key)} className="press" style={{
            flex:1, background:'transparent', border:'none', cursor:'pointer',
            display:'flex', flexDirection:'column', alignItems:'center', gap:3, padding:0,
          }}>
            <span style={{ position:'relative', display:'flex' }}>
              <t.Icon size={26} color={th.text} />
              {t.key==='hall' && unread>0 && (
                <span style={{ position:'absolute', top:-4, right:-8, background:th.danger, color:'#FFF', fontSize:FS(10), fontWeight:700, borderRadius:9, padding:'1px 5px', fontFamily:FONTS.mono }}>{unread>99?'99+':unread}</span>
              )}
            </span>
            <span style={{ fontSize:FS(12), fontWeight:active?700:500, color:th.text, opacity:active?1:.5 }}>{t.label}</span>
          </button>
        );
      })}
    </div>
  );
}
