import { RouterUrls } from "../common/RouterUrls"
import { DownloadHistoryEntity } from "../entity/DownloadHistoryEntity"
import { ConfigManager } from "../manager/UserConfigManager"

@ComponentV2
export struct DownloadHistoryItemView {
  @Param historyEntity?: DownloadHistoryEntity = undefined

  build() {
    Stack() {
      Row() {
        Column() {
          Row() {
            Text(ConfigManager.getDomainMap()[this.historyEntity?.domain!!] ? ConfigManager.getDomainMap()[this.historyEntity?.domain!!] : '其他')
              .height(16)
              .textAlign(TextAlign.Center)
              .fontColor(this.historyEntity?.getTypeTextColor())
              .fontSize(10)
              .borderRadius(2)
              .backgroundColor(this.historyEntity?.getTypeBgColor())
              .padding({left: 4, right: 4})
            Text(this.historyEntity?.title)
              .fontColor($r('app.color.color_212226'))
              .fontSize(14)
              .maxLines(1)
              .textOverflow({ overflow: TextOverflow.Ellipsis })
              .ellipsisMode(EllipsisMode.END)
              .margin({left: 8})
              .layoutWeight(1)
          }
          Text(this.historyEntity?.description ? this.historyEntity?.description : this.historyEntity?.title)
            .fontColor('#646670')
            .fontSize(12)
            .maxLines(1)
            .textOverflow({ overflow: TextOverflow.Ellipsis })
            .ellipsisMode(EllipsisMode.END)
            .margin({top: 5})

          Row() {
            Text(this.historyEntity?.save_size).fontColor($r('app.color.color_666666')).fontSize(12)
            Text(this.historyEntity?.create_time).fontColor($r('app.color.color_999999')).fontSize(10).margin({left: 10})
          }.margin({top: 8})
        }
        .padding({left: 16, right: 16})
        .alignItems(HorizontalAlign.Start)
        .layoutWeight(1)

        Divider().height(50).strokeWidth(0.5).vertical(true).backgroundColor('#E8E9ED')

        Stack(){
          Image(this.historyEntity?.request ? $r('app.media.ic_download_enable') : $r('app.media.ic_download_disable')).width(26).height(26)
        }
        .padding({left: 16, right: 16})
        .onClick(() => {
          if (this.historyEntity?.request) {
            this.getUIContext().getRouter().pushUrl({url: RouterUrls.TAKE_MATERIAL_PAGE, params: {url: this.historyEntity?.request}})
          }
        })
      }
      .width('100%')
      .padding({ top: 16, bottom: 16 })
      .backgroundColor(Color.White)
      .borderRadius(6)
    }
    .width('100%')
    .padding({ left: 16, right: 16 })
  }
}