/**
 * 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 { BulletpointIcon } from 'tdesign-icons-vue';
import { Button } from '../../../button/index.js';
import { Dialog } from '../../../dialog/index.js';
import { Checkbox } from '../../../checkbox/index.js';
import CheckboxGroup from '../../../checkbox/group.js';
import primaryTableProps from '../../primary-table-props.js';
import { prefix } from '../../../config.js';
import '../../../button/button.js';
import '../../../utils/classnames.js';
import '../../../loading/index.js';
import '../../../loading/loading.js';
import '../../../loading/icon/gradient.js';
import '../../../utils/set-style.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../utils/easing.js';
import '../../../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '../../../utils/transfer-dom.js';
import '../../../loading/props.js';
import '../../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../../../loading/type.js';
import '../../../loading/plugin.js';
import '../../../button/props.js';
import '../../../utils/ripple.js';
import '../../../button/type.js';
import '../../../dialog/dialog.js';
import '../../../dialog/actions.js';
import '../../../_chunks/dep-42d5c87e.js';
import 'lodash/isObject';
import '../../../dialog/props.js';
import '../../../utils/mixins.js';
import '../../../config-provider/config-receiver.js';
import '../../../config-provider/zh_CN_config.js';
import '../../../config-provider/type.js';
import '../../../utils/event.js';
import '../../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../../../dialog/type.js';
import '../../../dialog/plugin.js';
import '../../../checkbox/checkbox.js';
import '../../../checkbox/props.js';
import '../../../utils/map-props.js';
import '../../../checkbox/type.js';
import 'lodash/intersection';
import '../../../checkbox/checkbox-group-props.js';

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 content = "\u81EA\u5B9A\u4E49\u5217";
var showColumns = Vue.extend({
  name: "".concat(prefix, "-primary-show-columns"),
  props: {
    columns: primaryTableProps.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, {
        "attrs": {
          "variant": "base",
          "theme": "primary"
        },
        "on": _objectSpread({}, {
          click: this.handleConfirmShowColumnsDlg
        })
      }, ["\u786E\u5B9A"]), h(Button, {
        "on": _objectSpread({}, {
          click: this.handleCancelShowColumnsDlg
        })
      }, ["\u53D6\u6D88"])]);
    },
    renderShowColumnsDlg: function renderShowColumnsDlg() {
      var _this4 = this;

      var h = this.$createElement;
      return h(Dialog, {
        "attrs": {
          "header": content,
          "footer": this.renderShowColumnsDlgFooter,
          "visible": this.isShowColumnsDlg
        }
      }, [h("div", {
        "slot": "body"
      }, [h("div", [h(Checkbox, {
        "attrs": {
          "indeterminate": this.isSomeShowColumns,
          "checked": this.isAllShowColumns
        },
        "on": {
          "change": this.handleClickAllShowColumns
        }
      }, ["\u5168\u9009"])]), h(CheckboxGroup, {
        "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, {
        "attrs": {
          "icon": function icon() {
            return h(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(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();
      }
    }
  }
});

export { showColumns as default };
//# sourceMappingURL=show-columns.js.map
