// Shared visual primitives for Satindica

const fmtCLP = (n) => '$' + n.toLocaleString('es-CL');

// Striped placeholder used in product cards / hero — original SVG, no real product imagery
function ProductGlyph({ variant = 1, label = 'producto' }) {
  // 8 variants: subtle hue shifts within emerald/graphite range
  const palettes = [
    ['#0d2a1a', '#1a5c38', '#2ECC71'],
    ['#102a30', '#16494f', '#2ECC71'],
    ['#1a1a1a', '#2a2a2a', '#C9A84C'],
    ['#0e1f14', '#1a5c38', '#7be0a6'],
    ['#1c1c1c', '#2a2a2a', '#2ECC71'],
    ['#0d2a1a', '#16494f', '#C9A84C'],
    ['#111111', '#1a5c38', '#2ECC71'],
    ['#1c1c1c', '#3a3a3a', '#C9A84C'],
  ];
  const [bg, mid, accent] = palettes[(variant - 1) % palettes.length];
  // Geometry: a centered diamond + ring + striped backdrop
  const stripes = [];
  for (let i = 0; i < 14; i++) {
    stripes.push(
      <line key={i} x1={i*30 - 100} y1={-20} x2={i*30 + 200} y2={420}
            stroke={mid} strokeWidth="1" opacity="0.35" />
    );
  }
  return (
    <svg viewBox="0 0 400 400" preserveAspectRatio="xMidYMid slice"
         style={{ width: '100%', height: '100%', display: 'block', background: bg }}>
      <g>{stripes}</g>
      <circle cx="200" cy="200" r="118" fill="none" stroke={accent} strokeWidth="1.5" opacity="0.55" />
      <circle cx="200" cy="200" r="78"  fill="none" stroke={accent} strokeWidth="1"   opacity="0.35" />
      <rect x="170" y="170" width="60" height="60" transform="rotate(45 200 200)"
            fill="none" stroke={accent} strokeWidth="1.5" />
      <text x="200" y="206" textAnchor="middle"
            fontFamily="ui-monospace, 'SF Mono', Menlo, monospace"
            fontSize="11" fill={accent} letterSpacing="2" opacity="0.85">
        {label.toUpperCase()}
      </text>
    </svg>
  );
}

function Badge({ tone = 'emerald', children }) {
  const tones = {
    emerald: { bg: 'rgba(46,204,113,0.12)', bd: 'rgba(46,204,113,0.55)', fg: '#2ECC71' },
    gold:    { bg: 'rgba(201,168,76,0.12)', bd: 'rgba(201,168,76,0.55)', fg: '#C9A84C' },
    red:     { bg: 'rgba(220,80,80,0.12)',  bd: 'rgba(220,80,80,0.55)',  fg: '#E27272' },
    neutral: { bg: 'rgba(255,255,255,0.06)', bd: 'rgba(255,255,255,0.18)', fg: '#cfcfcf' },
  };
  const t = tones[tone] || tones.emerald;
  return (
    <span style={{
      display: 'inline-flex', alignItems: 'center', gap: 6,
      padding: '4px 9px', borderRadius: 999,
      fontFamily: 'ui-monospace, "SF Mono", Menlo, monospace',
      fontSize: 10, letterSpacing: '0.12em', textTransform: 'uppercase',
      background: t.bg, border: `1px solid ${t.bd}`, color: t.fg, fontWeight: 600,
    }}>{children}</span>
  );
}

function Logo({ size = 22 }) {
  return (
    <img
      src="common-articles/Logo Grow Satindica 1.png"
      height={Math.round(size * 2)}
      alt="Grow Satindica"
      style={{ display: 'block' }}
    />
  );
}

