<template>
  <scroll-view
    :scroll-left="scrollLeft"
    :class="['bg-' + color, type === 'center' ? 'text-center' : '', shadow ? 'nav-shadow' : '', className]"
    :style="style"
    class="nav"
    style="z-index: 10;"
    scroll-with-animation
    scroll-x
  >
    <template v-if="type !== 'flex'">
      <view
        v-for="(item, idx) in items"
        @tap="tabSelect(idx)"
        :class="value === idx ? 'text-green cur' : ''"
        :key="idx"
        class="cu-item"
      >
        {{ item }}
      </view>
    </template>

    <view v-else class="flex text-center">
      <view
        @tap="tabSelect(idx)"
        v-for="(item, idx) in items"
        :key="idx"
        :class="[value === idx ? (color ? 'bg-white cur' : 'bg-green cur') : '']"
        class="cu-item flex-sub"
      >
        {{ item }}
      </view>
    </view>
  </scroll-view>
</template>

<script>
export default {
  name: 'l-nav',

  props: {
    color: { default: 'white' },
    items: { default: () => [] },
    value: {},
    type: { default: 'default' },
    shadow: {}
  },

  data() {
    return {
      scrollLeft: 0
    }
  },

  methods: {
    tabSelect(idx) {
      this.scrollLeft = (idx - 1) * 60

      this.$emit('input', idx)
      this.$emit('change', idx)
    }
  }
}
</script>

<style scoped>
.nav-shodow {
  box-shadow: 0px 0px 7px 0px #666;
}
</style>
