/* MeuLook — Reusable UI Components */

/* ---- LOGO ICON (SVG) ---- */
const MeuLookIcon = ({ size = 40 }) => (
  <svg width={size} height={size} viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
    <defs>
      <linearGradient id="logo-grad" x1="0" y1="0" x2="64" y2="64" gradientUnits="userSpaceOnUse">
        <stop offset="0%" stopColor="var(--pink, #FF2D78)" />
        <stop offset="100%" stopColor="var(--purple, #8B5CF6)" />
      </linearGradient>
      <linearGradient id="logo-shine" x1="10" y1="8" x2="54" y2="56" gradientUnits="userSpaceOnUse">
        <stop offset="0%" stopColor="#fff" stopOpacity="0.35" />
        <stop offset="100%" stopColor="#fff" stopOpacity="0" />
      </linearGradient>
    </defs>
    <rect x="2" y="2" width="60" height="60" rx="18" fill="url(#logo-grad)" />
    <rect x="2" y="2" width="60" height="60" rx="18" fill="url(#logo-shine)" />
    {/* Mirror/looking glass icon */}
    <ellipse cx="32" cy="26" rx="13" ry="13" fill="none" stroke="#fff" strokeWidth="3" strokeLinecap="round" />
    <ellipse cx="32" cy="26" rx="8" ry="8" fill="rgba(255,255,255,0.2)" />
    <line x1="41" y1="36" x2="48" y2="50" stroke="#fff" strokeWidth="3.5" strokeLinecap="round" />
    {/* Sparkle */}
    <circle cx="28" cy="22" r="2" fill="rgba(255,255,255,0.8)" />
    <circle cx="25" cy="19" r="1" fill="rgba(255,255,255,0.5)" />
  </svg>
);

const MeuLookLogo = ({ size = 40 }) => (
  <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
    <MeuLookIcon size={size} />
    <span className="logo-text">Meu<em>Look</em></span>
  </div>
);

/* ---- SPARKLE DECORATION ---- */
const Sparkle = ({ style, size = 16, color = 'var(--pink)' }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill={color} style={{ ...style, flexShrink: 0 }}>
    <path d="M12 0L14.59 8.41L23 12L14.59 15.59L12 24L9.41 15.59L1 12L9.41 8.41Z" />
  </svg>
);

/* ---- GRADIENT BUTTON ---- */
const GradientButton = ({ children, href, onClick, size = 'md', variant = 'primary', style: extraStyle, className = '' }) => {
  const isMobile = typeof window !== 'undefined' && window.innerWidth <= 480;
  const sizes = { sm: { padding: '12px 24px', fontSize: '.88rem' }, md: { padding: isMobile ? '14px 24px' : '16px 32px', fontSize: isMobile ? '.92rem' : '1rem' }, lg: { padding: isMobile ? '16px 24px' : '20px 40px', fontSize: isMobile ? '.95rem' : '1.1rem' } };
  const s = sizes[size] || sizes.md;
  const base = {
    display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 10,
    background: variant === 'primary' ? 'var(--gradient)' : 'transparent',
    color: variant === 'primary' ? '#fff' : 'var(--pink)',
    border: variant === 'outline' ? '2px solid var(--pink)' : 'none',
    fontFamily: 'var(--font-display)', fontWeight: 800, letterSpacing: '.02em',
    textTransform: 'uppercase', textDecoration: 'none', borderRadius: 'var(--radius-pill)',
    cursor: 'pointer', position: 'relative', overflow: 'hidden',
    transition: 'var(--transition)', boxShadow: variant === 'primary' ? 'var(--shadow-cta)' : 'none',
    ...s, ...extraStyle
  };
  const Tag = href ? 'a' : 'button';
  const props = href ? { href, target: href.startsWith('http') ? '_blank' : undefined, rel: href.startsWith('http') ? 'noopener' : undefined } : { onClick, type: 'button' };
  return <Tag {...props} className={`glow-btn ${className}`} style={base}>{children}</Tag>;
};

/* ---- PILL TAG ---- */
const PillTag = ({ children, icon, style: extra }) => (
  <div className="pill-tag" style={extra}>
    {icon && <span style={{ display: 'flex' }}>{icon}</span>}
    {children}
  </div>
);

