import { promptAction } from '@kit.ArkUI'

@CustomDialog
export struct PerfactInputSheet {
  controller:CustomDialogController;

  @Prop inputTitle:string = '';
  @Prop inputPlaceholder:string = ''
  @State inputText:string = ''

  // 添加回调函数属性
  private inputCallBack: (input: string,title:string) => void = () => {};

  // 修改构造函数
  constructor(controller: CustomDialogController, inputCallBack: (input: string,title:string) => void) {
    super();
    this.controller = controller;
    this.inputCallBack = inputCallBack;
  }

  build() {
    Column() {
      // 操作按钮区域
      Row() {
        Button('取消')
          .layoutWeight(1)
          .backgroundColor(Color.Transparent)
          .fontColor($r('app.color.main_color'))
          .backgroundColor('#EEEEEE')
          .width('15%')
          .fontSize(15)
          .onClick(() => {
            this.controller.close()
          })

        Text(this.inputTitle)
          .width('65%')
          .fontSize(15)
          .fontColor('#333333')
          .textAlign(TextAlign.Center)

        Button('确定')
          .layoutWeight(1)
          .fontSize(15)
          .backgroundColor(Color.Transparent)
          .fontColor($r('app.color.main_color'))
          .backgroundColor('#EEEEEE')
          .width('15%')
          .onClick(() => {
            if (this.inputText.length <= 0) {
              promptAction.showToast({ message: '输入不能为空', duration: 1000 })
              return;
            }
            this.controller.close()
            this.inputCallBack(this.inputText, this.inputTitle);
          })
      }
      .height(30)

      Row(){
        TextInput({
         placeholder: this.inputPlaceholder
        })
          .height(50)
          .fontColor(Color.Black)
          .backgroundColor(Color.White)
          .onChange((value: string) => {
            this.inputText = value;
          })
      }
      .backgroundColor(Color.White)
    }
    .width('100%')
    .height(100)
    .backgroundColor('#EEEEEE')
  }
}
