<template>
  <div>
    <v-btn-toggle v-model="text" tile color="primary" group mandatory >
      <v-btn value="changeY" v-if="yList?.length">
        Y坐标 ( {{ yList.length < 1 ? 0 :settingsY.length }}/{{ yList.length }} )
      </v-btn>
      <v-btn value="changeX" v-if="xList?.length">
        X坐标 ( {{ +(xList.length > 0) }}/{{ xList.length }} )
      </v-btn>
    </v-btn-toggle>
    <v-divider></v-divider>
    <div class="box py-3">
      <div v-show="text === 'changeX'" style="height: calc(100vh - 204px); overflow-y: auto;">
        <v-list-item-group v-model="settingsX" mandatory @change="handleChangeX">
          <v-list-item v-for="item in xList" :key="'x' + item.value">
            <template v-slot:default="{ active }">
              <v-list-item-action>
                <v-checkbox :input-value="active" readonly></v-checkbox>
              </v-list-item-action>

              <v-list-item-content>
                <v-list-item-title>{{ item.text }}</v-list-item-title>
              </v-list-item-content>
            </template>
          </v-list-item>
        </v-list-item-group>
      </div>
      <div v-show="text === 'changeY'" style="height: calc(100vh - 204px); overflow-y: auto;">
        <v-list-item-group v-model="settingsY" mandatory multiple @change="handleChangeY">
          <v-list-item v-for="item in yList" :key="item.value">
            <template v-slot:default="{ active }">
              <v-list-item-action>
                <v-checkbox :input-value="active" readonly></v-checkbox>
              </v-list-item-action>

              <v-list-item-content>
                <v-list-item-title>{{ item.text }}</v-list-item-title>
              </v-list-item-content>
            </template>
          </v-list-item>
        </v-list-item-group>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'general-settings',
  components: {},
  props: {
    type: {
      type: String,
      default: '' // line bar pie
    },
    xList: {
      type: Array,
      default: () => []
    },
    yList: {
      type: Array,
      default: () => []
    },
    xChosen: {
      type: Number,
      default: 0
    },
    yChosen: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      text: 'changeY',
      settingsX: 0,
      settingsY: [0]
    }
  },
  watch: {
    yChosen: {
      handler (val) {
        if (val && val.length) this.settingsY = [...val] // 默认选中y个数改变
      },
      immediate: true,
      deep: true
    },
    xChosen: {
      handler (val) {
        this.settingsX = val || 0
      },
      immediate: true,
      deep: true
    }
  },
  created () {
  },
  methods: {
    handleChangeX () {
      this.handleChange('x')
    },
    handleChangeY () {
      this.handleChange('y')
    },
    handleChange (type) {
      if (this.type === 'pie') {
        if (this.settingsY?.length) this.settingsY = [this.settingsY[this.settingsY.length - 1]]
      }
      this.$emit('change', type, {
        x: this.settingsX,
        y: this.settingsY
      })
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
