
import { CustomWrapper, Text, View } from '@tarojs/components'
import { memo, useCallback, useEffect, useMemo } from 'react'
import ProductItem from '../productItem'
import Checkbox from '../productCheckbox'
import styles from './index.module.scss'
import MCheckbox from '@/components/checkbox'
import type { ProductType } from '@/context/ContextShop'
import { useCurrenShop } from '@/context/ContextShop'
import { formatHashTag } from '@/common/fotmat'
import type { saleModeType } from '@/common/enum'

interface ParamType {
  productItem: ProductType
}
type IndexType = {
  onSelect?: (val: boolean) => void
  sale_mode: saleModeType
} & ParamType
export default memo((props: ParamType) => {
  const { productItem } = props
  // const { state, dispatch } = useCurrenShop()
  useEffect(() => {
    console.log('productItem66:::', productItem)
  }, [productItem])
  return <Index productItem={productItem} sale_mode={0} />
})

const Index = memo((props: IndexType) => {
  const { productItem, onSelect, sale_mode } = props
  const setSelect = (status) => {
    onSelect?.(status)
  }
  const sale_mode_name = useMemo(() => {
    const data = ['大货', '剪版', '删剪']
    return data[sale_mode]
  }, [sale_mode])
  console.log('productItem22::', productItem)
  return <View className={styles.shop_product}>
    <View className={styles.shop_product_title}>
      <Checkbox productItem={productItem} />
      <View className={styles.title_desc}>
        <View className={styles.model}>
          <Text className={styles.name}>{formatHashTag(productItem?.product_code, productItem?.product_name)}</Text>
          <Text className={styles.label}>{sale_mode_name}</Text>
        </View>
      </View>
    </View>
    {productItem?.color_list?.map(item => <ProductItem key={item.product_color_id} colorItem={item} />)}
  </View>
})
