var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellSalesManagement/index.tsx
var pisellSalesManagement_exports = {};
__export(pisellSalesManagement_exports, {
  default: () => pisellSalesManagement_default
});
module.exports = __toCommonJS(pisellSalesManagement_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_date_picker = require("@pisell/date-picker");
var import_AdapterDayjs = require("@pisell/date-picker/es/AdapterDayjs");
var import_utils2 = require("../../utils");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_pisellSalesGrid = __toESM(require("../pisellSalesGrid"));
var import_usePerspectives = __toESM(require("./hooks/usePerspectives"));
var import_useSalesGridData = require("./hooks/useSalesGridData");
var import_locales = __toESM(require("./locales"));
var import_serve = require("./serve");
var PisellSalesManagement = (props) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
  const { perspective, __id } = props;
  const context = (0, import_useEngineContext.default)();
  const utils = ((_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) || {};
  const { action } = utils;
  import_utils2.request.setRequest(utils == null ? void 0 : utils.request);
  const _getRelationTables = (0, import_ahooks.useRequest)(import_serve.getRelationTables);
  const isActive = Boolean((_c = (_b = context == null ? void 0 : context.engine) == null ? void 0 : _b.props) == null ? void 0 : _c.isActive);
  const enableScanner = isActive;
  import_utils.locales.init(import_locales.default, ((_e = (_d = context == null ? void 0 : context.engine) == null ? void 0 : _d.props) == null ? void 0 : _e.locale) || "en");
  (0, import_react.useEffect)(() => {
    if (perspective === "monitor") {
      setTimeout(() => {
        action == null ? void 0 : action({
          type: "pisell1.registerBookingPlugin"
        });
      }, 300);
    }
  }, [perspective, action]);
  const useParams = (_g = (_f = window == null ? void 0 : window.app) == null ? void 0 : _f.history) == null ? void 0 : _g.useParams;
  const params = useParams == null ? void 0 : useParams();
  const queryBusinessCode = (0, import_react.useMemo)(() => {
    if (typeof window === "undefined") return void 0;
    const searchParams = new URLSearchParams(window.location.search || "");
    return searchParams.get("business_code") || void 0;
  }, []);
  const extParams = (0, import_react.useMemo)(() => {
    return {
      list: {
        business_code: props.biz || (params == null ? void 0 : params.biz) || queryBusinessCode
      }
    };
  }, [props.biz, params == null ? void 0 : params.biz, queryBusinessCode]);
  const perspectives = (0, import_usePerspectives.default)({
    relationTables: Array.isArray(_getRelationTables.data) ? _getRelationTables.data : []
  });
  const gridDataProps = (0, import_useSalesGridData.useSalesGridData)({
    perspective,
    extParams
  });
  const adapterLocale = ((_i = (_h = context == null ? void 0 : context.engine) == null ? void 0 : _h.props) == null ? void 0 : _i.locale) === "zh-CN" || ((_k = (_j = context == null ? void 0 : context.engine) == null ? void 0 : _j.props) == null ? void 0 : _k.locale) === "zh-HK" ? "zh-cn" : ((_m = (_l = context == null ? void 0 : context.engine) == null ? void 0 : _l.props) == null ? void 0 : _m.locale) === "en" || ((_o = (_n = context == null ? void 0 : context.engine) == null ? void 0 : _n.props) == null ? void 0 : _o.locale) === "en-US" ? "en" : "zh-cn";
  const rawLocale = ((_q = (_p = context == null ? void 0 : context.engine) == null ? void 0 : _p.props) == null ? void 0 : _q.locale) || (typeof localStorage !== "undefined" ? localStorage.getItem("umi_locale") : null) || "en-US";
  const materialsLocale = rawLocale === "zh" ? "zh-CN" : rawLocale;
  return /* @__PURE__ */ import_react.default.createElement(import_materials.PisellConfigProvider, { locale: materialsLocale }, /* @__PURE__ */ import_react.default.createElement(
    import_date_picker.LocalizationProvider,
    {
      dateAdapter: import_AdapterDayjs.AdapterDayjs,
      adapterLocale
    },
    /* @__PURE__ */ import_react.default.createElement("div", { style: Object.assign({}, { height: 0 }, props == null ? void 0 : props.style) }, /* @__PURE__ */ import_react.default.createElement(
      import_pisellSalesGrid.default,
      {
        perspectives,
        currentPerspective: perspective,
        extParams,
        __id,
        data: gridDataProps.data,
        loading: gridDataProps.loading,
        total: gridDataProps.total,
        pagination: gridDataProps.pagination,
        onPageChange: gridDataProps.onPageChange,
        searchParams: gridDataProps.searchParams,
        onSearch: gridDataProps.onSearch,
        onReset: gridDataProps.onReset,
        selectedKeys: gridDataProps.selectedKeys,
        selectedRows: gridDataProps.selectedRows,
        onSelectionChange: gridDataProps.onSelectionChange,
        rowKey: gridDataProps.rowKey,
        onRefresh: gridDataProps.onRefresh,
        refreshAsync: gridDataProps.refreshAsync,
        enableScanner
      }
    ))
  ));
};
var pisellSalesManagement_default = PisellSalesManagement;
