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

@ComponentV2
export struct VipMealItemView {
  @Param entity: VipMealEntity = new VipMealEntity();
  @Param isChecked: boolean = false;
  @Param isGrid: boolean = true;

  build() {
    RelativeContainer() {
      Column() {
        Text(this.entity.goods_name)
          .fontColor(this.isChecked ? Color.White : '#ABABAB')
          .fontSize(this.isChecked ? 15 : 12)
          .fontWeight(this.isChecked ? FontWeight.Medium : FontWeight.Regular)
          .margin({ top: this.isChecked ? 18 : 12 })
        Text() {
          Span('￥').fontSize(this.isChecked ? 12 : 10)
          Span(this.entity.price).fontSize(this.isChecked ? 28: 22)
        }
        .fontColor(this.isChecked ? '#94F2FE' : '#EAEAEA')
        .fontWeight(FontWeight.Medium)
        .margin({ top: this.isChecked ? 10 : 4 })

        Text() {
          Span('￥' + this.entity.origin_price).fontColor(this.isChecked ? $r('app.color.color_30ffffff') : '#6B6B6B').fontSize(this.isChecked ? 13 : 10)
            .decoration({ type: TextDecorationType.LineThrough, color: this.isChecked ? $r('app.color.color_30ffffff') : '#6B6B6B' })
        }
        .margin({ top:this.isChecked ? 5 : 2 })

        Text('立省￥' +
          (NumberUtil.toNumber(this.entity.origin_price) - NumberUtil.toNumber(this.entity.price)))
          .width('100%')
          .height(this.isChecked ? 28 : 22)
          .textAlign(TextAlign.Center)
          .fontColor(this.isChecked ? $r('app.color.color_90ffffff') : $r('app.color.color_80ffffff'))
          .fontSize(this.isChecked ? 12 : 10)
          .backgroundColor(this.isChecked ? '#181331' : '#4B4B53')
          .borderRadius({bottomLeft: this.isChecked ? 10 : 8, bottomRight: this.isChecked ? 10 : 8})
          .margin({ top: 10 })
      }
      .height('auto')
      .linearGradient({
        colors: [[this.isChecked ? '#3F2D67' : Color.Transparent, 0.0], [this.isChecked ? '#202443' : Color.Transparent, 1.0]],
        direction: GradientDirection.Right
      })
      .backgroundColor(this.isChecked ? Color.Transparent : '#2B2B38')
      .borderRadius(this.isChecked ? 10 : 8)
      .borderWidth(1)
      .borderColor(this.isChecked ? '#94F2FE' : Color.Transparent)
      .margin({top: this.isChecked ? 11 : 9})
      .alignRules({
        top: {anchor: '__container__', align: VerticalAlign.Top},
        bottom: {anchor: '__container__', align: VerticalAlign.Bottom},
      })
      .id('layout_content')

      Row() {
        Image($r('app.media.ic_vip_fire_tag')).width(this.isChecked ? 14 : 12).height(this.isChecked ? 14 : 12)
        Text(this.entity.tips).fontColor(Color.White).fontSize(this.isChecked ? 12 : 10).margin({ left: 2 })
      }
      .width('auto')
      .height(this.isChecked ? 22 : 18)
      .padding({left: this.isChecked ? 4 : 2, right: this.isChecked ? 6 : 4})
      .margin({top: this.isChecked ? -11 : -9})
      .borderRadius({
        topLeft: 9,
        topRight: 2,
        bottomLeft: 2,
        bottomRight: 9
      })
      .alignRules({
        top: {anchor: 'layout_content', align: VerticalAlign.Top}
      })
      .backgroundColor('#F94747')
      .visibility(StrUtil.isNotEmpty(this.entity.tips) ? Visibility.Visible : Visibility.None)
    }
    .width(this.isGrid ? 'auto' : this.isChecked ? 125 : 110)
    .height(148)
    .padding({left: this.isChecked ? 0 : 5, right: this.isChecked ? 0 : 5})
    .margin({ left: 6, right: 6 })
  }
}