import { Fragment } from "react";

/**
 * Splits text into masked words for the "words" reveal.
 * Real spaces are kept between words so the text reads naturally for
 * assistive technology and search engines.
 */
export default function SplitWords({ text }: { text: string }) {
  const words = text.split(/\s+/).filter(Boolean);
  return (
    <>
      {words.map((w, i) => (
        <Fragment key={`${w}-${i}`}>
          <span className="split-word">
            <span>{w}</span>
          </span>
          {i < words.length - 1 ? " " : null}
        </Fragment>
      ))}
    </>
  );
}
