import { FormOutlined } from '@ant-design/icons';
import { styled } from '@linaria/react';
import Empty from '../../core/Empty/index.js';
import cs from 'classnames';
import _ from 'lodash';
import React__default from 'react';

const Table = /*#__PURE__*/styled('div')({
  name: "Table",
  class: "E_t1sqg15u",
  propsAsIs: false
});
const TableHeader = /*#__PURE__*/styled('header')({
  name: "TableHeader",
  class: "E_t4zczcp",
  propsAsIs: false
});
const TableContent = /*#__PURE__*/styled('div')({
  name: "TableContent",
  class: "E_t1s7goww",
  propsAsIs: false
});
const TableRow = /*#__PURE__*/styled('div')({
  name: "TableRow",
  class: "E_t93e4cf",
  propsAsIs: false
});
const _exp = /*#__PURE__*/() => props => props.width;
const RowLabel = /*#__PURE__*/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.createElement(TableRow, {
    className: cs("table-row", {
      hiddenBorder
    }),
    "data-key": dataKey
  }, /* @__PURE__ */React__default.createElement(RowLabel, {
    width: labelWidth,
    className: cs({
      hidden: hiddenTitle
    })
  }, title), /* @__PURE__ */React__default.createElement("div", {
    className: "content"
  }, children));
};
const SummaryTableContent = props => {
  const {
    items,
    labelWidth,
    dataSource
  } = props;
  return /* @__PURE__ */React__default.createElement(React__default.Fragment, null, items.map(item => {
    if (item.dataIndex === "[__typename]") {
      return null;
    }
    const value = _.get(dataSource, item.dataIndex);
    return /* @__PURE__ */React__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) : _.isNull(value) || _.isUndefined(value) || value === "" ? Empty : value);
  }));
};
const SummaryTable = props => {
  const {
    showHeader = true,
    border = true,
    className,
    title,
    showEdit,
    onEdit,
    rightAlign,
    layout = "horizontal"
  } = props;
  return /* @__PURE__ */React__default.createElement(Table, {
    className: cs(["summary-table", className, border ? "has-border" : "", rightAlign ? "align-right" : "", layout])
  }, showHeader && /* @__PURE__ */React__default.createElement(TableHeader, {
    className: "table-header"
  }, /* @__PURE__ */React__default.createElement("span", {
    className: "table-title"
  }, title), showEdit && /* @__PURE__ */React__default.createElement(FormOutlined, {
    className: "edit-icon",
    onClick: () => {
      onEdit && onEdit();
    }
  })), /* @__PURE__ */React__default.createElement(TableContent, null, "children" in props ? props.children : /* @__PURE__ */React__default.createElement(SummaryTableContent, {
    items: props.items,
    labelWidth: props.labelWidth,
    dataSource: props.dataSource
  })));
};
var SummaryTable$1 = SummaryTable;

export { SummaryTableRow, SummaryTable$1 as default };
