// icons.jsx — 线性细描边 icon (1.5px 描边,统一 24x24 viewBox)
// 全部使用 currentColor,可被父级 color 控制

const Icon = ({ d, size = 22, stroke = 1.5, fill, children, viewBox = '0 0 24 24' }) => (
  <svg width={size} height={size} viewBox={viewBox} fill="none"
       stroke="currentColor" strokeWidth={stroke}
       strokeLinecap="round" strokeLinejoin="round">
    {children || <path d={d} />}
  </svg>
);

// ── 食材 icons ──
// All icons designed to read well at 16px (the size used in ingredient list).
// Strategy: bold silhouette > fine detail. Round body for fruit, vertical lines for leafy/long.
const FoodIcons = {
  tomato: ({ size = 22 }) => (
    <Icon size={size}>
      {/* round body */}
      <circle cx="12" cy="14" r="6" />
      {/* 5-pointed leaf calyx — quick star strokes */}
      <path d="M12 8V5M12 8l-2.5-2M12 8l2.5-2M9.5 7.5L8 7M14.5 7.5L16 7" />
    </Icon>
  ),
  egg: ({ size = 22 }) => (
    <Icon size={size}>
      {/* classic egg ovoid — slightly pointed top, rounder bottom */}
      <path d="M12 4c-3 0-5.5 4-5.5 9.5 0 4 2.5 6.5 5.5 6.5s5.5-2.5 5.5-6.5C17.5 8 15 4 12 4z" />
    </Icon>
  ),
  scallion: ({ size = 22 }) => (
    <Icon size={size}>
      {/* 3 long green leaves */}
      <path d="M9.5 13V3M12 13V2M14.5 13V3" />
      {/* white bulb at root */}
      <ellipse cx="12" cy="17" rx="3.5" ry="4" />
      {/* divider line between green and white */}
      <path d="M9 13h6" />
    </Icon>
  ),
  garlic: ({ size = 22 }) => (
    <Icon size={size}>
      {/* bulb tear-drop */}
      <path d="M12 4c-.4 0-.7.4-1 1-2.5 1-4 3.5-4 7 0 4.5 2.5 7.5 5 7.5s5-3 5-7.5c0-3.5-1.5-6-4-7-.3-.6-.6-1-1-1z" />
      {/* clove divisions — 2 curves tracing cloves */}
      <path d="M12 5.5v14M9 12c.5 3 1.5 5.5 3 7M15 12c-.5 3-1.5 5.5-3 7" />
    </Icon>
  ),
  salt: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M8 9.5h8l-.7 9.5a1.5 1.5 0 0 1-1.5 1.4h-3.6a1.5 1.5 0 0 1-1.5-1.4L8 9.5z" />
      <path d="M9 9.5V6.5a3 3 0 0 1 6 0v3" />
      <path d="M11 13v.5M13 15v.5M11.5 17v.5" />
    </Icon>
  ),
  sugar: ({ size = 22 }) => (
    <Icon size={size}>
      <rect x="5" y="7" width="14" height="11" rx="1" />
      <path d="M5 11h14M9 7v4M14 7v4M9 14v4M14 14v4" />
    </Icon>
  ),
  soy: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M9 3.5h6v2.5l1.5 1.5v11.5a1.5 1.5 0 0 1-1.5 1.5h-6a1.5 1.5 0 0 1-1.5-1.5V7.5L9 6V3.5z" />
      <path d="M7.5 11h9" />
    </Icon>
  ),
  paste: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M8 8h8v11.5a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1V8z" />
      <path d="M9.5 8V5.5a2.5 2.5 0 0 1 5 0V8" />
      <path d="M8 12h8" />
    </Icon>
  ),
  oil: ({ size = 22 }) => (
    <Icon size={size}>
      {/* bottle silhouette - narrow neck, wide body */}
      <path d="M10 4h4v3l1.5 2v9.5a2 2 0 0 1-2 2h-3a2 2 0 0 1-2-2V9l1.5-2V4z" />
      {/* liquid level line */}
      <path d="M8.5 12h7" />
      {/* drop shape inside */}
      <path d="M12 14c-.7.5-1 1.2-1 2 0 .8.5 1.2 1 1.2s1-.4 1-1.2c0-.8-.3-1.5-1-2z" fill="currentColor" stroke="none" />
    </Icon>
  ),
  broccoli: ({ size = 22 }) => (
    <Icon size={size}>
      <circle cx="9" cy="8" r="2.5" />
      <circle cx="14.5" cy="7" r="2.3" />
      <circle cx="13" cy="11" r="2.3" />
      <circle cx="8" cy="11.5" r="2" />
      <path d="M11 13v6M11 19h-2M11 19h2.5" />
    </Icon>
  ),
  chili: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M6 18c5-1 11-5 13-12-1-.5-2-.5-3 0-1 4-4 8-10 10v2z" />
      <path d="M19 6c.5-1 .5-2 0-2.5s-1.5-.5-2.5 0" />
    </Icon>
  ),
  oyster: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M4 13c0-4.5 3.5-8 8-8s8 3.5 8 8H4z" />
      <path d="M4 13h16v3a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-3z" />
      <path d="M8 13l1-4M12 13V7M16 13l-1-4" />
    </Icon>
  ),
  meat: ({ size = 22 }) => (
    <Icon size={size}>
      {/* Steak/chop silhouette: irregular round shape with a small bone on one side */}
      <path d="M5 13c0-4 3-7 7-7s7 3 7 6c0 4-3 7-7 7-3 0-7-2-7-6z" />
      {/* fat marbling — small inner curve */}
      <path d="M9 13c1-1.5 2.5-2 4-2s3 .5 4 2" />
      {/* small bone on right edge */}
      <circle cx="17" cy="11" r="1.4" fill="currentColor" />
    </Icon>
  ),
  starch: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M6 6h12l-1.5 13a1.5 1.5 0 0 1-1.5 1.4h-6a1.5 1.5 0 0 1-1.5-1.4L6 6z" />
      <path d="M6 6l1-2.5h10L18 6" />
      <path d="M9 11l.5 6M14.5 11l-.5 6M11.7 11v6" />
    </Icon>
  ),
  wine: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M9 3.5h6v3.5c1.5.5 2.5 2 2.5 4S16 14.5 13.5 15v5.5h-3V15c-2.5-.5-4-2-4-4s1-3.5 2.5-4V3.5z" />
      <path d="M9 3.5h6" />
    </Icon>
  ),
  vinegar: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M10 3.5h4v2.5l1 1.5v11a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-11l1-1.5V3.5z" />
      <path d="M9 11h6" />
      <path d="M11 14v.5M13 16v.5" />
    </Icon>
  ),
  sesame: ({ size = 22 }) => (
    <Icon size={size}>
      <ellipse cx="9" cy="10" rx="1.5" ry="2.5" transform="rotate(-20 9 10)" />
      <ellipse cx="14" cy="9" rx="1.5" ry="2.5" transform="rotate(20 14 9)" />
      <ellipse cx="11.5" cy="14.5" rx="1.5" ry="2.5" />
    </Icon>
  ),
  rice: ({ size = 22 }) => (
    <Icon size={size}>
      {/* bowl rim and body */}
      <path d="M4 13h16a8 8 0 0 1-7.5 7H11.5A8 8 0 0 1 4 13z" />
      {/* rice grains piled on top */}
      <ellipse cx="9" cy="11" rx="1.2" ry="2" transform="rotate(-25 9 11)" />
      <ellipse cx="12" cy="9.5" rx="1.2" ry="2" />
      <ellipse cx="15" cy="11" rx="1.2" ry="2" transform="rotate(25 15 11)" />
    </Icon>
  ),
  pepper: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M8 7h8v3l-1 1v8a1.5 1.5 0 0 1-1.5 1.5h-3A1.5 1.5 0 0 1 9 19v-8l-1-1V7z" />
      <path d="M11 4h2v3h-2z" />
      <path d="M11 13v.5M13 15v.5M11.5 17v.5" />
    </Icon>
  ),
};

