function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useEffect, useMemo } from 'react';
import { useRequest } from 'ahooks';
import { locales } from '@pisell/utils';
import { PisellConfigProvider } from '@pisell/materials';
import { LocalizationProvider } from '@pisell/date-picker';
import { AdapterDayjs } from '@pisell/date-picker/es/AdapterDayjs';
import { request } from "../../utils";
import useEngineContext from "../../hooks/useEngineContext";
import PisellSalesGrid from "../pisellSalesGrid";
import usePerspectives from "./hooks/usePerspectives";
import { useSalesGridData } from "./hooks/useSalesGridData";
import orderListLocales from "../orderList/locales";
import salesManagementLocales from "./locales";
import { getRelationTables } from "./serve";
var PisellSalesManagement = function PisellSalesManagement(props) {
  var _context$appHelper, _context$engine, _window, _context$engine2, _context$engine3, _context$engine4, _context$engine5, _context$engine6;
  var perspective = props.perspective,
    __id = props.__id;
  var context = useEngineContext();
  var utils = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
  var action = utils.action;
  request.setRequest(utils === null || utils === void 0 ? void 0 : utils.request);
  var _getRelationTables = useRequest(getRelationTables);
  var mergedLocales = {
    en: _objectSpread(_objectSpread({}, orderListLocales.en), salesManagementLocales.en),
    'zh-CN': _objectSpread(_objectSpread({}, orderListLocales['zh-CN']), salesManagementLocales['zh-CN']),
    'zh-HK': _objectSpread(_objectSpread({}, orderListLocales['zh-HK']), salesManagementLocales['zh-HK'])
  };
  locales.init(mergedLocales, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || 'en');
  useEffect(function () {
    if (perspective === 'monitor') {
      setTimeout(function () {
        action === null || action === void 0 || action({
          type: 'pisell1.registerBookingPlugin'
        });
      }, 300);
    }
  }, [perspective, action]);

  //@ts-ignore
  var useParams = (_window = window) === null || _window === void 0 || (_window = _window.app) === null || _window === void 0 || (_window = _window.history) === null || _window === void 0 ? void 0 : _window.useParams;
  //@ts-ignore
  var params = useParams === null || useParams === void 0 ? void 0 : useParams();
  var queryBusinessCode = useMemo(function () {
    if (typeof window === 'undefined') return undefined;
    var searchParams = new URLSearchParams(window.location.search || '');
    return searchParams.get('business_code') || undefined;
  }, []);
  var extParams = useMemo(function () {
    return {
      list: {
        business_code: props.biz || (params === null || params === void 0 ? void 0 : params.biz) || queryBusinessCode
      }
    };
  }, [props.biz, params === null || params === void 0 ? void 0 : params.biz, queryBusinessCode]);
  var perspectives = usePerspectives({
    relationTables: Array.isArray(_getRelationTables.data) ? _getRelationTables.data : []
  });
  var gridDataProps = useSalesGridData({
    perspective: perspective,
    extParams: extParams
  });
  var adapterLocale = (context === null || context === void 0 || (_context$engine2 = context.engine) === null || _context$engine2 === void 0 || (_context$engine2 = _context$engine2.props) === null || _context$engine2 === void 0 ? void 0 : _context$engine2.locale) === 'zh-CN' || (context === null || context === void 0 || (_context$engine3 = context.engine) === null || _context$engine3 === void 0 || (_context$engine3 = _context$engine3.props) === null || _context$engine3 === void 0 ? void 0 : _context$engine3.locale) === 'zh-HK' ? 'zh-cn' : (context === null || context === void 0 || (_context$engine4 = context.engine) === null || _context$engine4 === void 0 || (_context$engine4 = _context$engine4.props) === null || _context$engine4 === void 0 ? void 0 : _context$engine4.locale) === 'en' || (context === null || context === void 0 || (_context$engine5 = context.engine) === null || _context$engine5 === void 0 || (_context$engine5 = _context$engine5.props) === null || _context$engine5 === void 0 ? void 0 : _context$engine5.locale) === 'en-US' ? 'en' : 'zh-cn';

  // 与 materials getCurrentLocale 回退链一致：engine.props.locale → localStorage umi_locale → en-US，保证 Find/Filter/Sort 与 Quick Filter 同源语言
  var rawLocale = (context === null || context === void 0 || (_context$engine6 = context.engine) === null || _context$engine6 === void 0 || (_context$engine6 = _context$engine6.props) === null || _context$engine6 === void 0 ? void 0 : _context$engine6.locale) || (typeof localStorage !== 'undefined' ? localStorage.getItem('umi_locale') : null) || 'en-US';
  var materialsLocale = rawLocale === 'zh' ? 'zh-CN' : rawLocale;
  return /*#__PURE__*/React.createElement(PisellConfigProvider, {
    locale: materialsLocale
  }, /*#__PURE__*/React.createElement(LocalizationProvider, {
    dateAdapter: AdapterDayjs,
    adapterLocale: adapterLocale
  }, /*#__PURE__*/React.createElement("div", {
    style: Object.assign({}, {
      height: 0
    }, props === null || props === void 0 ? void 0 : props.style)
  }, /*#__PURE__*/React.createElement(PisellSalesGrid, {
    perspectives: perspectives,
    currentPerspective: perspective,
    extParams: extParams,
    __id: __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
  }))));
};
export default PisellSalesManagement;