1/*
2 * Copyright (c) 2022-2023 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 */
15import Log from '../utils/log';
16
17@CustomDialog
18export default struct ConfirmDialog {
19  private readonly TAG: string = 'ConfirmDialog';
20  private controller?: CustomDialogController;
21  private title: string | Resource = '';
22  private content: string | Resource = '';
23  private confirmText: string | Resource = '';
24  private cancelText: string | Resource = '';
25  private confirmOperation?: () => void;
26  @StorageLink('POP_TYPE_WIDTH') POP_TYPE_WIDTH: number = 0;
27
28  build() {
29    Column() {
30      Flex({ alignItems: ItemAlign.Center }) {
31        Text(this.title)
32          .fontColor($r('sys.color.ohos_id_color_text_primary'))
33          .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
34          .fontWeight(FontWeight.Medium)
35      }
36        .height('64vp')
37        .margin({
38          left: '32vp',
39          right: '32vp',
40        })
41      Text(this.content)
42        .fontColor($r('sys.color.ohos_id_color_text_primary'))
43        .fontSize($r('sys.float.ohos_id_text_size_body1'))
44        .margin({
45          left: '32vp',
46          right: '32vp',
47          bottom: '8vp'
48        })
49      Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) {
50        Text(this.cancelText)
51          .fontColor($r('sys.color.ohos_id_color_emphasize_transparent'))
52          .fontSize($r('sys.float.ohos_id_text_size_button1'))
53          .fontWeight(FontWeight.Medium)
54          .flexGrow(1)
55          .textAlign(TextAlign.Center)
56          .onClick(() => {
57            Log.info(this.TAG, 'click cancel+')
58            if (this.controller !== null && this.controller !== undefined) {
59              this.controller.close()
60            }
61            Log.info(this.TAG, 'click cancel-')
62          })
63        Divider()
64          .vertical(true)
65          .strokeWidth('2vp')
66          .color($r('sys.color.ohos_id_color_list_separator'))
67          .height('24dp')
68          .margin({ left: '4vp', right: '4vp'})
69        Text(this.confirmText)
70          .fontColor($r('sys.color.ohos_id_color_warning'))
71          .fontSize($r('sys.float.ohos_id_text_size_button1'))
72          .fontWeight(FontWeight.Medium)
73          .flexGrow(1)
74          .textAlign(TextAlign.Center)
75          .onClick(() => {
76            Log.info(this.TAG, 'click confirm+')
77            if (this.confirmOperation !== undefined) {
78              this.confirmOperation()
79            }
80            Log.info(this.TAG, 'click confirm-')
81            if (this.controller !== undefined) {
82              this.controller.close()
83            }
84          })
85      }
86      .height('40vp')
87      .margin({
88        left: '16vp',
89        right: '16vp',
90        bottom : '16vp'
91      })
92    }
93    .borderRadius('24vp')
94    .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
95    .alignItems(HorizontalAlign.Start)
96  }
97}