// @Preview
import {ICallBack } from '../base/model/NetHandler';
export type ICallBack=()=>void;

/*
//例子
* 必须声明全局变量
* controller?: CustomDialogController
* 单按钮通过判断按钮title显示
* 左右按钮回调方法 可选
 this.controller = new CustomDialogController({
          builder: BusAlert({
            leftBtnTitle:'shishi',
            rightBtnTitle:'haode',
            leftAction:()=>{
              console.log('左边方法')
            },
            rightAction:()=>{
              console.log('右边方法')
            },
            title:'测试',
            content:'我就试试'
          }),
          // autoCancel: true, // 允许点击蒙层关闭弹窗
          customStyle: true, // 使用自定义样式
          alignment: DialogAlignment.Center
        })
        this.controller.open()
 * */
@Preview
@CustomDialog
export struct BusAlert {
  @Prop title: string = '';
  @Prop content: string = '';
  @Prop leftBtnTitle: string = '';
  @Prop rightBtnTitle: string = '';
  leftAction?:ICallBack
  rightAction?:ICallBack
  controller: CustomDialogController

  build() {
    Stack() {
      Column() {
        Text(this.title)
          .fontSize(16)
          .fontWeight(FontWeight.Medium)
          .margin({ top: 3 })
        Text(this.content)
          .fontSize(14)
          .margin({ top: 24 })

        Row({ space: 16 }) {
          if (this.leftBtnTitle) {
            Text(this.leftBtnTitle)
              .height(40)
                // .width(115)
              .layoutWeight(1)
              .textAlign(TextAlign.Center)
              .fontSize(15)
              .fontColor($r('app.color.font3474ee'))
              .borderRadius(20)
              .borderWidth(1)
              .borderColor($r('app.color.font3474ee'))
              .onClick(() => {
                this.controller.close(); // 关闭弹窗
                if (this.leftAction) {
                  this.leftAction()
                }
              })
          }
          if (this.rightBtnTitle) {
            Text(this.rightBtnTitle)
              .textAlign(TextAlign.Center)
              .fontSize(15)
              .fontColor(Color.White)
              .height(40)
              .layoutWeight(1)
              .backgroundColor($r('app.color.font3474ee'))
              .borderRadius(20)
              .onClick(() => {
                this.controller.close(); // 关闭弹窗
                if (this.rightAction) {
                  this.rightAction()
                }
              })
          }
        }
        .height(40)
        .width('100%')
        .margin({
          top: 35,
          bottom: 18
        })
      }
      .padding({
        top:12,
        left: 19,
        right: 19
      })
      .backgroundColor(Color.White)
      .borderRadius(8)
      .width(280)
    }
    // .margin({left: 40, right: 40})
    // .width("100%")
  }
}