"use client";

import Image from "next/image";
import { type FormEvent, useState } from "react";
import { useWaitlist } from "@/components/waitlist/WaitlistProvider";

const SignupForm = () => {
  const { openWaitlist } = useWaitlist();
  const [email, setEmail] = useState("");

  const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
    event.preventDefault();
    openWaitlist(email.trim() || undefined);
  };

  return (
    <div>
      <form
        onSubmit={handleSubmit}
        className="flex flex-col gap-3 sm:flex-row sm:items-stretch sm:gap-4"
      >
        <label className="sr-only" htmlFor="hero-email">
          Email address
        </label>
        <input
          id="hero-email"
          type="email"
          value={email}
          onChange={(event) => setEmail(event.target.value)}
          placeholder="Enter your email"
          className="w-full min-w-0 flex-1 rounded-lg border-2 border-brand bg-white px-4 py-3 text-base text-ink outline-none transition-shadow focus:shadow-[0_0_0_3px_rgba(108,92,231,0.2)]"
        />
        <button
          className="shrink-0 rounded-lg bg-brand px-5 py-3 text-base font-semibold text-white transition-colors duration-300 hover:bg-brand-strong sm:px-6 sm:text-lg"
          type="submit"
        >
          Start for free
        </button>
      </form>

      <ul className="mt-3 flex flex-col items-center gap-2 text-sm text-ink/70 sm:mt-2 sm:flex-row sm:flex-wrap sm:justify-center sm:gap-x-6 sm:gap-y-1 lg:justify-start">
        <li className="flex items-center gap-2">
          <Image
            src="/homepage/check.svg"
            alt=""
            width={14}
            height={14}
            aria-hidden="true"
          />
          Free 14-day trial
        </li>
        <li className="flex items-center gap-2">
          <Image
            src="/homepage/check.svg"
            alt=""
            width={14}
            height={14}
            aria-hidden="true"
          />
          No credit card required
        </li>
      </ul>
    </div>
  );
};

export default SignupForm;
