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/components/record-view/index.tsx
var record_view_exports = {};
__export(record_view_exports, {
  default: () => record_view_default
});
module.exports = __toCommonJS(record_view_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_Pagination = __toESM(require("../Pagination"));
var import_icons = require("@ant-design/icons");
var import_react_infinite_scroll_component = __toESM(require("react-infinite-scroll-component"));
var import_hooks = require("../../hooks");
var import_index = require("./index.less");
var prefix = "pisell-lowcode-";
var RecordView = (props) => {
  const {
    detail,
    leftSpan,
    rightSpan,
    gutter,
    style,
    pagination,
    header,
    footer,
    renderItem,
    onRowClick,
    paginationType,
    listGap,
    loadMoreData,
    listHeight,
    pcDetailModalDisplay,
    padDetailModalDisplay,
    mobilePadDetailModalDisplay,
    children,
    locale,
    emptyButtons = [],
    ...others
  } = props;
  const responsive = (0, import_hooks.useResponsive)();
  const [detailModalShow, setDetailModalShow] = (0, import_react.useState)(false);
  const detailModalDisplay = (0, import_react.useMemo)(() => {
    if (responsive === "pc") {
      return pcDetailModalDisplay;
    } else if (responsive === "ipad") {
      return padDetailModalDisplay;
    } else if (responsive === "phone") {
      return mobilePadDetailModalDisplay;
    }
  }, [
    responsive,
    pcDetailModalDisplay,
    padDetailModalDisplay,
    mobilePadDetailModalDisplay
  ]);
  const _footer = (0, import_react.useMemo)(() => {
    if (!(pagination && paginationType === "default") && !footer) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, pagination && paginationType === "default" && /* @__PURE__ */ import_react.default.createElement(import_Pagination.default, { showLessItems: true, ...pagination }), footer);
  }, [pagination, footer]);
  const _renderItem = (0, import_react.useCallback)(
    (item) => {
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          onClick: () => {
            setDetailModalShow(true);
            onRowClick(item);
          },
          style: { marginBottom: listGap }
        },
        renderItem(item)
      );
    },
    [renderItem]
  );
  const _leftSpan = (0, import_react.useMemo)(() => {
    if (detailModalDisplay) {
      return 24;
    }
    return leftSpan;
  }, [leftSpan, detailModalDisplay]);
  const emptyDom = (0, import_react.useMemo)(() => {
    if (props.dataSource.length > 0) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Empty,
      {
        description: locale == null ? void 0 : locale.emptyText,
        image: import_antd.Empty.PRESENTED_IMAGE_SIMPLE
      }
    ), !!emptyButtons.length && /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}empty-button` }, /* @__PURE__ */ import_react.default.createElement(import_antd.Space, null, emptyButtons.map((item) => /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { ...item })))));
  }, [props.dataSource, locale, emptyButtons]);
  const scrollListId = (0, import_react.useMemo)(() => {
    return `scrollableDiv-${(0, import_utils.getUniqueId)()}`;
  }, []);
  const list = (0, import_react.useMemo)(() => {
    if (paginationType === "scroll") {
      return /* @__PURE__ */ import_react.default.createElement("div", null, header && /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}scroll-header-wrap` }, header), /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          id: scrollListId,
          style: {
            height: listHeight || 400,
            overflow: "auto"
          }
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_react_infinite_scroll_component.default,
          {
            dataLength: props.dataSource.length,
            next: loadMoreData,
            hasMore: props.dataSource.length < ((pagination == null ? void 0 : pagination.total) || 999999),
            loader: props.dataSource.length > 0 && /* @__PURE__ */ import_react.default.createElement(
              import_antd.Skeleton,
              {
                avatar: true,
                paragraph: { rows: 1 },
                active: true,
                className: `${prefix}scroll-skeleton`
              }
            ),
            scrollableTarget: scrollListId
          },
          /* @__PURE__ */ import_react.default.createElement(import_antd.List, { ...others, renderItem: _renderItem }, emptyDom)
        )
      ), _footer && /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}scroll-footer-wrap` }, _footer));
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.List,
      {
        ...others,
        renderItem: _renderItem,
        header,
        footer: _footer
      },
      emptyDom
    );
  }, [props, _renderItem, _footer]);
  return /* @__PURE__ */ import_react.default.createElement(import_antd.Row, { gutter, style, className: `${prefix}record-view` }, /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: _leftSpan }, list), !detailModalDisplay && /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: rightSpan }, detail), detailModalShow && detailModalDisplay && /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}detail-modal-wrap` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}modal-header` }, /* @__PURE__ */ import_react.default.createElement(
    import_icons.CloseOutlined,
    {
      className: `${prefix}close-icon`,
      onClick: () => setDetailModalShow(false)
    }
  )), detail));
};
var record_view_default = RecordView;
