import { dynamic } from "@solidjs/web";
import { createSignal, omit } from "solid-js";
import { FieldsetContext } from "../../internals/fieldset-context.jsx";
import { mergeRootProps } from "../../internals/merge-root-props.jsx";
import { resolveClassStyle } from "../../internals/resolve-class-style.jsx";
/**
 * Groups a shared legend with related controls.
 * Renders a `<fieldset>` element (or `as` override).
 *
 * Documentation: [Base UI Fieldset](https://base-ui.com/react/components/fieldset)
 */
export function FieldsetRoot(props) {
  const disabled = () => props.disabled ?? false;

  // Internal legend-id registration: `<Fieldset.Legend>` writes its
  // generated id here during setup (owned scope) and clears it on cleanup.
  // `ownedWrite` opts out of Solid 2's write-in-owned-scope check — this is
  // pure internal plumbing, never surfaced to consumers.
  const [legendId, setLegendId] = createSignal(undefined, {
    ownedWrite: true,
    name: "fieldset.legendId"
  });
  const contextValue = {
    disabled,
    legendId,
    setLegendId,
    present: true
  };
  const userStyling = resolveClassStyle(props, () => ({
    disabled: disabled()
  }));
  const userHtmlProps = omit(props, "class", "style", "attrs", "as", "disabled", "children");
  const internalProps = {
    get disabled() {
      // Emit the native `disabled` attribute so the browser actually
      // disables form controls inside the fieldset.
      return disabled();
    },
    get "data-disabled"() {
      return disabled() ? "" : undefined;
    },
    get "aria-labelledby"() {
      // Empty string keeps the key present in ownKeys from first render
      // so a late-mounting legend can write into `legendId` and have
      // the binding update. Matches progress/meter-root pattern.
      return legendId() ?? "";
    }
  };
  const styledUserProps = mergeRootProps(userStyling, userHtmlProps);
  const merged = mergeRootProps(internalProps, styledUserProps);
  const Tag = dynamic(() => props.as ?? "fieldset");
  return <Tag {...merged}>
			<FieldsetContext value={contextValue}>{props.children}</FieldsetContext>
		</Tag>;
}
//# sourceMappingURL=fieldset-root.jsx.map