// ── UI icons ──
const UIIcons = {
  back: ({ size = 22 }) => <Icon size={size}><path d="M15 5l-7 7 7 7" /></Icon>,
  forward: ({ size = 22 }) => <Icon size={size}><path d="M9 5l7 7-7 7" /></Icon>,
  bookmark: ({ size = 22, filled }) => (
    <Icon size={size}>
      <path d="M7 4h10v17l-5-3.5L7 21V4z" fill={filled ? 'currentColor' : 'none'} />
    </Icon>
  ),
  share: ({ size = 22 }) => (
    <Icon size={size}>
      <circle cx="6" cy="12" r="2" />
      <circle cx="18" cy="6" r="2" />
      <circle cx="18" cy="18" r="2" />
      <path d="M8 11l8-4M8 13l8 4" />
    </Icon>
  ),
  search: ({ size = 22 }) => (
    <Icon size={size}><circle cx="11" cy="11" r="6" /><path d="M16 16l4 4" /></Icon>
  ),
  filter: ({ size = 22 }) => (
    <Icon size={size}><path d="M4 6h16M7 12h10M10 18h4" /></Icon>
  ),
  clock: ({ size = 22 }) => (
    <Icon size={size}><circle cx="12" cy="12" r="8" /><path d="M12 8v4l3 2" /></Icon>
  ),
  flame: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M12 3c1 3 4 4.5 4 8.5a4 4 0 0 1-8 0c0-2 1-3 1-5 1.5 1 3 1.5 3-3.5z" />
    </Icon>
  ),
  user: ({ size = 22 }) => (
    <Icon size={size}><circle cx="12" cy="9" r="3" /><path d="M5 20c0-3.5 3-6 7-6s7 2.5 7 6" /></Icon>
  ),
  check: ({ size = 22 }) => <Icon size={size}><path d="M5 12l5 5 9-11" /></Icon>,
  plus: ({ size = 22 }) => <Icon size={size}><path d="M12 5v14M5 12h14" /></Icon>,
  minus: ({ size = 22 }) => <Icon size={size}><path d="M5 12h14" /></Icon>,
  more: ({ size = 22 }) => (
    <Icon size={size}>
      <circle cx="6" cy="12" r="1" fill="currentColor" />
      <circle cx="12" cy="12" r="1" fill="currentColor" />
      <circle cx="18" cy="12" r="1" fill="currentColor" />
    </Icon>
  ),
  home: ({ size = 22 }) => (
    <Icon size={size}><path d="M4 11l8-7 8 7v9a1 1 0 0 1-1 1h-4v-7h-6v7H5a1 1 0 0 1-1-1v-9z" /></Icon>
  ),
  book: ({ size = 22 }) => (
    <Icon size={size}><path d="M5 4h6a3 3 0 0 1 3 3v13a2 2 0 0 0-2-2H5V4z" /><path d="M19 4h-6a3 3 0 0 0-3 3v13a2 2 0 0 1 2-2h7V4z" /></Icon>
  ),
  heart: ({ size = 22, filled }) => (
    <Icon size={size}>
      <path d="M12 19s-7-4.5-7-10a4 4 0 0 1 7-2.5A4 4 0 0 1 19 9c0 5.5-7 10-7 10z"
            fill={filled ? 'currentColor' : 'none'} />
    </Icon>
  ),
  timer: ({ size = 22 }) => (
    <Icon size={size}><circle cx="12" cy="13" r="7" /><path d="M12 9v4l2 2M9 3h6M11 3v3" /></Icon>
  ),
  serving: ({ size = 22 }) => (
    <Icon size={size}><path d="M3 12c0-3 4-5 9-5s9 2 9 5H3z" /><path d="M3 12c0 3 4 7 9 7s9-4 9-7" /></Icon>
  ),
  chef: ({ size = 22 }) => (
    <Icon size={size}>
      <path d="M7 12c-2 0-3.5-1.5-3.5-3.5S5 5 7 5c.5-1.5 2-2.5 3.5-2.5S13 3.5 13.5 5h.5c2 0 3.5 1.5 3.5 3.5S16 12 14 12v6H7v-6z" />
      <path d="M7 16h7" />
    </Icon>
  ),
};

window.FoodIcons = FoodIcons;
window.UIIcons = UIIcons;
