<template>
  <div id="view-selector" class="view-selector">
    <a-select
      :value="curViewType"
      dropdown-class-name="view-selector-drop-down"
      @select="handleChange"
    >
      <a-select-option
        v-for="option in options"
        :key="option.type"
        :value="option.type"
      >
        {{ option.name }}
      </a-select-option>
    </a-select>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import store from '@/store'

export default defineComponent({
  name: 'ViewSelector',
  setup() {
    const curViewType = computed(() => store.state.curView.type)
    const options = computed(() => store.state.viewOptions)
    const handleChange = (type: string) => {
      store.commit(
        'SET_CURRENT_VIEW',
        options.value.find((option) => type === option.type)
      )
    }
    return {
      curViewType,
      options,
      handleChange,
    }
  },
})
</script>

<style lang="stylus">
@import '../../components/MyComponent/main.styl'

$bg = rgba(13, 39, 76, .7)
$size = .1rem
$height = .26rem

#view-selector.view-selector
  position fixed
  top .45rem
  left calc(20vw + .1rem)
  z-index 99
  .ant-select
    background $bg
    min-width .9rem
    .ant-select-selector
      min-width .9rem
      border-top none
      border-left none
      border-right none
      height $height
      .ant-select-selection-item
        font-size $size
        line-height $height
        text-align center
        color #fff
        font-weight bold
    .ant-select-arrow
      font-size $size * 0.8
.view-selector-drop-down
  &.ant-select-dropdown
    background $bg
    font-size $size
    .ant-select-item
      font-size $size
      line-height $height / 2
    .ant-select-item-option-selected:not(.ant-select-item-option-disabled)
      background $bg
      font-size $size
</style>
