import l from "react";
const t = (a, f) => {
  if (!l.isValidElement(a))
    return null;
  const { id: d, defaultId: r, isOpen: s, isDisabled: o, onTriggerClick: n, onEscape: p } = f, i = a.props;
  return l.cloneElement(a, {
    // Preserve existing id; fall back to provided id prop, then the component-level default
    id: i.id ?? d ?? r,
    "aria-expanded": s,
    "aria-haspopup": "dialog",
    "aria-disabled": o,
    // Mirrors the div[role="button"] wrapper: disabled removes from tab order, enabled is reachable
    tabIndex: o ? -1 : 0,
    onClick: (e) => {
      typeof i.onClick == "function" && i.onClick(e), !e.defaultPrevented && !o && n();
    },
    onKeyDown: (e) => {
      typeof i.onKeyDown == "function" && i.onKeyDown(e), e.defaultPrevented || (e.key === "Escape" ? p() : (e.key === "Enter" || e.key === " ") && (e.key === " " && e.preventDefault(), o || n()));
    }
  });
};
export {
  t as default
};
//# sourceMappingURL=cloneTriggerElement.js.map
