import { useState } from 'react';
import { useScrollReveal } from '@/hooks/useScrollReveal';

/**
 * Resources Section - Free Resources Download
 * Displays downloadable resources with email signup
 */

const resources = [
  'Checklist',
  'Roadmap',
  'AI Toolkit',
  'Business Canvas',
  'Prompt Library',
];

export const ResourcesSection = () => {
  const [email, setEmail] = useState('');
  const [submitted, setSubmitted] = useState(false);
  const panelRef = useScrollReveal();

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    setSubmitted(true);
    // Reset after 3 seconds
    setTimeout(() => {
      setEmail('');
      setSubmitted(false);
    }, 3000);
  };

  return (
    <section className="section bg-[var(--bg-deep)]" id="resources">
      <div className="container">
        <div
          ref={panelRef}
          className="reveal bg-[var(--panel)] border border-[var(--line)] rounded-[24px] p-14 grid grid-cols-1 lg:grid-cols-[1.1fr_1fr] gap-14 items-center"
        >
          {/* Left side - Resources list */}
          <div>
            <span className="eyebrow">Section 11 — Free Resources</span>
            <h2 className="heading">
              Tải miễn phí<br />
              Bộ tài liệu <span className="accent">Chuyển đổi số</span>
            </h2>

            {/* Resource list */}
            <div className="grid grid-cols-2 gap-3.5 mt-7">
              {resources.map((resource, idx) => (
                <div key={idx} className="flex items-center gap-2.5 text-sm text-[var(--text)]">
                  <span className="w-4.5 h-4.5 text-[var(--cyan)] flex-shrink-0">
                    <svg className="w-full h-full stroke-current fill-none stroke-1.8 stroke-linecap-round stroke-linejoin-round">
                      <use href="#i-check" />
                    </svg>
                  </span>
                  {resource}
                </div>
              ))}
            </div>
          </div>

          {/* Right side - Email form */}
          <div className="bg-[var(--bg-deep)] border border-[var(--line)] rounded-[16px] p-8">
            <form onSubmit={handleSubmit}>
              {/* Label */}
              <label
                htmlFor="resEmail"
                className="font-mono text-xs text-[var(--muted)] tracking-widest uppercase block mb-2.5"
              >
                Email nhận tài liệu
              </label>

              {/* Input row */}
              <div className="flex gap-2.5 flex-wrap">
                <input
                  type="email"
                  id="resEmail"
                  placeholder="ban@congty.com"
                  value={email}
                  onChange={(e) => setEmail(e.target.value)}
                  required
                  className="flex-1 min-w-[180px] bg-[var(--panel)] border border-[var(--line)] rounded-[10px] px-4 py-3.5 text-[var(--text)] font-body text-sm focus:outline-none focus:border-[var(--cyan)]"
                />
                <button
                  type="submit"
                  className="inline-flex items-center gap-2 px-5.5 py-3.5 bg-[var(--cyan)] text-[var(--bg-deep)] rounded-[10px] font-semibold text-sm transition-all duration-200 hover:translate-y-[-2px] hover:shadow-lg"
                >
                  Download
                  <svg className="w-4 h-4 stroke-current fill-none stroke-1.8">
                    <use href="#i-download" />
                  </svg>
                </button>
              </div>

              {/* Form note */}
              <p className="text-xs text-[var(--muted-2)] mt-3">
                Chúng tôi sẽ gửi bộ tài liệu qua email trong vòng vài phút. Không spam.
              </p>

              {/* Success message */}
              {submitted && (
                <p className="text-sm text-[var(--cyan)] mt-3.5 font-mono">
                  Đã gửi! Kiểm tra hộp thư của bạn để tải bộ tài liệu.
                </p>
              )}
            </form>
          </div>
        </div>
      </div>
    </section>
  );
};
