// packages/core/src/components/form/form-label.tsx
import type { JSX } from "solid-js";
import { splitProps } from "solid-js";
import { useFormFieldContext } from "./form-context";
import type { FormLabelProps } from "./form.props";

export type { FormLabelProps };

/**
 * Renders a <label> element linked to the field's control via htmlFor.
 */
export function FormLabel(props: FormLabelProps): JSX.Element {
  const [local, rest] = splitProps(props, ["children"]);
  const fieldCtx = useFormFieldContext();

  return (
    <label for={fieldCtx.controlId} {...rest}>
      {local.children}
    </label>
  );
}
