import { onUnmounted as m } from "vue";
import { AsyncOpenResultError as f } from "../interface.mjs";
import { useCreateTableModal as w } from "./use-create-table-modal.mjs";
const a = (e) => e.id;
function b(e) {
  const { finishCallback: c, getRowKey: r, ...l } = e, { destroy: n, openModal: i, closeModal: p, ...u } = w({
    ...l,
    destroyOnUnmounted: !1,
    getRowKey: r || a
  }), y = async (t = [], d = {}) => {
    try {
      const o = await i(t, d) || {
        keys: [],
        rows: []
      };
      return c?.(o), o;
    } catch (o) {
      if (o === f.ModalCancel)
        return {
          keys: t?.map(r || a),
          rows: t
        };
      throw o;
    }
  }, s = () => {
    p();
  };
  return m(() => {
    s(), n();
  }), {
    open: y,
    destroy: n,
    close: s,
    ...u
  };
}
export {
  b as useTableSelectModal
};
