"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

require("core-js/modules/es7.array.includes");

require("./index.css");

var _values = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/values"));

var _base = require("../../utils/base");

var _item = _interopRequireDefault(require("./item"));

var _get2 = _interopRequireDefault(require("lodash/get"));

var _vueNormalizeComponent = _interopRequireDefault(require("../../utils/vue-normalize-component.js"));

/* script */
var __vue_script__ = {
  name: (0, _base.createComponentName)('filter'),
  components: {
    item: _item.default
  },
  mixins: [_base.componentMixin],
  props: {
    tags: {
      type: Array,
      default: function _default() {
        return [];
      }
    },
    hides: {
      type: Array,
      default: function _default() {
        return [];
      }
    }
  },

  data() {
    return {
      maps: {}
    };
  },

  watch: {
    maps: {
      handler(value) {
        var ids = (0, _values.default)(value).filter(Boolean);
        this.$emit('change', ids);
      },

      deep: true
    }
  },

  mounted() {
    var _this = this;

    // 映射关系
    var _this$$route$query$fi = this.$route.query.filter,
        filter = _this$$route$query$fi === void 0 ? [] : _this$$route$query$fi;
    this.maps = this.tags.reduce(function (prev, curr) {
      var item = curr.lists.find(function (o) {
        return filter.includes(String(o.id));
      });
      var val = item ? item.id : null; // 某些筛选项需要自定义隐藏选择全部的按钮

      if (!val && _this.hides.includes(curr.name)) {
        val = (0, _get2.default)(curr, 'lists[0].id');
      }

      prev[curr.name] = val;
      return prev;
    }, {});
  },

  methods: {
    selected(name, id, index, parentIndex) {
      this.maps[name] = id;
      this.$emit('selected', {
        name,
        id,
        index,
        parentIndex
      });
    }

  },

  render() {
    var _this2 = this;

    var h = arguments[0];
    return h("div", {
      "class": this.bem()
    }, [this.tags.map(function (item, index) {
      return h("item", {
        attrs: {
          info: item,
          parentIndex: index,
          selected: _this2.selected,
          visiableAllBtn: !_this2.hides.includes(item.name),
          selectId: _this2.maps[item.name]
        },
        key: index
      });
    })]);
  }

};
/* template */

/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = undefined;
/* component normalizer */

/* style inject */

/* style inject SSR */
var _default2 = (0, _vueNormalizeComponent.default)({}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

exports.default = _default2;