'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var icons = require('@ant-design/icons');
var react = require('@linaria/react');
var index = require('../../core/Empty/index.js');
var cs = require('classnames');
var _ = require('lodash');
var React = require('react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var cs__default = /*#__PURE__*/_interopDefault(cs);
var ___default = /*#__PURE__*/_interopDefault(_);
var React__default = /*#__PURE__*/_interopDefault(React);

const Table = /*#__PURE__*/react.styled('div')({
  name: "Table",
  class: "E_t1sqg15u",
  propsAsIs: false
});
const TableHeader = /*#__PURE__*/react.styled('header')({
  name: "TableHeader",
  class: "E_t4zczcp",
  propsAsIs: false
});
const TableContent = /*#__PURE__*/react.styled('div')({
  name: "TableContent",
  class: "E_t1s7goww",
  propsAsIs: false
});
const TableRow = /*#__PURE__*/react.styled('div')({
  name: "TableRow",
  class: "E_t93e4cf",
  propsAsIs: false
});
const _exp = /*#__PURE__*/() => props => props.width;
const RowLabel = /*#__PURE__*/react.styled('label')({
  name: "RowLabel",
  class: "E_rhz2uv5",
  propsAsIs: false,
  vars: {
    "rhz2uv5-0": [_exp()]
  }
});
const SummaryTableRow = props => {
  const {
    labelWidth = "42%",
    title,
    children,
    hiddenTitle = false,
    hiddenBorder = false,
    dataKey
  } = props;
  return /* @__PURE__ */React__default.default.createElement(TableRow, {
    className: cs__default.default("table-row", {
      hiddenBorder
    }),
    "data-key": dataKey
  }, /* @__PURE__ */React__default.default.createElement(RowLabel, {
    width: labelWidth,
    className: cs__default.default({
      hidden: hiddenTitle
    })
  }, title), /* @__PURE__ */React__default.default.createElement("div", {
    className: "content"
  }, children));
};
const SummaryTableContent = props => {
  const {
    items,
    labelWidth,
    dataSource
  } = props;
  return /* @__PURE__ */React__default.default.createElement(React__default.default.Fragment, null, items.map(item => {
    if (item.dataIndex === "[__typename]") {
      return null;
    }
    const value = ___default.default.get(dataSource, item.dataIndex);
    return /* @__PURE__ */React__default.default.createElement(SummaryTableRow, {
      key: item.key,
      labelWidth,
      hiddenTitle: item == null ? void 0 : item.hiddenTitle,
      hiddenBorder: item == null ? void 0 : item.hiddenBorder,
      title: item.title,
      dataKey: item.key
    }, item.render ? item.render(value, dataSource) : ___default.default.isNull(value) || ___default.default.isUndefined(value) || value === "" ? index : value);
  }));
};
const SummaryTable = props => {
  const {
    showHeader = true,
    border = true,
    className,
    title,
    showEdit,
    onEdit,
    rightAlign,
    layout = "horizontal"
  } = props;
  return /* @__PURE__ */React__default.default.createElement(Table, {
    className: cs__default.default(["summary-table", className, border ? "has-border" : "", rightAlign ? "align-right" : "", layout])
  }, showHeader && /* @__PURE__ */React__default.default.createElement(TableHeader, {
    className: "table-header"
  }, /* @__PURE__ */React__default.default.createElement("span", {
    className: "table-title"
  }, title), showEdit && /* @__PURE__ */React__default.default.createElement(icons.FormOutlined, {
    className: "edit-icon",
    onClick: () => {
      onEdit && onEdit();
    }
  })), /* @__PURE__ */React__default.default.createElement(TableContent, null, "children" in props ? props.children : /* @__PURE__ */React__default.default.createElement(SummaryTableContent, {
    items: props.items,
    labelWidth: props.labelWidth,
    dataSource: props.dataSource
  })));
};
var SummaryTable$1 = SummaryTable;

exports.SummaryTableRow = SummaryTableRow;
exports.default = SummaryTable$1;
