import Container from "@/components/Container/Container";
import Section from "@/components/Section/Section";
import Wsywig from "@/components/Wsywig/Wsywig";

const BulletTick = () => (
  <svg
    aria-hidden="true"
    viewBox="0 0 48 48"
    fill="none"
    className="flex-shrink-0 w-[32px] h-[32px] lg:w-[48px] lg:h-[48px]"
  >
    <circle cx="24" cy="24" r="23" stroke="white" strokeWidth="3" />
    <path
      d="M14 24.5L20.5 31L34 17.5"
      stroke="white"
      strokeWidth="3"
      strokeLinecap="round"
      strokeLinejoin="round"
    />
  </svg>
);

const UspCard = (props: { [rest: string]: any }) => {
  const bullets: string[] = [];

  for (let i = 0; i < props.bullets; i++) {
    const line = String(props[`bullets_${i}_line`] || "").trim();

    if (line) {
      bullets.push(line);
    }
  }

  if (!props.title && bullets.length < 1 && !props.body) return <></>;

  return (
    <Container id={props.anchor}>
      <Section gridArea="thin">
        <div className="rounded-xl bg-green p-xs lg:p-md flex flex-col gap-sm">
          {props.title && <h3 className="h1 text-white m-none">{props.title}</h3>}
          {(bullets.length > 0 || props.body) && (
            <div
              className={`grid grid-cols-1 gap-sm lg:gap-x-sm lg:items-center ${
                bullets.length > 0 && props.body ? "lg:grid-cols-2" : ""
              }`}
            >
              {bullets.length > 0 && (
                <ul className="list-none p-none m-none flex flex-col justify-center gap-xs lg:gap-sm">
                  {bullets.map((line, index) => (
                    <li key={index} className="flex xs:items-start lg:items-center gap-xs">
                      <BulletTick />
                      <span className="h3 m-none">{line}</span>
                    </li>
                  ))}
                </ul>
              )}
              {props.body && (
                <div className="[&_p]:h3 [&_p]:mb-sm [&_p:last-child]:mb-none">
                  <Wsywig content={props.body} />
                </div>
              )}
            </div>
          )}
        </div>
      </Section>
    </Container>
  );
};

export default UspCard;