// Tiny custom icons (pure geometry — no detailed illustrations)
const Icon = {
  search: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6">
      <circle cx="11" cy="11" r="6.5" /><line x1="16" y1="16" x2="21" y2="21" strokeLinecap="round"/>
    </svg>
  ),
  user: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6">
      <circle cx="12" cy="8" r="4" /><path d="M4 21c1-5 5-7 8-7s7 2 8 7" strokeLinecap="round"/>
    </svg>
  ),
  cart: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6">
      <path d="M4 5h2l2.5 11h11l2-8H7" strokeLinecap="round" strokeLinejoin="round"/>
      <circle cx="10" cy="20" r="1.4" fill="currentColor" stroke="none"/>
      <circle cx="18" cy="20" r="1.4" fill="currentColor" stroke="none"/>
    </svg>
  ),
  arrow: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6">
      <line x1="4" y1="12" x2="20" y2="12" strokeLinecap="round"/>
      <polyline points="14 6 20 12 14 18" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  star: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 2l2.9 6.2 6.6.7-4.9 4.6 1.4 6.6L12 16.9 5.9 20.1l1.4-6.6L2.4 8.9l6.7-.7z"/>
    </svg>
  ),
  // Category glyphs — geometric, all share visual language
  cat: {
    semillas: (
      <svg viewBox="0 0 40 40" width="28" height="28" fill="none" stroke="currentColor" strokeWidth="1.5">
        <ellipse cx="20" cy="22" rx="9" ry="13" />
        <path d="M20 9v26" />
      </svg>
    ),
    iluminacion: (
      <svg viewBox="0 0 40 40" width="28" height="28" fill="none" stroke="currentColor" strokeWidth="1.5">
        <path d="M14 6h12l-2 14H16z" /><path d="M17 24h6v6h-6z" /><path d="M19 32h2" />
      </svg>
    ),
    fertilizantes: (
      <svg viewBox="0 0 40 40" width="28" height="28" fill="none" stroke="currentColor" strokeWidth="1.5">
        <path d="M14 8h12v6l-2 18H16L14 14z" /><path d="M14 14h12" />
      </svg>
    ),
    sustratos: (
      <svg viewBox="0 0 40 40" width="28" height="28" fill="none" stroke="currentColor" strokeWidth="1.5">
        <rect x="6" y="20" width="28" height="14" /><path d="M10 20l4-10h12l4 10" />
      </svg>
    ),
    carpas: (
      <svg viewBox="0 0 40 40" width="28" height="28" fill="none" stroke="currentColor" strokeWidth="1.5">
        <path d="M6 32V10h28v22" /><path d="M6 10l14 8 14-8" /><path d="M20 18v14" />
      </svg>
    ),
    riego: (
      <svg viewBox="0 0 40 40" width="28" height="28" fill="none" stroke="currentColor" strokeWidth="1.5">
        <path d="M20 6c5 7 8 11 8 15a8 8 0 11-16 0c0-4 3-8 8-15z" />
      </svg>
    ),
    parafernalia: (
      <svg viewBox="0 0 40 40" width="28" height="28" fill="none" stroke="currentColor" strokeWidth="1.5">
        <circle cx="20" cy="20" r="10" /><circle cx="20" cy="20" r="3" /><path d="M20 6v4M20 30v4M6 20h4M30 20h4"/>
      </svg>
    ),
    kits: (
      <svg viewBox="0 0 40 40" width="28" height="28" fill="none" stroke="currentColor" strokeWidth="1.5">
        <rect x="7" y="12" width="26" height="20" /><path d="M14 12V8h12v4" /><path d="M7 22h26" />
      </svg>
    ),
  },
  social: {
    ig: (
      <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
        <rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1" fill="currentColor"/>
      </svg>
    ),
    tt: (
      <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
        <path d="M14 3v11.2a3.3 3.3 0 11-3.3-3.3v3a.3.3 0 10.3.3V3z" /><path d="M14 3c0 2.6 2 4.6 4.6 4.6V10C16 10 14 9 13 7.6"/>
      </svg>
    ),
    yt: (
      <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
        <path d="M22 12s0-3.4-.4-5a2.6 2.6 0 00-1.8-1.8C17.8 5 12 5 12 5s-5.8 0-7.8.2A2.6 2.6 0 002.4 7C2 8.6 2 12 2 12s0 3.4.4 5a2.6 2.6 0 001.8 1.8c2 .2 7.8.2 7.8.2s5.8 0 7.8-.2A2.6 2.6 0 0021.6 17c.4-1.6.4-5 .4-5zM10 15V9l5 3z"/>
      </svg>
    ),
  },
};

Object.assign(window, { ProductGlyph, Badge, Logo, Icon, fmtCLP });
