import { NumberUtil, StrUtil } from "@pura/harmony-utils"
import { VipMealEntity } from "../entity/VipMealEntity"

@ComponentV2
export struct DiamondItemView {
  @Param goodInfo?: VipMealEntity = undefined

  build() {
    RelativeContainer() {
      Row() {
        Image(StrUtil.isNotEmpty(this.goodInfo?.image) ? this.goodInfo?.image : $r('app.media.ic_diamond')).width(24).height(24).id('iv_icon')
        Text() {
          Span('兑换M币 ').fontSize(15).fontWeight(FontWeight.Medium)
          Span(this.goodInfo?.value).fontSize(24).fontColor('#FF4529').fontFamily('ddp500m')
          Span('个').fontSize(12)
        }
        .fontColor($r('app.color.color_1a1a1a'))
        .margin({left: 12})
      }
      .margin({left: 16, top: 16})
      .id('tv_count')

      Text(NumberUtil.toNumber(this.goodInfo?.price) / NumberUtil.toNumber(this.goodInfo?.value) + '元一个M币巨优惠')
        .fontColor($r('app.color.color_666666'))
        .fontSize(12)
        .alignRules({
          left: {anchor: 'tv_count', align: HorizontalAlign.Start},
          top: {anchor: 'tv_count', align: VerticalAlign.Bottom}
        })
        .margin({top: 10})
        .id('tv_desc')

      Text() {
        Span('￥').fontSize(13).fontWeight(FontWeight.Medium)
        Span(this.goodInfo?.price).fontSize(24).fontFamily('ddp500m')
      }
      .fontColor('#FF4529')
      .alignRules({
        top: {anchor: 'tv_desc', align: VerticalAlign.Top},
        right: {anchor: '__container__', align: HorizontalAlign.End},
      })
      .margin({right: 16, top: -5})

      if (StrUtil.isNotEmpty(this.goodInfo?.tips)) {
        Text(this.goodInfo?.tips).fontColor('#9E5C0B').fontSize(13)
          .height(22)
          .textAlign(TextAlign.Center)
          .padding({left: 8, right: 8})
          .linearGradient({
            colors:[['#FFEACA', 0.0], ['#FFD7A6', 1.0]],
            direction: GradientDirection.Right
          })
          .alignRules({
            top: {anchor: '__container__', align: VerticalAlign.Top},
            right: {anchor: '__container__', align: HorizontalAlign.End}
          })
          .borderRadius({bottomLeft: 10 , topRight: 10})
      }
    }
    .width('100%')
    .height(86)
    .borderRadius(10)
    .borderWidth(1)
    .borderColor(this.goodInfo?.checked ? '#FF8C1B' : '#DDDDDD')
    .backgroundColor(this.goodInfo?.checked ? '#FFFAEF' : Color.White)
  }
}