'use strict';

var BCALMBPZ = require('./BCALMBPZ.cjs');
var PBFD2E7P = require('./PBFD2E7P.cjs');
var _3YLGPPWQ = require('./3YLGPPWQ.cjs');

// src/disclosure/disclosure-store.ts
function createDisclosureStore(props = {}) {
  const store = BCALMBPZ.mergeStore(
    props.store,
    BCALMBPZ.omit(props.disclosure, ["contentElement", "disclosureElement"])
  );
  BCALMBPZ.throwOnConflictingProps(props, store);
  const syncState = store == null ? void 0 : store.getState();
  const open = PBFD2E7P.defaultValue(
    props.open,
    syncState == null ? void 0 : syncState.open,
    props.defaultOpen,
    false
  );
  const animated = PBFD2E7P.defaultValue(props.animated, syncState == null ? void 0 : syncState.animated, false);
  const initialState = {
    open,
    animated,
    animating: !!animated && open,
    mounted: open,
    contentElement: PBFD2E7P.defaultValue(syncState == null ? void 0 : syncState.contentElement, null),
    disclosureElement: PBFD2E7P.defaultValue(syncState == null ? void 0 : syncState.disclosureElement, null)
  };
  const disclosure = BCALMBPZ.createStore(initialState, store);
  BCALMBPZ.setup(
    disclosure,
    () => BCALMBPZ.sync(disclosure, ["animated", "animating"], (state) => {
      if (state.animated) return;
      disclosure.setState("animating", false);
    })
  );
  BCALMBPZ.setup(
    disclosure,
    () => BCALMBPZ.subscribe(disclosure, ["open"], () => {
      if (!disclosure.getState().animated) return;
      disclosure.setState("animating", true);
    })
  );
  BCALMBPZ.setup(
    disclosure,
    () => BCALMBPZ.sync(disclosure, ["open", "animating"], (state) => {
      disclosure.setState("mounted", state.open || state.animating);
    })
  );
  return _3YLGPPWQ.__spreadProps(_3YLGPPWQ.__spreadValues({}, disclosure), {
    disclosure: props.disclosure,
    setOpen: (value) => disclosure.setState("open", value),
    show: () => disclosure.setState("open", true),
    hide: () => disclosure.setState("open", false),
    toggle: () => disclosure.setState("open", (open2) => !open2),
    stopAnimation: () => disclosure.setState("animating", false),
    setContentElement: (value) => disclosure.setState("contentElement", value),
    setDisclosureElement: (value) => disclosure.setState("disclosureElement", value)
  });
}

exports.createDisclosureStore = createDisclosureStore;
//# sourceMappingURL=RCQ5P4YE.cjs.map
