import { Text, View } from '@tarojs/components'
import classnames from 'classnames'
import { memo, useMemo } from 'react'
import styles from './index.module.scss'
import { AFTER_ORDER_STATUS, REFUND_STATUS_ORDER } from '@/common/enum'

interface Param {
  onLogistics?: (val: 1 | 2) => void // 1 上传物流 2 查看物流
  orderInfo: {
    return_user_name?: string
    return_user_phone?: string
    stage?: number
    sale_mode?: 0 | 1 | 2 // 0 大货 1剪板 2散剪
    type?: number // 申请单退款状态
    return_address?: string
  }
}
export default memo(({ orderInfo, onLogistics }: Param) => {
  const {
    ReturnStageApplying,
    ReturnStageWaitCheck,
    ReturnStageChecked,
    ReturnStageReturned,
    ReturnStageCancel,
    ReturnStageQualityCheckPendingRefund,
    ReturnStageServiceOrderPendingRefund,
    ReturnStageRejected,
  } = AFTER_ORDER_STATUS

  const {
    ReturnApplyOrderTypeAdvanceReceiptRefund, // 预收退款
    ReturnApplyOrderTypeReturnForRefund, // 退货退款
    ReturnApplyOrderTypeSalesRefund, // 销售退款
  } = REFUND_STATUS_ORDER

  // 是否显示地址
  const showAddress = useMemo(() => {
    const after_list = [ReturnStageApplying.value, ReturnStageCancel.value, ReturnStageRejected.value]
    const refurn_list = [ReturnApplyOrderTypeSalesRefund.value, ReturnApplyOrderTypeAdvanceReceiptRefund.value]
    return !after_list.includes(orderInfo?.stage!) && orderInfo?.sale_mode != 1 && !refurn_list.includes(orderInfo?.type!)
  }, [orderInfo])

  // 上传物流
  const upLogistics = useMemo(() => {
    return orderInfo?.stage == ReturnStageWaitCheck.value
  }, [orderInfo])

  return (
    <>
      {showAddress && (
        <View className={styles.address_main}>
          <View className={styles.address_title_tag}>
            <Text className={classnames(styles.miconfont, 'iconfont icon-zhuyi')}></Text>
            请按以下退货地址寄回货物并提供退货物流信息
          </View>
          <View className={styles.order_address}>
            <View className={classnames(styles.order_address_icon, 'iconfont', 'icon-fahuo')}></View>
            <View className={styles.order_address_text_con}>
              <View className={styles.order_address_text_title}>
                <Text className={classnames(styles.address_text, styles.address_text_no)}>{orderInfo?.return_address}</Text>
              </View>
              <View className={styles.order_address_text_name}>
                <Text>谭先生</Text>
                <Text>{orderInfo?.return_user_phone}</Text>
                {(upLogistics && (
                  <View className={styles.updateBtn} onClick={() => onLogistics?.(1)}>
                    上传物流
                  </View>
                )) || (
                  <View className={styles.updateBtn} onClick={() => onLogistics?.(2)}>
                    查看物流
                  </View>
                )}
              </View>
            </View>
          </View>
        </View>
      )}
    </>
  )
})
