import { Fragment } from "react";
import Button from "@/components/ui/Button";
import TextAnimation from "@/components/ui/TextAnimation";
import ScrollReveal from "@/components/ui/ScrollReveal";

type FeatureItem = {
  label: string;
  title: string;
  bullets: string[];
  primaryButton: { text: string; href: string };
  secondaryButton: { text: string; href: string };
};

interface FeaturesLabeledListProps {
  tag: string;
  title: string;
  description: string;
  primaryButton?: { text: string; href: string };
  secondaryButton?: { text: string; href: string };
  items: FeatureItem[];
}

const FeaturesLabeledList = ({
  tag,
  title,
  description,
  primaryButton,
  secondaryButton,
  items,
}: FeaturesLabeledListProps) => {
  return (
    <section aria-label="Features section" className="py-20">
      <div className="flex flex-col gap-8">
        <div className="flex flex-col items-center w-content-width mx-auto gap-2">
          <span className="px-3 py-1 mb-1 text-sm card rounded">{tag}</span>

          <TextAnimation
            text={title}
            variant="fade"
            gradientText={true}
            tag="h2"
            className="text-6xl font-medium text-center text-balance"
          />

          <TextAnimation
            text={description}
            variant="fade"
            gradientText={false}
            tag="p"
            className="md:max-w-6/10 text-lg leading-tight text-center"
          />

          {(primaryButton || secondaryButton) && (
            <div className="flex flex-wrap justify-center gap-3 mt-3">
              {primaryButton && <Button text={primaryButton.text} href={primaryButton.href} variant="primary"/>}
              {secondaryButton && <Button text={secondaryButton.text} href={secondaryButton.href} variant="secondary"animationDelay={0.1} />}
            </div>
          )}
        </div>

        <div className="flex flex-col gap-5 w-content-width mx-auto">
          {items.map((item) => (
            <ScrollReveal
              variant="slide-up"
              key={item.label}
              className="flex flex-col md:flex-row gap-5 md:gap-12 p-5 md:p-12 card rounded"
            >
              <div className="w-full md:w-1/2 flex md:justify-start">
                <h3 className="text-7xl font-medium leading-tight truncate">{item.label}</h3>
              </div>

              <div className="w-full h-px bg-foreground/20 md:hidden" />

              <div className="flex flex-col w-full md:w-1/2 gap-5">
                <h4 className="text-2xl md:text-3xl font-medium leading-tight">{item.title}</h4>

                <div className="flex flex-wrap items-center gap-1">
                  {item.bullets.map((text, index) => (
                    <Fragment key={index}>
                      <span className="text-base">{text}</span>
                      {index < item.bullets.length - 1 && <span className="text-base text-accent">•</span>}
                    </Fragment>
                  ))}
                </div>

                <div className="flex flex-wrap gap-3 mt-2">
                  <Button text={item.primaryButton.text} href={item.primaryButton.href} variant="primary" />
                  <Button text={item.secondaryButton.text} href={item.secondaryButton.href} variant="secondary" />
                </div>
              </div>
            </ScrollReveal>
          ))}
        </div>
      </div>
    </section>
  );
};

export default FeaturesLabeledList;
