import { Text, View } from '@tarojs/components'
import classnames from 'classnames'
import { memo, useRef, useState } from 'react'
import styles from './index.module.scss'

interface Param {
  onSelect?: (val: number) => void
}
export default memo(({ onSelect }: Param) => {
  // 收货方法 1:自提，2：物流
  const shipmentMode = useRef([
    { value: 1, label: '上门自提', selected: false },
    { value: 2, label: '物流', selected: false },
  ])
  const [selectValue, setSelectValue] = useState()
  const selectShipmentMode = (value) => {
    setSelectValue(() => value)
    onSelect?.(value)
  }
  return (
    <View className={styles.order_title}>
      <Text>收货方式</Text>
      {shipmentMode.current.map((item) => {
        return <View className={classnames(styles.order_status, (selectValue == item.value) && styles.order_status_selected)} onClick={() => selectShipmentMode(item.value)}>{item.label}</View>
      })}
    </View>
  )
})
