import Taro from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import formatPrice from "@/utils/formatPrice";
import SeeDetails from '@/assets/icons/GuideCheck/SeeDetails.png'
import baozan from '@/assets/icons/housemantj/bgood.png'
import CouponCard from '@/components/CouponCard'
import { compressImage } from '@/utils'
import Location from '@/components/Location'
import './style.less'


const CouponMedia = CouponCard.Media
const Action = CouponCard.Action
export default (props) => {
  const { item, cardNavigateTo } = props

  const targetType = item.targetType
  const star = parseFloat(((item.sweetScore + item.environmentScore + item.serviceScore) / 3).toFixed(1));

  const handleDetail = () => {
    targetType == "shop_package" ? Taro.navigateTo({ url: `/pages/details/foodDetails/foodDetails?id=${item.shopId}` })
      : targetType == "tourist" ? Taro.navigateTo({ url: `/pages/details/mjDetails/sceneryDetails?id=${item.targetId}` })
        : Taro.navigateTo({ url: `/pages/details/foodDetails/foodDetails?id=${item.targetId}` })
  }

  const PayAction = <Action.Icon icon={SeeDetails} text='查看详情' onClick={handleDetail} />

  return (

    <View className='View-box-LR'>
      {
        targetType === "shop_package" && (
          <View style={{ margin: '15px 5px' }}>
            <CouponCard action={PayAction}>
              <CouponMedia>
                <CouponMedia.Header
                  cashback={item.cashback}
                  image={compressImage(item.poster)}
                  badge='food'
                />
                <CouponMedia.Body star={star}>
                  <View className='cpn-card-text'>
                    {(item.title).toString().length > 25 ? (item.title).substring(0, 25) + '...' : (item.title)}
                  </View>
                  <View className='cpn-card-text' style={{ marginTop: '10rpx' }}>
                    <Text className='cpn-card-text_mn'>￥{`${(item.actualPrice / 100)?.toFixed(2)}元`}</Text>
                    <Text className='cpn-card-text_rm'>{`门市价${(item.standardPrice / 100)?.toFixed(2)}元`}</Text>
                  </View>
                  <View className='cpn-md-act'>
                    <Location {...item} />
                  </View>
                </CouponMedia.Body>
              </CouponMedia>
            </CouponCard>
          </View>
        )
      }
      {
        targetType !== "shop_package" && (
          <View style={{ margin: '15px 5px' }}>
            <CouponCard action={PayAction}>
              <CouponMedia>
                <CouponMedia.Header
                  image={compressImage(item.poster)}
                  badge={targetType}
                />
                <CouponMedia.Body >
                  <View className='cpn-card-text'>
                    {(item.title).toString().length > 25 ? (item.title).substring(0, 25) + '...' : (item.title)}
                  </View>
                  <View className='cpn-card-text' style={{ marginTop: '10rpx' }}>
                    <Text className='cpn-card-text_mn'>￥{`${formatPrice(item.averagePrice)}元`}</Text>
                  </View>
                  <View className='cpn-md-act'>
                    <Location {...item} />
                    <view className='wdscbaozan'>
                      <image className='title-on' src={baozan} />
                      <text className='title-on-text'>爆赞 {item.likeNum}</text>
                    </view>
                  </View>
                </CouponMedia.Body>
              </CouponMedia>
            </CouponCard>
          </View>
        )
      }
    </View>
  )
}
