import { Constants } from '../common/Constants';
import { RouterUrls } from '../common/RouterUrls';
import { LengthMetrics } from '@kit.ArkUI';

@CustomDialog
export struct PrivacyPolicyDialog {
  controller: CustomDialogController;
  cancel: () => void = () => {
  }
  confirm: () => void = () => {
  }

  build() {
    Stack({alignContent: Alignment.Top}) {
      Image($r('app.media.ic_tip_dialog_top_bg')).width('100%').aspectRatio(2.72)

      Column() {
        Text('欢迎使用')
          .fontColor($r('app.color.color_212226'))
          .fontSize(24)
          .fontFamily('ysbth')
          .margin({ top: 20 })

        Text() {
          Span('请你务必审慎阅读、充分理解')
          Span('《服务协议》')
            .fontColor($r("app.color.color_466afd"))
            .onClick(() => {
              this.getUIContext().getRouter().pushUrl({
                url: RouterUrls.WEB_PAGE, params: {
                  title: '用户协议',
                  url: Constants.USER_AGREEMENT
                }
              })
            })
          Span('和')
          Span('《隐私政策》')
            .fontColor($r("app.color.color_466afd"))
            .onClick(() => {
              this.getUIContext().getRouter().pushUrl({
                url: RouterUrls.WEB_PAGE, params: {
                  title: '隐私政策',
                  url: Constants.PRIVACY_POLICY
                }
              })
            })
          Span('各条款，包括但不限于:为了更好的向你提供服务，我们需要访问你的相册、位置信息等。你可阅读')
          Span('《隐私政策》')
            .fontColor($r("app.color.color_466afd"))
            .onClick(() => {
              this.getUIContext().getRouter().pushUrl({
                url: RouterUrls.WEB_PAGE, params: {
                  title: '隐私政策',
                  url: Constants.PRIVACY_POLICY
                }
              })
            })
          Span('了解详细信息。如果你同意，请点击下面同意按钮开始接受我们的服务。')
        }
        .fontColor($r('app.color.color_727686'))
        .fontSize(14)
        .lineSpacing(LengthMetrics.px(20))
        .margin({ top: 10, left: 20, right: 20 })

        Row(){
          Button('拒绝', { type: ButtonType.Capsule, stateEffect: true })
            .width(110)
            .height(40)
            .fontColor($r('app.color.color_80859B'))
            .fontSize(16)
            .backgroundColor($r("app.color.color_f1f2f6"))
            .margin({left: 20})
            .onClick(() => {
              this.controller.close();
              if (this.cancel) {
                this.cancel();
              }
            })
          Blank().layoutWeight(1)
          Button('同意', { type: ButtonType.Capsule, stateEffect: true })
            .width(110)
            .height(40)
            .fontColor(Color.White)
            .fontSize(16)
            .backgroundColor($r("app.color.color_466afd"))
            .margin({right: 20})
            .onClick(() => {
              this.controller.close();
              if (this.confirm) {
                this.confirm();
              }
            })
        }
        .margin({ top: 20, bottom: 20 })
      }
    }
    .borderRadius(20)
    .backgroundColor(Color.White)
  }
}