/* ---- SECTION HEADER ---- */
const SectionHeader = ({ tag, tagIcon, title, subtitle, light = true, align = 'center' }) => (
  <div className="section-header reveal" style={{ textAlign: align }}>
    {tag && <PillTag icon={tagIcon}>{tag}</PillTag>}
    <h2 className="section-title" style={!light ? { color: '#fff' } : {}} dangerouslySetInnerHTML={{ __html: title }}></h2>
    {subtitle && <p className="section-sub" style={{ ...(align === 'center' ? { margin: '14px auto 0' } : { marginTop: 14 }), ...(!light ? { color: 'rgba(255,255,255,.6)' } : {}) }}>{subtitle}</p>}
  </div>
);

/* ---- FLOATING ORBS ---- */
const FloatingOrbs = ({ colors, count = 4 }) => {
  const orbs = React.useMemo(() => {
    return Array.from({ length: count }, (_, i) => ({
      color: colors[i % colors.length],
      size: 80 + Math.random() * 200,
      x: Math.random() * 100,
      y: Math.random() * 100,
      delay: Math.random() * 4,
      duration: 5 + Math.random() * 4
    }));
  }, [count]);
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden', pointerEvents: 'none' }}>
      {orbs.map((o, i) => (
        <div key={i} className="floating-orb" style={{
          position: 'absolute', width: o.size, height: o.size, borderRadius: '50%',
          background: `radial-gradient(circle, ${o.color}44, transparent 70%)`,
          left: `${o.x}%`, top: `${o.y}%`, filter: 'blur(40px)', opacity: 0.6,
          animation: `float ${o.duration}s ease-in-out ${o.delay}s infinite`
        }}></div>
      ))}
    </div>
  );
};

/* ---- SCROLL REVEAL HOOK ---- */
const useScrollReveal = () => {
  React.useEffect(() => {
    const els = document.querySelectorAll('.reveal');
    const io = new IntersectionObserver(entries => {
      entries.forEach(en => {
        if (en.isIntersecting) { en.target.classList.add('visible'); io.unobserve(en.target); }
      });
    }, { threshold: 0.1 });
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  }, []);
};

/* ---- DRAWN LINE REVEAL ---- */
const useDrawnLines = () => {
  React.useEffect(() => {
    const els = document.querySelectorAll('.drawn-line');
    const io = new IntersectionObserver(entries => {
      entries.forEach(en => {
        if (en.isIntersecting) { en.target.classList.add('visible'); io.unobserve(en.target); }
      });
    }, { threshold: 0.3 });
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  }, []);
};

/* ---- ICON COMPONENTS ---- */
const Icon = ({ name, size = 24, stroke = 'currentColor', fill = 'none', strokeWidth = 2 }) => {
  const icons = {
    zap: <><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></>,
    shield: <><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></>,
    palette: <><circle cx="13.5" cy="6.5" r=".5" fill={stroke}/><circle cx="17.5" cy="10.5" r=".5" fill={stroke}/><circle cx="8.5" cy="7.5" r=".5" fill={stroke}/><circle cx="6.5" cy="12.5" r=".5" fill={stroke}/><path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"/></>,
    lock: <><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></>,
    star: <><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></>,
    heart: <><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></>,
    check: <><polyline points="20 6 9 17 4 12"/></>,
    x: <><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></>,
    arrowDown: <><line x1="12" y1="5" x2="12" y2="19"/><polyline points="19 12 12 19 5 12"/></>,
    upload: <><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></>,
    camera: <><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></>,
    mail: <><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></>,
    instagram: <><rect x="2" y="2" width="20" height="20" rx="5" ry="5"/><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"/><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"/></>,
    shirt: <><path d="M20.38 3.46 16 2a4 4 0 0 1-8 0L3.62 3.46a2 2 0 0 0-1.34 2.23l.58 3.57a1 1 0 0 0 .99.84H6v10c0 1.1.9 2 2 2h8a2 2 0 0 0 2-2V10h2.15a1 1 0 0 0 .99-.84l.58-3.57a2 2 0 0 0-1.34-2.23z"/></>,
    scissors: <><circle cx="6" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><line x1="20" y1="4" x2="8.12" y2="15.88"/><line x1="14.47" y1="14.48" x2="20" y2="20"/><line x1="8.12" y1="8.12" x2="12" y2="12"/></>,
    gem: <><polyline points="6 3 18 3 22 9 12 22 2 9 6 3"/><line x1="22" y1="9" x2="2" y2="9"/><line x1="12" y1="22" x2="6" y2="3"/><line x1="12" y1="22" x2="18" y2="3"/></>,
    sun: <><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></>,
    chat: <><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></>,
    ban: <><circle cx="12" cy="12" r="10"/><line x1="4.93" y1="4.93" x2="19.07" y2="19.07"/></>,
    book: <><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/></>,
    download: <><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></>,
    image: <><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></>,
    sparkles: <><path d="M12 3l1.5 4.5L18 9l-4.5 1.5L12 15l-1.5-4.5L6 9l4.5-1.5L12 3z"/><path d="M5 18l.75 2.25L8 21l-2.25.75L5 24l-.75-2.25L2 21l2.25-.75L5 18z"/></>,
  };
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill={fill} stroke={stroke} strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round">{icons[name]}</svg>
  );
};

