const { useState, useEffect } = React;

function Footer({ onCotizarClick }) {
  const [isMobile, setIsMobile] = useState(window.innerWidth <= 768);

  useEffect(() => {
    const handleResize = () => setIsMobile(window.innerWidth <= 768);
    window.addEventListener('resize', handleResize);
    return () => window.removeEventListener('resize', handleResize);
  }, []);

  const linkBtn = (item) => {
    const { label, href, download } = typeof item === 'string' ? { label: item } : item;
    const style = {
      background: 'none', border: 'none', padding: '0 0 10px',
      cursor: 'pointer', fontFamily: "'Figtree', sans-serif",
      fontSize: '14px', color: 'rgba(245,240,230,0.5)',
      display: 'block', textAlign: isMobile ? 'center' : 'left', letterSpacing: '0.01em',
      transition: 'color 0.2s',
      margin: isMobile ? '0 auto' : '0', textDecoration: 'none',
    };
    const handlers = {
      onMouseEnter: (e) => e.currentTarget.style.color = '#F5F0E6',
      onMouseLeave: (e) => e.currentTarget.style.color = 'rgba(245,240,230,0.5)',
    };
    return href
      ? <a key={label} href={href} download={download} style={style} {...handlers}>{label}</a>
      : <button key={label} style={style} {...handlers}>{label}</button>;
  };

  return (
    <footer id="contact" style={{
      position: 'relative', overflow: 'hidden'
    }}>
      {/* Bg */}
      <div style={{
        position: 'absolute', inset: 0,
        backgroundImage: 'url(images/disena-espacio.png)',
        backgroundSize: 'cover', backgroundPosition: 'center',
        opacity: 0.04
      }} />
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(180deg, #0B0B0F 0%, #080604 100%)'
      }} />

      {/* Luz ambiental cálida (cerca de la banda CTA) */}
      <div style={{
        position: 'absolute', top: '-80px', left: '50%',
        transform: 'translateX(-50%)',
        width: '820px', height: '460px', borderRadius: '50%',
        background: 'radial-gradient(ellipse, rgba(224,180,74,0.18) 0%, rgba(212,175,55,0.07) 40%, transparent 72%)',
        pointerEvents: 'none', zIndex: 0,
      }} />

      {/* CTA Band */}
      <div style={{
        position: 'relative', zIndex: 1,
        borderTop: '1px solid rgba(255,255,255,0.06)',
        borderBottom: '1px solid rgba(255,255,255,0.06)',
        padding: isMobile ? '40px 4%' : '56px 5.5%'
      }}>
        <div style={{
          maxWidth: '1280px', margin: '0 auto',
          display: 'flex', 
          flexDirection: isMobile ? 'column' : 'row',
          alignItems: 'center', 
          justifyContent: 'space-between',
          gap: isMobile ? '28px' : '40px',
          background: 'linear-gradient(135deg, rgba(255,255,255,0.07) 0%, rgba(255,255,255,0.02) 100%)',
          backdropFilter: 'blur(24px)',
          border: '1px solid rgba(255,255,255,0.1)',
          borderRadius: '28px',
          padding: isMobile ? '32px 24px' : '44px 52px',
          boxShadow: '0 8px 40px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.07)',
          textAlign: isMobile ? 'center' : 'left'
        }}>
          <div>
            <p style={{
              fontFamily: "'Figtree', sans-serif",
              fontSize: '11px', letterSpacing: '0.22em',
              textTransform: 'uppercase', color: '#D4AF37',
              marginBottom: '12px'
            }}>¿Tenés un proyecto?</p>
            <h3 style={{
              fontFamily: "'Figtree', sans-serif",
              fontSize: isMobile ? '24px' : 'clamp(26px, 3vw, 44px)',
              fontWeight: 600, color: '#F5F0E6',
              letterSpacing: '-0.02em', lineHeight: 1.2
            }}>Convertí tu espacio<br />en algo extraordinario</h3>
          </div>
          <button onClick={onCotizarClick} style={{
            flexShrink: 0,
            background: '#D4AF37', color: '#0B0B0F',
            border: 'none', borderRadius: '50px',
            padding: isMobile ? '14px 32px' : '16px 40px', 
            cursor: 'pointer',
            fontFamily: "'Figtree', sans-serif",
            fontSize: '15px', fontWeight: 600,
            letterSpacing: '0.02em',
            boxShadow: '0 8px 28px rgba(212,175,55,0.3)',
            transition: 'background 0.2s, transform 0.2s, box-shadow 0.2s',
            width: isMobile ? '100%' : 'auto'
          }}
          onMouseEnter={(e) => {
            e.currentTarget.style.background = '#e8c44a';
            e.currentTarget.style.transform = 'translateY(-2px)';
            e.currentTarget.style.boxShadow = '0 14px 36px rgba(212,175,55,0.4)';
          }}
          onMouseLeave={(e) => {
            e.currentTarget.style.background = '#D4AF37';
            e.currentTarget.style.transform = 'translateY(0)';
            e.currentTarget.style.boxShadow = '0 8px 28px rgba(212,175,55,0.3)';
          }}>
            Cotizar ahora →</button>
        </div>
      </div>

      {/* Main grid */}
      <div style={{
        position: 'relative', zIndex: 1,
        padding: isMobile ? '48px 4% 36px' : '72px 5.5% 48px',
        maxWidth: '1280px', margin: '0 auto',
        display: 'grid',
        gridTemplateColumns: isMobile ? '1fr' : '2fr 1fr 1fr 1fr',
        gap: isMobile ? '36px' : '48px',
        textAlign: isMobile ? 'center' : 'left'
      }}>
        {/* Brand */}
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: isMobile ? 'center' : 'flex-start' }}>
          <div style={{
            fontFamily: "'Figtree', sans-serif",
            fontSize: '22px',
            letterSpacing: '0.12em',
            marginBottom: '18px', color: "rgba(235, 233, 227, 0.87)", fontWeight: "400"
          }}>HOMECONNECT</div>
          <p style={{
            fontFamily: "'Figtree', sans-serif",
            fontSize: '14px', lineHeight: 1.75,
            color: 'rgba(245,240,230,0.4)', maxWidth: '270px',
            marginBottom: '28px'
          }}>
            Proveedor integral para tu obra: marmolería, iluminación, herrajes
            y muebles a medida, directo de fábrica y sin intermediarios.
          </p>
          {/* Socials */}
          <div style={{ display: 'flex', gap: '10px', justifyContent: 'center' }}>
            {[
              { label: 'WA', title: 'WhatsApp', href: `https://wa.me/${window.WA_NUMBER || '5491125062187'}`, svg: <svg width="18" height="18" viewBox="0 0 448 512" fill="currentColor"><path d="M380.9 97.1C339 55.1 283.2 32 223.9 32c-122.4 0-222 99.6-222 222 0 39.1 10.2 77.3 29.6 111L0 480l117.7-30.9c32.4 17.7 68.9 27 106.1 27h.1c122.3 0 224.1-99.6 224.1-222 0-59.3-25.2-115-67.1-157.1zm-157 341.6c-33.2 0-65.7-8.9-94-25.7l-6.7-4-69.8 18.3L72 359.2l-4.4-7c-18.5-29.4-28.2-63.3-28.2-98.2 0-101.7 82.8-184.5 184.6-184.5 49.3 0 95.6 19.2 130.4 54.1 34.8 34.9 56.2 81.2 56.1 130.5 0 101.8-84.9 184.6-186.6 184.6zm101.2-138.2c-5.5-2.8-32.8-16.2-37.9-18-5.1-1.9-8.8-2.8-12.5 2.8-3.7 5.6-14.3 18-17.6 21.8-3.2 3.7-6.5 4.2-12 1.4-32.6-16.3-54-29.1-75.5-66-5.7-9.8 5.7-9.1 16.3-30.3 1.8-3.7.9-6.9-.5-9.7-1.4-2.8-12.5-30.1-17.1-41.2-4.5-10.8-9.1-9.3-12.5-9.5-3.2-.2-6.9-.2-10.6-.2-3.7 0-9.7 1.4-14.8 6.9-5.1 5.6-19.4 19-19.4 46.3 0 27.3 19.9 53.7 22.6 57.4 2.8 3.7 39.1 59.7 94.8 83.8 35.2 15.2 49 16.5 66.6 13.9 10.7-1.6 32.8-13.4 37.4-26.4 4.6-13 4.6-24.1 3.2-26.4-1.3-2.5-5-3.9-10.5-6.6z"/></svg> }
            ].map((s) =>
              <a key={s.label} href={s.href || '#'} target="_blank" rel="noopener noreferrer" title={s.title} style={{
                width: '38px', height: '38px', borderRadius: '50%',
                background: 'rgba(255,255,255,0.05)',
                border: '1px solid rgba(255,255,255,0.1)',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                textDecoration: 'none',
                color: 'rgba(245,240,230,0.45)',
                transition: 'border-color 0.2s, color 0.2s, transform 0.2s'
              }}
              onMouseEnter={(e) => {
                e.currentTarget.style.borderColor = '#D4AF37';
                e.currentTarget.style.color = '#D4AF37';
                e.currentTarget.style.transform = 'translateY(-2px)';
              }}
              onMouseLeave={(e) => {
                e.currentTarget.style.borderColor = 'rgba(255,255,255,0.1)';
                e.currentTarget.style.color = 'rgba(245,240,230,0.45)';
                e.currentTarget.style.transform = 'translateY(0)';
              }}>
                {s.svg}</a>
            )}
          </div>
        </div>

        {/* Servicios */}
        <div>
          <h4 style={{
            fontFamily: "'Figtree', sans-serif",
            fontSize: '10px', fontWeight: 700,
            letterSpacing: '0.18em', textTransform: 'uppercase',
            color: 'rgba(245,240,230,0.3)', marginBottom: '20px'
          }}>Servicios</h4>
          {['Marmolería', 'Muebles a medida', 'Herrajes', 'Iluminación'].map(linkBtn)}
        </div>

        {/* Empresa */}
        <div>
          <h4 style={{
            fontFamily: "'Figtree', sans-serif",
            fontSize: '10px', fontWeight: 700,
            letterSpacing: '0.18em', textTransform: 'uppercase',
            color: 'rgba(245,240,230,0.3)', marginBottom: '20px'
          }}>Empresa</h4>
          {[
            'Inicio',
            { label: 'Sobre Nosotros', href: 'documentos/Home_Connect_Acerca_de_Nosotros_Ampliado.pdf', download: true },
            'Proyectos',
            'Contacto',
          ].map(linkBtn)}
        </div>

        {/* Contacto */}
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: isMobile ? 'center' : 'flex-start' }}>
          <h4 style={{
            fontFamily: "'Figtree', sans-serif",
            fontSize: '10px', fontWeight: 700,
            letterSpacing: '0.18em', textTransform: 'uppercase',
            color: 'rgba(245,240,230,0.3)', marginBottom: '20px'
          }}>Contacto</h4>
          {[
            { label: 'Teléfono', value: '+54 9 11 2506-2187' },
            { label: 'Email', value: 'connecthomec@gmail.com' },
            { label: 'Dirección', value: 'Buenos Aires, Argentina' },
            { label: 'Horario', value: 'Lun–Vie 9:00–18:00' }
          ].map((item) =>
            <div key={item.label} style={{ marginBottom: '14px', textAlign: isMobile ? 'center' : 'left' }}>
              <p style={{
                fontFamily: "'Figtree', sans-serif",
                fontSize: '10px', letterSpacing: '0.12em',
                textTransform: 'uppercase',
                color: 'rgba(245,240,230,0.22)', marginBottom: '3px'
              }}>{item.label}</p>
              <p style={{
                fontFamily: "'Figtree', sans-serif",
                fontSize: '13px', color: 'rgba(245,240,230,0.55)'
              }}>{item.value}</p>
            </div>
          )}
        </div>
      </div>

      {/* Bottom */}
      <div style={{
        position: 'relative', zIndex: 1,
        borderTop: '1px solid rgba(255,255,255,0.05)',
        padding: '24px 5.5%',
        maxWidth: '1280px', margin: '0 auto',
        display: 'flex', 
        flexDirection: isMobile ? 'column' : 'row',
        alignItems: 'center', 
        justifyContent: 'space-between',
        gap: isMobile ? '14px' : '0',
        textAlign: 'center'
      }}>
        <p style={{
          fontFamily: "'Figtree', sans-serif",
          fontSize: '12px', color: 'rgba(245,240,230,0.18)'
        }}>© 2025 Homeconnect. Todos los derechos reservados.</p>

        <div style={{ display: 'flex', flexWrap: 'wrap', gap: isMobile ? '12px' : '20px', alignItems: 'center', justifyContent: 'center' }}>
          {[
            { label: 'Términos y Condiciones', href: 'terminos-y-condiciones.html' },
            { label: 'Política de Privacidad', href: 'politica-privacidad.html' },
            { label: 'Condiciones del Servicio', href: 'condiciones-servicio.html' },
            { label: 'Eliminación de Datos de Usuario', href: 'eliminacion-datos.html' },
          ].map(l => (
            <a key={l.href} href={l.href} style={{
              fontFamily: "'Figtree', sans-serif",
              fontSize: '11px', letterSpacing: '0.04em',
              color: 'rgba(245,240,230,0.3)', textDecoration: 'none',
              transition: 'color 0.2s',
            }}
            onMouseEnter={(e) => e.currentTarget.style.color = '#D4AF37'}
            onMouseLeave={(e) => e.currentTarget.style.color = 'rgba(245,240,230,0.3)'}>
              {l.label}
            </a>
          ))}
        </div>

        <div style={{ display: 'flex', gap: '8px', alignItems: 'center', justifyContent: 'center' }}>
          <div style={{ width: '40px', height: '1px', background: 'linear-gradient(to right, transparent, rgba(212,175,55,0.4))' }} />
          <p style={{
            fontFamily: "'Figtree', sans-serif",
            fontSize: '11px', letterSpacing: '0.14em',
            textTransform: 'uppercase', color: 'rgba(245,240,230,0.18)'
          }}>Diseño · Calidad · Tradición</p>
        </div>
      </div>
    </footer>);

}

Object.assign(window, { Footer });