/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import get from 'lodash/get';
import baseTableProps from '../../base-table-props.js';
import ExpandBox from '../expand-box.js';
import TableRow from '../../base-table/table-row.js';
import { ExpandProps } from '../../util/interface.js';
import { getRecord, filterDataByIds } from '../../util/common.js';
import { prefix } from '../../../config.js';
import { emitEvent } from '../../../utils/event.js';
import { renderTNodeJSX } from '../../../utils/render-tnode.js';
import '../../../_chunks/dep-42d5c87e.js';
import 'lodash/isFunction';
import 'tdesign-icons-vue';
import '../../../utils/mixins.js';
import '../../../config-provider/config-receiver.js';
import '../../../config-provider/zh_CN_config.js';
import '../../../config-provider/type.js';
import '../../primary-table-props.js';
import '../../base-table/table-cell.js';
import '../../../popup/index.js';
import '../../../popup/popup.js';
import '@babel/runtime/helpers/typeof';
import '@popperjs/core';
import '../../../_chunks/dep-1db5c91c.js';
import '../../../utils/classnames.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../utils/easing.js';
import '../../../popup/props.js';
import '../../../utils/set-style.js';
import '../../../utils/map-props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../../../popup/type.js';
import '../../../utils/helper.js';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var expandedColKey = "expanded-icon-cell";
var expand = Vue.extend({
  name: "".concat(prefix, "-primary-table-expand"),
  props: _objectSpread({
    data: baseTableProps.data,
    rowKey: baseTableProps.rowKey
  }, ExpandProps),
  computed: {
    reRowKey: function reRowKey() {
      return this.rowKey || "id";
    }
  },
  methods: {
    getExpandRowHandler: function getExpandRowHandler() {
      var _this = this;

      if (!this.expandedRow && !this.$scopedSlots.expandedRow) return;
      return function (h, params) {
        return renderTNodeJSX(_this, "expandedRow", {
          params: params
        });
      };
    },
    getExpandColumns: function getExpandColumns(columns) {
      var _this2 = this;

      var expandRowHandler = this.getExpandRowHandler();
      if (!expandRowHandler || !this.expandIcon) return columns;
      return [{
        colKey: expandedColKey,
        width: 48,
        attrs: {
          "class": ["".concat(prefix, "-table__expandable-icon-cell")],
          style: {
            overflow: "auto"
          }
        },
        cell: function cell(h, _ref) {
          var row = _ref.row,
              rowIndex = _ref.rowIndex;
          return _this2.renderExpandIconCell({
            row: row,
            rowIndex: rowIndex
          });
        }
      }].concat(_toConsumableArray(columns));
    },
    renderExpandIconCell: function renderExpandIconCell(_ref2) {
      var _this3 = this;

      var row = _ref2.row,
          rowIndex = _ref2.rowIndex;
      var h = this.$createElement;
      var _this$expandedRowKeys = this.expandedRowKeys,
          expandedRowKeys = _this$expandedRowKeys === void 0 ? [] : _this$expandedRowKeys;
      var id = get(row, this.reRowKey);
      var isExpanded = expandedRowKeys.indexOf(id) !== -1;
      return h(ExpandBox, {
        "attrs": {
          "expandIcon": this.expandIcon,
          "expanded": isExpanded,
          "row": row,
          "rowIndex": rowIndex
        },
        "on": {
          "click": function click(e) {
            _this3.expandOnRowClick && e.stopPropagation();

            _this3.handleExpandChange(row);
          }
        }
      });
    },
    renderExpandedRow: function renderExpandedRow(_ref3) {
      var rows = _ref3.rows,
          row = _ref3.row,
          defaultColumns = _ref3.columns,
          rowIndex = _ref3.rowIndex;
      var h = this.$createElement;
      var columnCounts = defaultColumns.length;
      var expandRowHandler = this.getExpandRowHandler();
      if (!expandRowHandler) return;
      var expandedRowKeys = this.expandedRowKeys;
      var id = get(row, this.reRowKey);
      var isShowExpanded = expandedRowKeys.includes(id);
      var params = {
        record: getRecord(row),
        row: row,
        index: rowIndex
      };
      var columns = [{
        colKey: "expanded-row",
        attrs: {
          colspan: columnCounts,
          "class": ["".concat(prefix, "-table__expanded-cell")]
        },
        render: function render(h) {
          return expandRowHandler(h, params);
        }
      }];
      rows.push(h(TableRow, {
        "key": "ExpandTableRowBox".concat(rowIndex),
        "attrs": {
          "rowKey": this.rowKey,
          "columns": columns
        },
        "style": _objectSpread({}, !isShowExpanded ? {
          display: "none"
        } : {})
      }));
    },
    handleExpandChange: function handleExpandChange() {
      var record = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      var expandedRowKeys = _toConsumableArray(this.expandedRowKeys);

      var id = get(record, this.reRowKey);
      var expandedRowIndex = expandedRowKeys.indexOf(id);
      var isExpanded = expandedRowIndex !== -1;
      isExpanded ? expandedRowKeys.splice(expandedRowIndex, 1) : expandedRowKeys.push(id);
      emitEvent(this, "expand-change", expandedRowKeys, {
        expandedRowData: filterDataByIds(this.data, expandedRowKeys)
      });
    }
  }
});

export { expand as default };
//# sourceMappingURL=expand.js.map