/* ---- TRUST ITEM ---- */
const TrustItem = ({ icon, children, light = false }) => (
  <div className="trust-item">
    <div className="trust-icon" style={light ? {} : { background: 'rgba(255,255,255,.12)', color: '#fff' }}>
      <Icon name={icon} size={16} strokeWidth={2.5} />
    </div>
    <span style={light ? {} : { color: 'rgba(255,255,255,.85)' }}>{children}</span>
  </div>
);

/* ---- FAQ ITEM ---- */
const FAQItem = ({ question, answer }) => {
  const [open, setOpen] = React.useState(false);
  return (
    <div className={`faq-item ${open ? 'open' : ''}`}>
      <button className="faq-q" onClick={() => setOpen(!open)}>
        {question}
        <div className="faq-icon"><span>+</span></div>
      </button>
      <div className="faq-a"><div className="faq-a-inner">{answer}</div></div>
    </div>
  );
};

/* ---- TESTIMONIAL CARD ---- */
const TestimonialCard = ({ name, location, quote, delay = 0 }) => (
  <div className={`test-card reveal d${delay}`}>
    <div className="test-stars">★★★★★</div>
    <blockquote>{quote}</blockquote>
    <div className="test-author">
      <div className="test-avatar">{name.charAt(0)}</div>
      <div>
        <div className="test-name">{name}</div>
        <div className="test-loc">{location}</div>
      </div>
    </div>
  </div>
);

/* ---- PALETTE DEMO BAR ---- */
const PaletteBar = () => {
  const colors = [
    { bg: '#FFB800', name: 'Dourado' }, { bg: '#FF6B6B', name: 'Coral' },
    { bg: '#FF2D78', name: 'Pink' }, { bg: '#8B5CF6', name: 'Lavanda' },
    { bg: '#06D6A0', name: 'Menta' }, { bg: '#3B82F6', name: 'Azul' },
    { bg: '#F97316', name: 'Pêssego' }, { bg: '#EC4899', name: 'Rosa' }
  ];
  return (
    <div className="palette-bar reveal">
      {colors.map((c, i) => (
        <div key={i} className="palette-swatch" style={{ background: c.bg }}>
          <span>{c.name}</span>
        </div>
      ))}
    </div>
  );
};

/* ---- SEASONS BAR ---- */
const SeasonsBar = () => (
  <div className="seasons-bar reveal">
    <div className="season spring"><span>Primavera</span></div>
    <div className="season summer"><span>Verão</span></div>
    <div className="season autumn"><span>Outono</span></div>
    <div className="season winter"><span>Inverno</span></div>
  </div>
);

/* Export all to window */
Object.assign(window, {
  MeuLookIcon, MeuLookLogo, Sparkle, GradientButton, PillTag, SectionHeader,
  FloatingOrbs, useScrollReveal, useDrawnLines, Icon, TrustItem, FAQItem,
  TestimonialCard, PaletteBar, SeasonsBar
});
