/* eslint-disable */
const { useState, useEffect, useRef, useMemo, useCallback } = React;

/* ============== ICONS ============== */
const Icon = {
  Chat: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1.1-4.6A8 8 0 1 1 21 12Z" strokeLinecap="round" strokeLinejoin="round"/></svg>),
  Target: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1.5" fill="currentColor"/></svg>),
  Cal: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 9h18M8 3v4M16 3v4"/></svg>),
  Brain: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M9 4a3 3 0 0 0-3 3v1a3 3 0 0 0-2 5 3 3 0 0 0 2 5 3 3 0 0 0 3 3 3 3 0 0 0 3-2V6a3 3 0 0 0-3-2Z"/><path d="M15 4a3 3 0 0 1 3 3v1a3 3 0 0 1 2 5 3 3 0 0 1-2 5 3 3 0 0 1-3 3 3 3 0 0 1-3-2V6a3 3 0 0 1 3-2Z"/></svg>),
  Bell: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M6 8a6 6 0 0 1 12 0c0 6 2 8 2 8H4s2-2 2-8Z" strokeLinecap="round" strokeLinejoin="round"/><path d="M10 20a2 2 0 0 0 4 0"/></svg>),
  Gear: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 0 1-4 0v-.1a1.7 1.7 0 0 0-1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1A2 2 0 1 1 4.4 17l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 0 1 0-4h.1a1.7 1.7 0 0 0 1.5-1 1.7 1.7 0 0 0-.3-1.8l-.1-.1A2 2 0 1 1 7 4.4l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1A2 2 0 1 1 19.6 7l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 0 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1Z"/></svg>),
  Layers: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M12 3 2 8l10 5 10-5-10-5Z"/><path d="M2 13l10 5 10-5M2 18l10 5 10-5"/></svg>),
  HandOff: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M3 12h13M12 8l4 4-4 4"/><circle cx="20" cy="12" r="2"/></svg>),
  Chart: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M4 19V5M4 19h16M8 15v-4M12 15V9M16 15V7"/></svg>),
  Tag: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M3 12V5a2 2 0 0 1 2-2h7l9 9-9 9-9-9Z"/><circle cx="8" cy="8" r="1.4" fill="currentColor"/></svg>),
  Crm: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="9" cy="8" r="3"/><path d="M3 20a6 6 0 0 1 12 0"/><path d="M15 11h6M15 15h6M15 19h4"/></svg>),
  Check: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" {...p}><path d="M5 12l5 5 9-11" strokeLinecap="round" strokeLinejoin="round"/></svg>),
  Sun: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>),
  Moon: (p) => (<svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z"/></svg>),
  Plus: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" {...p}><path d="M12 5v14M5 12h14" strokeLinecap="round"/></svg>),
  Arrow: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" {...p}><path d="M5 12h14M13 6l6 6-6 6" strokeLinecap="round" strokeLinejoin="round"/></svg>),
  Mail: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg>),
  Menu: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" {...p}><path d="M4 7h16M4 17h16" strokeLinecap="round"/></svg>),
  Close: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" {...p}><path d="M6 6l12 12M18 6 6 18" strokeLinecap="round"/></svg>),
};

/* ============== BRAND / TOOL LOGOS — slots for official SVGs ==============
   Each tool renders an <img> pointing to assets/brands/<slug>.svg with a
   per-tool class (e.g. `logo-whatsapp`). To swap in the real logo, just
   overwrite that SVG file. CSS rules in styles.css can selectively apply
   `filter: brightness(0) invert(1)` per class for logos that need to be
   forced to white.
*/
const brandLogo = (slug, alt) => {
  const C = (p = {}) => {
    const { width, height, className = '', style, ...rest } = p;
    return (
      <img
        src={`assets/brands/${slug}.svg`}
        alt={alt}
        className={`brand-logo logo-${slug} ${className}`.trim()}
        style={style}
        {...rest}
      />
    );
  };
  C.displayName = `Brand(${alt})`;
  C.slug = slug;
  return C;
};

const Tool = {
  Instagram: brandLogo('instagram', 'Instagram'),
  WhatsApp:  brandLogo('whatsapp', 'WhatsApp'),
  Gmail:     brandLogo('email', 'Email'),
  Drive:     brandLogo('drive', 'Google Drive'),
  Excel:     brandLogo('excel', 'Microsoft Excel'),
  Tiendanube:brandLogo('tiendanube', 'Tiendanube'),
  Web:       brandLogo('web', 'Sitio Web'),
  Webhook:   brandLogo('webhooks', 'Webhooks'),
  Mailchimp: brandLogo('mailchimp', 'Mailchimp'),
  GCal:      brandLogo('gcal', 'Google Calendar'),
  Calendly:  brandLogo('calendly', 'Calendly'),
  ML:        brandLogo('mercadolibre', 'MercadoLibre'),
  TikTok:    brandLogo('tiktok', 'TikTok'),
  Meta:      brandLogo('meta', 'Meta'),
  Shopify:   brandLogo('shopify', 'Shopify'),
  Claude:    brandLogo('claude', 'Claude'),
  ChatGPT:   brandLogo('chatgpt', 'ChatGPT'),
};

/* ============== WHINK LOGO ============== */
const WhinkLogo = ({ size = 28 }) => (
  <span style={{ display: 'inline-flex', alignItems: 'center', gap: 10 }}>
    <span
      role="img"
      aria-label="Whink"
      style={{
        display: 'block',
        width: size,
        height: size,
        flexShrink: 0,
        backgroundImage: 'url(assets/logo.svg)',
        backgroundSize: 'contain',
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center',
        transform: 'translateZ(0)',
      }}
    />
    <span style={{ fontWeight: 600, fontSize: size * 0.7, letterSpacing: '-0.02em' }}>Whink</span>
  </span>
);

/* ============== REVEAL HOOK ============== */
const useReveal = () => {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current; if (!el) return;
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) { el.classList.add('in'); io.unobserve(el); } });
    }, { rootMargin: '0px 0px -80px 0px', threshold: 0.05 });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return ref;
};
const Reveal = ({ children, delay = 0, variant, as: Tag = 'div', className = '', style = {}, ...rest }) => {
  const ref = useReveal();
  const baseClass = variant ? `reveal-${variant}` : 'reveal';
  return <Tag ref={ref} className={`${baseClass} ${className}`} style={{ transitionDelay: `${delay}ms`, ...style }} {...rest}>{children}</Tag>;
};

window.Whink = { Icon, Tool, WhinkLogo, Reveal, useReveal };
