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

'use strict';

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

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var get = require('lodash/get');
var table_baseTableProps = require('../../base-table-props.js');
var table_primaryTable_expandBox = require('../expand-box.js');
var table_baseTable_tableRow = require('../../base-table/table-row.js');
var table_util_interface = require('../../util/interface.js');
var table_util_common = require('../../util/common.js');
var config = require('../../../config.js');
var utils_event = require('../../../utils/event.js');
var utils_renderTnode = require('../../../utils/render-tnode.js');
require('../../../_chunks/dep-44e6bdf6.js');
require('lodash/isFunction');
require('tdesign-icons-vue');
require('../../../utils/mixins.js');
require('../../../config-provider/config-receiver.js');
require('../../../config-provider/zh_CN_config.js');
require('../../primary-table-props.js');
require('../../base-table/table-cell.js');
require('../../../popup/index.js');
require('../../../popup/popup.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../../../_chunks/dep-939cdc39.js');
require('../../../utils/classnames.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../popup/props.js');
require('../../../utils/set-style.js');
require('../../../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../../../utils/withInstall.js');
require('lodash/capitalize');
require('../../../utils/helper.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);

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__default["default"](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__default["default"].extend({
  name: "".concat(config.prefix, "-primary-table-expand"),
  props: _objectSpread({
    data: table_baseTableProps["default"].data,
    rowKey: table_baseTableProps["default"].rowKey
  }, table_util_interface.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 utils_renderTnode.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(config.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__default["default"](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__default["default"](row, this.reRowKey);
      var isExpanded = expandedRowKeys.indexOf(id) !== -1;
      return h(table_primaryTable_expandBox["default"], {
        "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__default["default"](row, this.reRowKey);
      var isShowExpanded = expandedRowKeys.includes(id);
      var params = {
        record: table_util_common.getRecord(row),
        row: row,
        index: rowIndex
      };
      var columns = [{
        colKey: "expanded-row",
        attrs: {
          colspan: columnCounts,
          "class": ["".concat(config.prefix, "-table__expanded-cell")]
        },
        render: function render(h) {
          return expandRowHandler(h, params);
        }
      }];
      rows.push(h(table_baseTable_tableRow["default"], {
        "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__default["default"](this.expandedRowKeys);

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

exports["default"] = expand;
//# sourceMappingURL=expand.js.map
