import AppConstants from "../../app/AppConstant";
import { common } from "@kit.AbilityKit";

@Component
export struct WebAppErrorDialog {
  @State message: string = "";
  @State ywry: string = "";
  @State ywryPhone: string = "";

  build() {
    Column() {
      Text(this.message)
        .fontColor($r('app.color.colorGrey8'))
        .fontSize($r('app.float.text_size_14'))

      Row() {
        Text(this.ywry)
          .fontColor($r('app.color.colorGrey8'))
          .fontSize($r('app.float.text_size_14'))
        Text(this.ywryPhone)
          .fontColor($r('app.color.bull'))
          .fontSize($r('app.float.text_size_14'))
          .copyOption(CopyOptions.LocalDevice)
          .decoration({
            type: TextDecorationType.Underline,
            color: Color.Blue,
            style: TextDecorationStyle.SOLID
          })
          .onClick(()=>{
            this.callPhone(this.ywryPhone)
          })
      }
      .alignItems(VerticalAlign.Center)
      .justifyContent(FlexAlign.Center)
      .height($r('app.float.default_38'))
      .width(AppConstants.PERCENTAGE_MAX)

    }
    .alignItems(HorizontalAlign.Center)
    .width(AppConstants.PERCENTAGE_MAX)
  }

  callPhone(phone:string){
    let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
    // 构造拨号参数
    let want:Want = {
      action: "ohos.intent.action.DIAL",
      parameters: {
        "uri": "tel:" + phone // 必须符合tel:协议格式
      }
    };

    try {
      context.startAbility(want).then(() => {
        console.info("成功跳转拨号界面");
      }).catch((err:Error) => {
        console.error("跳转失败：" + JSON.stringify(err));
      });
    } catch (error) {
      console.error("启动异常：" + JSON.stringify(error));
    }
  }
}