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 { DialogCallback } from '../../model/common/DialogUtil';
16import { Log } from '../../utils/Log';
17import { ColumnSize, ScreenManager } from '../../model/common/ScreenManager';
18import { Constants } from '../../model/common/Constants';
19import data_preferences from '@ohos.data.preferences';
20
21const TAG: string = 'common_RemoveDialog';
22
23@CustomDialog
24export struct RemoveDialog {
25  @StorageLink('isHorizontal') isHorizontal: boolean = ScreenManager.getInstance().isHorizontal();
26  @StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar();
27  @StorageLink('leftBlank') leftBlank: number[] =
28    [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()];
29  @Consume dialogCallback: DialogCallback;
30  @Consume dialogMessage: Resource;
31  controller?: CustomDialogController;
32  @StorageLink('confirmText') confirmText: Resource = $r('app.string.dialog_remove');
33  private isPcDevice: boolean = AppStorage.get<string>('deviceType') === Constants.PC_DEVICE_TYPE;
34
35  build() {
36    Column() {
37      Column() {
38        Text(this.dialogMessage)
39          .fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
40          .fontWeight(FontWeight.Medium)
41          .fontColor($r('sys.color.ohos_id_color_text_primary'))
42          .textAlign(TextAlign.Center)
43
44      }
45      .alignItems(HorizontalAlign.Center)
46      .width('100%')
47      .margin({
48        top: $r('app.float.dialog_content_margin'),
49        bottom: $r('app.float.dialog_button_and_text_margin')
50      })
51
52      Stack({ alignContent: Alignment.Top }) {
53        Row() {
54          Column() {
55            Button() {
56              Text($r('app.string.dialog_cancel'))
57                .fontSize($r('sys.float.ohos_id_text_size_button1'))
58                .fontColor($r('app.color.color_control_highlight'))
59                .fontWeight(FontWeight.Medium)
60                .width('100%')
61                .textAlign(TextAlign.Center)
62            }
63            .key('RemoveDialogCancelButton')
64            .margin({
65              right: $r('app.float.dialog_double_buttons_margin_right')
66            })
67            .backgroundColor(this.isPcDevice ? $r('sys.color.ohos_id_color_button_normal') : $r('app.color.transparent'))
68            .borderRadius($r('sys.float.ohos_id_corner_radius_button'))
69            .height($r('app.float.details_dialog_button_height'))
70            .onClick(() => {
71              Log.debug(TAG, `cancelCallback`);
72              this.controller?.close();
73              this.dialogCallback && this.dialogCallback.cancelCallback();
74            })
75          }.width('50%')
76
77          if (!this.isPcDevice) {
78            Divider()
79              .vertical(true)
80              .color(Constants.DEFAULT_DIVIDER_COLOR)
81              .height(Constants.DEFAULT_DIVIDER_HEIGHT)
82          }
83
84          Column() {
85            Button() {
86              Text(this.confirmText)
87                .fontSize($r('sys.float.ohos_id_text_size_button1'))
88                .fontColor($r('sys.color.ohos_id_color_warning'))
89                .fontWeight(FontWeight.Medium)
90                .width('100%')
91                .textAlign(TextAlign.Center)
92            }
93            .key('RemoveDialogConfirmButton')
94            .margin({
95              left: $r('app.float.dialog_double_buttons_margin_left')
96            })
97            .backgroundColor(this.isPcDevice ? $r('sys.color.ohos_id_color_button_normal') : $r('app.color.transparent'))
98            .borderRadius($r('sys.float.ohos_id_corner_radius_button'))
99            .height($r('app.float.details_dialog_button_height'))
100            .onClick(() => {
101              Log.debug(TAG, `confirmCallback`);
102              this.controller?.close();
103              this.dialogCallback && this.dialogCallback.confirmCallback();
104            })
105          }.width('50%')
106        }
107      }
108      .width('100%')
109      .height($r('app.float.details_dialog_button_area_height'))
110    }
111    .borderRadius($r('sys.float.ohos_id_corner_radius_default_l'))
112    .width(this.isPcDevice ? $r('app.float.pc_dialog_width') : ScreenManager.getInstance()
113                                                                 .getColumnsWidth(ColumnSize.COLUMN_FOUR))
114    .backgroundColor($r('app.color.white'))
115    .margin({
116      right: $r('app.float.dialog_content_margin'),
117      left: $r('app.float.dialog_content_margin'),
118      bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + this.leftBlank[3]
119    })
120    .padding({
121      left: $r('app.float.dialog_double_buttons_padding'),
122      right: $r('app.float.dialog_double_buttons_padding')
123    })
124    .alignItems(HorizontalAlign.Center)
125    .shadow({
126      radius: $r('app.float.dialog_defult_shadow_m_radio'),
127      color: $r('app.color.dialog_defult_shadow_m_color'),
128      offsetX: $r('app.float.dialog_defult_shadow_m_offsetX'),
129      offsetY: $r('app.float.dialog_defult_shadow_m_offsetY')
130    })
131  }
132}
133