import "./index.css";
import _Object$values from "@babel/runtime-corejs2/core-js/object/values";

/* script */
import { createComponentName, componentMixin } from '../_utils/component';
import item from './Item';
import _get from 'lodash/get';
const __vue_script__ = {
  name: createComponentName('filter'),
  components: {
    item
  },
  mixins: [componentMixin],
  props: {
    tags: {
      type: Array,
      default: () => []
    },
    hides: {
      type: Array,
      default: () => []
    }
  },

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

  watch: {
    maps: {
      handler(value) {
        const ids = _Object$values(value).filter(Boolean);

        this.$emit('change', ids);
      },

      deep: true
    }
  },

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

      if (!val && this.hides.includes(curr.name)) {
        val = _get(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() {
    const h = arguments[0];
    return h("div", {
      "class": this.bem()
    }, [this.tags.map((item, index) => {
      return h("item", {
        attrs: {
          info: item,
          parentIndex: index,
          selected: this.selected,
          visiableAllBtn: !this.hides.includes(item.name),
          selectId: this.maps[item.name]
        },
        key: index
      });
    })]);
  }

};
/* template */

/* style */

const __vue_inject_styles__ = undefined;
/* scoped */

const __vue_scope_id__ = undefined;
/* module identifier */

const __vue_module_identifier__ = undefined;
/* functional template */

const __vue_is_functional_template__ = undefined;
/* component normalizer */

import __vue_normalize__ from '../_utils/vue-normalize-component.js';
/* style inject */

/* style inject SSR */

export default __vue_normalize__({}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);