1/**
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { StyleConstants } from '../constants/StyleConstants';
17import { LayoutViewModel } from '../viewmodel/LayoutViewModel';
18
19@CustomDialog
20export struct RemoveFormDialog {
21  @StorageLink('isPad') isPad: boolean = false;
22  @StorageLink('NavigationBarStatusValue') navigationBarStatusValue: boolean = false;
23  mRemoveFormDialogWidth: string = '';
24  controller?: CustomDialogController;
25  cancel: () => void = () => {
26  };
27  confirm: () => void = () => {
28  };
29  dialogName: string = '';
30  private mLayoutViewModel?: LayoutViewModel;
31
32  private async updateScreenSize() {
33    if (this.mLayoutViewModel?.getCommonDialogWidth()) {
34      this.mRemoveFormDialogWidth = this.mLayoutViewModel?.getCommonDialogWidth();
35    }
36  }
37
38  aboutToAppear(): void {
39    this.mLayoutViewModel = LayoutViewModel.getInstance();
40    this.updateScreenSize();
41  }
42
43  aboutToDisappear(): void {
44  }
45
46  build() {
47    Flex({ direction: FlexDirection.Column, justifyContent: this.isPad ? FlexAlign.Center : FlexAlign.End }) {
48        Column() {
49          Row() {
50            Text(this.dialogName)
51              .width(StyleConstants.PERCENTAGE_70)
52              .fontSize(StyleConstants.DEFAULT_FORM_FONT_CONTENT_SIZE)
53              .fontWeight(StyleConstants.DEFAULT_FORM_FONT_TITLE_WEIGHT)
54          }
55          .alignItems(VerticalAlign.Center)
56          .margin({ top: StyleConstants.DEFAULT_20 })
57
58          Row() {
59            Text($r('app.string.remove_form_dialog_content'))
60              .width(StyleConstants.PERCENTAGE_70)
61              .fontSize(StyleConstants.DEFAULT_FORM_FONT_TITLE_SIZE)
62              .fontWeight(StyleConstants.DEFAULT_FORM_FONT_CONTENT_WEIGHT)
63          }
64          .alignItems(VerticalAlign.Center)
65          .margin({ top: StyleConstants.DEFAULT_20 })
66
67          Flex({ justifyContent: FlexAlign.SpaceEvenly }) {
68            Button() {
69              Text($r('app.string.cancel'))
70                .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
71                .fontColor(StyleConstants.BUTTON_FONT_COLOR)
72            }
73            .backgroundColor(StyleConstants.DEFAULT_BG_COLOR)
74            .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
75            .width(StyleConstants.DEFAULT_BUTTON_WIDTH)
76            .onClick(() => {
77              this.controller?.close();
78              this.cancel()
79            })
80
81            Divider()
82              .vertical(true)
83              .color(StyleConstants.DEFAULT_DIVIDER_COLOR)
84              .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
85
86            Button() {
87              Text($r('app.string.delete_form'))
88                .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
89                .fontColor(StyleConstants.DEFAULT_COLOR_ERROR)
90            }
91            .backgroundColor(StyleConstants.DEFAULT_BG_COLOR)
92            .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
93            .width(StyleConstants.DEFAULT_BUTTON_WIDTH)
94            .onClick(() => {
95              this.controller?.close();
96              this.confirm()
97            })
98          }
99        }
100        .backgroundColor($r('app.color.default_dialog_background'))
101        .backgroundBlurStyle(BlurStyle.Regular)
102        .padding({
103          bottom: StyleConstants.DEFAULT_DIALOG_BOTTOM_MARGIN
104        })
105        .border({
106          radius: StyleConstants.DEFAULT_DIALOG_RADIUS
107        })
108        .width(this.mRemoveFormDialogWidth)
109      }
110    .margin({ bottom: this.navigationBarStatusValue ? StyleConstants.DEFAULT_12 : StyleConstants.DEFAULT_40 })
111    .padding({ left: StyleConstants.DEFAULT_12, right: StyleConstants.DEFAULT_12 })
112  }
113}