Component({
  props: {
    show: false,
    dateList: [],
    onChange: () => null
  },
  data: {
    activeIndex: -1,
    scrollLeft: 0
  },

  didMount() {},

  methods: {
    updateState(state) {
      return new Promise(resolve => this.setData(state, resolve));
    },

    async onScroll(e) {
      const {
        scrollLeft
      } = e.detail;
      await this.updateState({
        scrollLeft
      });
    },

    async onSelectAll() {
      const {
        activeIndex
      } = this.data;
      if (activeIndex === -1) return;
      await this.updateState({
        scrollLeft: 0,
        activeIndex: -1
      });
      this.props.onChange('');
    },

    async onSelectOne(e) {
      const {
        dateList
      } = this.props;
      const {
        activeIndex
      } = this.data;
      const {
        index
      } = e.target.dataset;
      if (index === activeIndex) return;
      this.props.onChange(dateList[index] || '');
      await this.updateState({
        activeIndex: index
      });
    }

  }
});