import { StrUtil } from "@pura/harmony-utils";

export enum PageStatus {
  LOADING,
  NO_DATA,
  GONE,
  ERROR
}

@ComponentV2
export struct EmptyView {
  @Param status: PageStatus = PageStatus.LOADING;
  @Param noDataImage: Resource = $r('app.media.ic_empty_data');
  @Param noDataText: string = '暂无数据';
  @Param noDataBtnText: string = ''
  @Param noDataBtnIcon?: Resource = undefined
  @Param onBtnClick?: () => void = undefined;

  build() {
    Stack() {
      Column() {
        Image(this.noDataImage).width(160).height(160).margin({ top: -50 })
        Text(this.noDataText).fontColor($r('app.color.color_999999')).fontSize(12)
        Button({ type: ButtonType.Capsule, stateEffect: true }) {
          Row() {
            if (this.noDataBtnIcon) {
              Image(this.noDataBtnIcon).width(22).height(22)
            }
            Text(this.noDataBtnText).fontColor(Color.White).fontSize(16).fontWeight(FontWeight.Medium)
          }
        }
        .height(46)
        .backgroundColor($r('app.color.color_466afd'))
        .padding({
          left: 22,
          right: 22
        })
        .margin({ top: 40 })
        .visibility(StrUtil.isNotEmpty(this.noDataBtnText) ? Visibility.Visible : Visibility.Hidden)
        .onClick(() => {
          if (this.onBtnClick) {
            this.onBtnClick();
          }
        })
      }.visibility(this.status === PageStatus.NO_DATA ? Visibility.Visible : Visibility.None)

      Column() {
        LoadingProgress().width(60).height(60).color($r('app.color.color_999999')).margin({ top: -50 })
        Text('正在加载...').fontColor($r('app.color.color_999999')).fontSize(12).margin({ top: 10 })
      }.visibility(this.status === PageStatus.LOADING ? Visibility.Visible : Visibility.None)
    }
    .width('100%')
    .height('100%')
    .visibility(this.status !== PageStatus.GONE ? Visibility.Visible : Visibility.None)
  }
}