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, _r;
  const { perspective, __id, keyword, mode, hideToolbarSearch, onOpenDetail } = props;
  const context = (0, import_useEngineContext.default)();
  const utils = ((_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) || {};
  const { action } = utils;
  const app = (_b = utils == null ? void 0 : utils.getApp) == null ? void 0 : _b.call(utils);
  import_utils2.request.setRequest(utils == null ? void 0 : utils.request);
  const _getRelationTables = (0, import_ahooks.useRequest)(import_serve.getRelationTables);
  const isActive = Boolean((_d = (_c = context == null ? void 0 : context.engine) == null ? void 0 : _c.props) == null ? void 0 : _d.isActive);
  const enableScanner = isActive;
  import_utils.locales.init(import_locales.default, ((_f = (_e = context == null ? void 0 : context.engine) == null ? void 0 : _e.props) == null ? void 0 : _f.locale) || "en");
  (0, import_react.useEffect)(() => {
    if (perspective === "monitor") {
      setTimeout(() => {
        action == null ? void 0 : action({
          type: "pisell1.registerBookingPlugin"
        });
      }, 300);
    }
  }, [perspective, action]);
  const params = (_h = (_g = app == null ? void 0 : app.history) == null ? void 0 : _g.useParams) == null ? void 0 : _h.call(_g);
  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 resolvedBusinessCode = (0, import_react.useMemo)(() => {
    const raw = props.businessCode ?? props.biz ?? (params == null ? void 0 : params.business_code) ?? (params == null ? void 0 : params.biz) ?? queryBusinessCode;
    const value = raw != null ? String(raw).trim() : "";
    return value || void 0;
  }, [
    props.businessCode,
    props.biz,
    params == null ? void 0 : params.business_code,
    params == null ? void 0 : params.biz,
    queryBusinessCode
  ]);
  const extParams = (0, import_react.useMemo)(() => {
    return {
      list: {
        business_code: resolvedBusinessCode,
        // 仅当外部传入 mode 时附加，避免对既有调用方产生任何影响
        ...mode !== void 0 ? { mode } : {}
      }
    };
  }, [resolvedBusinessCode, mode]);
  const perspectivesRaw = (0, import_usePerspectives.default)({
    relationTables: Array.isArray(_getRelationTables.data) ? _getRelationTables.data : [],
    onOpenDetail,
    businessCode: resolvedBusinessCode
  });
  const perspectives = (0, import_react.useMemo)(() => {
    if (!hideToolbarSearch) return perspectivesRaw;
    return (perspectivesRaw || []).map((p) => {
      var _a2;
      const originalGet = p == null ? void 0 : p.getChildComponentProps;
      if (typeof originalGet !== "function") {
        return {
          ...p,
          childComponentProps: {
            ...(p == null ? void 0 : p.childComponentProps) || {},
            toolBar: {
              ...((_a2 = p == null ? void 0 : p.childComponentProps) == null ? void 0 : _a2.toolBar) || {},
              search: false
            }
          }
        };
      }
      return {
        ...p,
        getChildComponentProps: (ctx) => {
          const result = originalGet(ctx) || {};
          return {
            ...result,
            toolBar: {
              ...result.toolBar || {},
              search: false
            }
          };
        }
      };
    });
  }, [perspectivesRaw, hideToolbarSearch]);
  const gridDataProps = (0, import_useSalesGridData.useSalesGridData)({
    perspective,
    extParams,
    externalKeyword: keyword
  });
  const adapterLocale = ((_j = (_i = context == null ? void 0 : context.engine) == null ? void 0 : _i.props) == null ? void 0 : _j.locale) === "zh-CN" || ((_l = (_k = context == null ? void 0 : context.engine) == null ? void 0 : _k.props) == null ? void 0 : _l.locale) === "zh-HK" ? "zh-cn" : ((_n = (_m = context == null ? void 0 : context.engine) == null ? void 0 : _m.props) == null ? void 0 : _n.locale) === "en" || ((_p = (_o = context == null ? void 0 : context.engine) == null ? void 0 : _o.props) == null ? void 0 : _p.locale) === "en-US" ? "en" : "zh-cn";
  const rawLocale = ((_r = (_q = context == null ? void 0 : context.engine) == null ? void 0 : _q.props) == null ? void 0 : _r.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;
