import { dynamic } from "@solidjs/web";
import { createMemo, omit, Show } from "solid-js";
import { composeRefs, userRef } from "../../internals/compose-refs.jsx";
import { mergeRootProps } from "../../internals/merge-root-props.jsx";
import { resolveClassStyle } from "../../internals/resolve-class-style.jsx";
import { useComboboxRootContext } from "../root/combobox-root-context.jsx";
const EMPTY_STATE = {};

/**
 * Renders its children only when the items list is empty. Announces
 * changes politely via `role="status"`.
 */
export function ComboboxEmpty(props) {
  const root = useComboboxRootContext();

  // Items-mode counts the filtered items; static-children mode (no `items`
  // prop) counts the registered children currently matching the query.
  const empty = createMemo(() => root.items() !== undefined ? root.flatFilteredItems().length === 0 : root.visibleItemCount() === 0);
  const internal = {
    role: "status",
    "aria-live": "polite",
    "aria-atomic": true,
    get children() {
      return <Show when={empty()}>{props.children}</Show>;
    }
  };
  const userClassStyle = resolveClassStyle(props, () => EMPTY_STATE);
  // Strip children explicitly so user's children getter doesn't shadow ours.
  const userProps = omit(props, "as", "class", "style", "attrs", "children");
  let merged = mergeRootProps(internal, userClassStyle);
  merged = mergeRootProps(merged, userProps);
  const setEmptyRef = el => {
    root.emptyRef.current = el;
  };
  const Tag = dynamic(() => props.as ?? "div");
  return <Tag {...merged} ref={composeRefs(setEmptyRef, userRef(props))} />;
}
//# sourceMappingURL=combobox-empty.jsx.map
