// packages/core/src/components/dialog/dialog-description.tsx
import type { JSX } from "solid-js";
import { createUniqueId, onCleanup, onMount, splitProps } from "solid-js";
import { useInternalDialogContext } from "./dialog-context";
import type { DialogDescriptionProps } from "./dialog.props";

export type { DialogDescriptionProps };

/** Renders as p and registers its ID for aria-describedby on Dialog.Content. */
export function DialogDescription(props: DialogDescriptionProps): JSX.Element {
  const [local, rest] = splitProps(props, ["children"]);
  const ctx = useInternalDialogContext();
  const id = createUniqueId();

  onMount(() => ctx.setDescriptionId(id));
  onCleanup(() => ctx.setDescriptionId(undefined));

  return (
    <p id={id} {...rest}>
      {local.children}
    </p>
  );
}
