/**
 * 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 tdesignIconsVue = require('tdesign-icons-vue');
var button_index = require('../../../button/index.js');
var dialog_index = require('../../../dialog/index.js');
var checkbox_index = require('../../../checkbox/index.js');
var checkbox_group = require('../../../checkbox/group.js');
var table_primaryTableProps = require('../../primary-table-props.js');
var config = require('../../../config.js');
require('../../../button/button.js');
require('../../../utils/classnames.js');
require('../../../loading/index.js');
require('../../../loading/loading.js');
require('../../../loading/icon/gradient.js');
require('../../../utils/set-style.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('../../../utils/transfer-dom.js');
require('../../../loading/props.js');
require('../../../utils/withInstall.js');
require('lodash/capitalize');
require('../../../loading/plugin.js');
require('../../../button/props.js');
require('../../../utils/ripple.js');
require('../../../dialog/dialog.js');
require('../../../dialog/actions.js');
require('../../../_chunks/dep-44e6bdf6.js');
require('lodash/isObject');
require('../../../dialog/props.js');
require('../../../utils/mixins.js');
require('../../../config-provider/config-receiver.js');
require('../../../config-provider/zh_CN_config.js');
require('../../../utils/event.js');
require('../../../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('../../../dialog/plugin.js');
require('../../../checkbox/checkbox.js');
require('../../../checkbox/props.js');
require('../../../utils/map-props.js');
require('lodash/intersection');
require('../../../checkbox/checkbox-group-props.js');

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);

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 content = "\u81EA\u5B9A\u4E49\u5217";
var showColumns = Vue__default["default"].extend({
  name: "".concat(config.prefix, "-primary-show-columns"),
  props: {
    columns: table_primaryTableProps["default"].columns,
    showColumns: {
      type: Boolean,
      "default": false
    }
  },
  data: function data() {
    return {
      showColumnKeys: this.columns.map(function (_ref) {
        var colKey = _ref.colKey;
        return colKey;
      }),
      showColumnCheckboxKeys: this.columns.map(function (_ref2) {
        var colKey = _ref2.colKey;
        return colKey;
      }),
      isShowColumnsDlg: false
    };
  },
  computed: {
    showColumnCheckboxOpts: function showColumnCheckboxOpts() {
      return this.columns.filter(function (_ref3) {
        var colKey = _ref3.colKey,
            title = _ref3.title;
        return colKey && title;
      }).map(function (_ref4) {
        var colKey = _ref4.colKey,
            title = _ref4.title;
        return {
          label: title,
          value: colKey
        };
      });
    },
    isAllShowColumns: function isAllShowColumns() {
      var _this = this;

      return this.showColumnCheckboxOpts.every(function (_ref5) {
        var value = _ref5.value;
        return _this.showColumnCheckboxKeys.includes(value);
      });
    },
    isSomeShowColumns: function isSomeShowColumns() {
      var _this2 = this;

      return !this.isAllShowColumns && this.showColumnCheckboxOpts.some(function (_ref6) {
        var value = _ref6.value;
        return _this2.showColumnCheckboxKeys.includes(value);
      });
    }
  },
  methods: {
    getShowColumns: function getShowColumns(columns) {
      var _this3 = this;

      return columns.filter(function (_ref7) {
        var colKey = _ref7.colKey;
        return _this3.showColumnKeys.includes(colKey) || !_this3.showColumnCheckboxOpts.map(function (_ref8) {
          var value = _ref8.value;
          return value;
        }).includes(colKey);
      });
    },
    renderShowColumnsDlgFooter: function renderShowColumnsDlgFooter() {
      var h = this.$createElement;
      return h("div", [h(button_index.Button, {
        "attrs": {
          "variant": "base",
          "theme": "primary"
        },
        "on": _objectSpread({}, {
          click: this.handleConfirmShowColumnsDlg
        })
      }, ["\u786E\u5B9A"]), h(button_index.Button, {
        "on": _objectSpread({}, {
          click: this.handleCancelShowColumnsDlg
        })
      }, ["\u53D6\u6D88"])]);
    },
    renderShowColumnsDlg: function renderShowColumnsDlg() {
      var _this4 = this;

      var h = this.$createElement;
      return h(dialog_index.Dialog, {
        "attrs": {
          "header": content,
          "footer": this.renderShowColumnsDlgFooter,
          "visible": this.isShowColumnsDlg
        }
      }, [h("div", {
        "slot": "body"
      }, [h("div", [h(checkbox_index.Checkbox, {
        "attrs": {
          "indeterminate": this.isSomeShowColumns,
          "checked": this.isAllShowColumns
        },
        "on": {
          "change": this.handleClickAllShowColumns
        }
      }, ["\u5168\u9009"])]), h(checkbox_group["default"], {
        "attrs": {
          "options": this.showColumnCheckboxOpts
        },
        "model": {
          value: _this4.showColumnCheckboxKeys,
          callback: function callback($$v) {
            _this4.showColumnCheckboxKeys = $$v;
          }
        }
      })])]);
    },
    renderShowColumns: function renderShowColumns() {
      var _this5 = this;

      var h = this.$createElement;
      return h("div", [h("div", [h(button_index.Button, {
        "attrs": {
          "icon": function icon() {
            return h(tdesignIconsVue.BulletpointIcon);
          }
        },
        "on": {
          "click": function click() {
            return _this5.isShowColumnsDlg = true;
          }
        }
      }, [content])]), this.renderShowColumnsDlg()]);
    },
    handleClickAllShowColumns: function handleClickAllShowColumns() {
      this.showColumnCheckboxKeys = this.isAllShowColumns ? [] : this.showColumnCheckboxOpts.map(function (_ref9) {
        var value = _ref9.value;
        return value;
      });
    },
    handleConfirmShowColumnsDlg: function handleConfirmShowColumnsDlg() {
      this.showColumnKeys = _toConsumableArray__default["default"](this.showColumnCheckboxKeys);
      this.handleCancelShowColumnsDlg();
    },
    handleCancelShowColumnsDlg: function handleCancelShowColumnsDlg() {
      this.isShowColumnsDlg = false;
    },
    updateColumns: function updateColumns() {
      this.showColumnKeys = this.columns.map(function (_ref10) {
        var colKey = _ref10.colKey;
        return colKey;
      });
      this.showColumnCheckboxKeys = this.columns.map(function (_ref11) {
        var colKey = _ref11.colKey;
        return colKey;
      });
    }
  },
  watch: {
    columns: {
      deep: true,
      handler: function handler() {
        this.updateColumns();
      }
    }
  }
});

exports["default"] = showColumns;
//# sourceMappingURL=show-columns.js.map
