1/*
2 * Copyright (c) 2024 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
16if (!("finalizeConstruction" in ViewPU.prototype)) {
17    Reflect.set(ViewPU.prototype, "finalizeConstruction", () => {
18    });
19}
20
21export var DownloadIconStyle;
22(function (b2) {
23    b2[b2["FULL_FILLED"] = 1] = "FULL_FILLED";
24    b2[b2["LINES"] = 2] = "LINES";
25})(DownloadIconStyle || (DownloadIconStyle = {}));
26
27export var DownloadDescription;
28(function (a2) {
29    a2[a2["DOWNLOAD"] = 1] = "DOWNLOAD";
30    a2[a2["DOWNLOAD_FILE"] = 2] = "DOWNLOAD_FILE";
31    a2[a2["SAVE"] = 3] = "SAVE";
32    a2[a2["SAVE_IMAGE"] = 4] = "SAVE_IMAGE";
33    a2[a2["SAVE_FILE"] = 5] = "SAVE_FILE";
34    a2[a2["DOWNLOAD_AND_SHARE"] = 6] = "DOWNLOAD_AND_SHARE";
35    a2[a2["RECEIVE"] = 7] = "RECEIVE";
36    a2[a2["CONTINUE_TO_RECEIVE"] = 8] = "CONTINUE_TO_RECEIVE";
37})(DownloadDescription || (DownloadDescription = {}));
38
39export var DownloadLayoutDirection;
40(function (z1) {
41    z1[z1["HORIZONTAL"] = 0] = "HORIZONTAL";
42    z1[z1["VERTICAL"] = 1] = "VERTICAL";
43})(DownloadLayoutDirection || (DownloadLayoutDirection = {}));
44const downloadDescriptionResourceMap = new Map([
45    [DownloadDescription.DOWNLOAD, {
46        "id": -1,
47        "type": 10003,
48        params: ['sys.string.ohos_id_text_save_button_description_download'],
49        "bundleName": "__harDefaultBundleName__",
50        "moduleName": "__harDefaultModuleName__"
51    }],
52    [DownloadDescription.DOWNLOAD_FILE, {
53        "id": -1,
54        "type": 10003,
55        params: ['sys.string.ohos_id_text_save_button_description_download_file'],
56        "bundleName": "__harDefaultBundleName__",
57        "moduleName": "__harDefaultModuleName__"
58    }],
59    [DownloadDescription.SAVE, {
60        "id": -1,
61        "type": 10003,
62        params: ['sys.string.ohos_id_text_save_button_description_save'],
63        "bundleName": "__harDefaultBundleName__",
64        "moduleName": "__harDefaultModuleName__"
65    }],
66    [DownloadDescription.SAVE_IMAGE, {
67        "id": -1,
68        "type": 10003,
69        params: ['sys.string.ohos_id_text_save_button_description_save_image'],
70        "bundleName": "__harDefaultBundleName__",
71        "moduleName": "__harDefaultModuleName__"
72    }],
73    [DownloadDescription.SAVE_FILE, {
74        "id": -1,
75        "type": 10003,
76        params: ['sys.string.ohos_id_text_save_button_description_save_file'],
77        "bundleName": "__harDefaultBundleName__",
78        "moduleName": "__harDefaultModuleName__"
79    }],
80    [DownloadDescription.DOWNLOAD_AND_SHARE, {
81        "id": -1,
82        "type": 10003,
83        params: ['sys.string.ohos_id_text_save_button_description_download_and_share'],
84        "bundleName": "__harDefaultBundleName__",
85        "moduleName": "__harDefaultModuleName__"
86    }],
87    [DownloadDescription.RECEIVE, {
88        "id": -1,
89        "type": 10003,
90        params: ['sys.string.ohos_id_text_save_button_description_receive'],
91        "bundleName": "__harDefaultBundleName__",
92        "moduleName": "__harDefaultModuleName__"
93    }],
94    [DownloadDescription.CONTINUE_TO_RECEIVE, {
95        "id": -1,
96        "type": 10003,
97        params: ['sys.string.ohos_id_text_save_button_description_continue_to_receive'],
98        "bundleName": "__harDefaultBundleName__",
99        "moduleName": "__harDefaultModuleName__"
100    }]
101]);
102const MARGIN_DEFAULT = '0vp';
103
104export class DownloadFileButton extends ViewPU {
105    constructor(t1, u1, v1, w1 = -1, x1 = undefined, y1) {
106        super(t1, v1, w1, y1);
107        if (typeof x1 === "function") {
108            this.paramsGenerator_ = x1;
109        }
110        this.__contentOptions = new ObservedPropertyObjectPU({
111            icon: DownloadIconStyle.FULL_FILLED,
112            text: DownloadDescription.DOWNLOAD
113        }, this, "contentOptions");
114        this.__styleOptions = new ObservedPropertyObjectPU({
115            iconSize: '16vp',
116            layoutDirection: DownloadLayoutDirection.HORIZONTAL,
117            fontSize: '16fp',
118            fontStyle: FontStyle.Normal,
119            fontWeight: FontWeight.Medium,
120            fontFamily: 'HarmonyOS Sans',
121            fontColor: '#ffffffff',
122            iconColor: '#ffffffff',
123            textIconSpace: '4vp'
124        }, this, "styleOptions");
125        this.setInitiallyProvidedValue(u1);
126        this.finalizeConstruction();
127    }
128
129    setInitiallyProvidedValue(s1) {
130        if (s1.contentOptions !== undefined) {
131            this.contentOptions = s1.contentOptions;
132        }
133        if (s1.styleOptions !== undefined) {
134            this.styleOptions = s1.styleOptions;
135        }
136    }
137
138    updateStateVars(r1) {
139    }
140
141    purgeVariableDependenciesOnElmtId(q1) {
142        this.__contentOptions.purgeDependencyOnElmtId(q1);
143        this.__styleOptions.purgeDependencyOnElmtId(q1);
144    }
145
146    aboutToBeDeleted() {
147        this.__contentOptions.aboutToBeDeleted();
148        this.__styleOptions.aboutToBeDeleted();
149        SubscriberManager.Get().delete(this.id__());
150        this.aboutToBeDeletedInternal();
151    }
152
153    get contentOptions() {
154        return this.__contentOptions.get();
155    }
156
157    set contentOptions(p1) {
158        this.__contentOptions.set(p1);
159    }
160
161    get styleOptions() {
162        return this.__styleOptions.get();
163    }
164
165    set styleOptions(o1) {
166        this.__styleOptions.set(o1);
167    }
168
169    getTextContent(n1) {
170        return downloadDescriptionResourceMap.get(n1);
171    }
172
173    downloadImage(j1 = null) {
174        this.observeComponentCreation2((l1, m1) => {
175            Image.create(this.contentOptions.icon === DownloadIconStyle.LINES ? {
176                "id": -1,
177                "type": 20000,
178                params: ['sys.media.ohos_save_button_line'],
179                "bundleName": "__harDefaultBundleName__",
180                "moduleName": "__harDefaultModuleName__"
181            } : {
182                "id": -1,
183                "type": 20000,
184                params: ['sys.media.ohos_save_button_filled'],
185                "bundleName": "__harDefaultBundleName__",
186                "moduleName": "__harDefaultModuleName__"
187            });
188            Image.size({ width: this.styleOptions.iconSize, height: this.styleOptions.iconSize });
189            Image.fillColor(this.styleOptions.iconColor);
190        }, Image);
191    }
192
193    downloadText(f1 = null) {
194        this.observeComponentCreation2((h1, i1) => {
195            Text.create(!this.contentOptions.text || !this.getTextContent(this.contentOptions.text) ? {
196                "id": -1,
197                "type": 10003,
198                params: ['sys.string.ohos_id_text_save_button_description_download'],
199                "bundleName": "__harDefaultBundleName__",
200                "moduleName": "__harDefaultModuleName__"
201            } :
202            this.getTextContent(this.contentOptions.text));
203            Text.fontSize(this.styleOptions.fontSize);
204            Text.fontColor(this.styleOptions.fontColor);
205            Text.fontStyle(this.styleOptions.fontStyle);
206            Text.fontWeight(this.styleOptions.fontWeight);
207            Text.fontFamily(this.styleOptions.fontFamily);
208            Text.margin({
209                top: this.styleOptions.layoutDirection === DownloadLayoutDirection.VERTICAL ?
210                this.styleOptions.textIconSpace :
211                    MARGIN_DEFAULT,
212                left: this.styleOptions.layoutDirection === DownloadLayoutDirection.HORIZONTAL ?
213                this.styleOptions.textIconSpace :
214                    MARGIN_DEFAULT
215            });
216        }, Text);
217        Text.pop();
218    }
219
220    initialRender() {
221        this.observeComponentCreation2((b, c) => {
222            If.create();
223            if (this.styleOptions.layoutDirection === DownloadLayoutDirection.HORIZONTAL) {
224                this.ifElseBranchUpdateFunction(0, () => {
225                    this.observeComponentCreation2((d1, e1) => {
226                        Row.create();
227                    }, Row);
228                    this.observeComponentCreation2((z, a1) => {
229                        If.create();
230                        if (this.contentOptions.icon) {
231                            this.ifElseBranchUpdateFunction(0, () => {
232                                this.downloadImage.bind(this)();
233                            });
234                        } else {
235                            this.ifElseBranchUpdateFunction(1, () => {
236                            });
237                        }
238                    }, If);
239                    If.pop();
240                    this.observeComponentCreation2((v, w) => {
241                        If.create();
242                        if (this.contentOptions.text) {
243                            this.ifElseBranchUpdateFunction(0, () => {
244                                this.downloadText.bind(this)();
245                            });
246                        } else {
247                            this.ifElseBranchUpdateFunction(1, () => {
248                            });
249                        }
250                    }, If);
251                    If.pop();
252                    Row.pop();
253                });
254            } else {
255                this.ifElseBranchUpdateFunction(1, () => {
256                    this.observeComponentCreation2((p, q) => {
257                        Column.create();
258                    }, Column);
259                    this.observeComponentCreation2((l, m) => {
260                        If.create();
261                        if (this.contentOptions.icon) {
262                            this.ifElseBranchUpdateFunction(0, () => {
263                                this.downloadImage.bind(this)();
264                            });
265                        } else {
266                            this.ifElseBranchUpdateFunction(1, () => {
267                            });
268                        }
269                    }, If);
270                    If.pop();
271                    this.observeComponentCreation2((h, i) => {
272                        If.create();
273                        if (this.contentOptions.text) {
274                            this.ifElseBranchUpdateFunction(0, () => {
275                                this.downloadText.bind(this)();
276                            });
277                        } else {
278                            this.ifElseBranchUpdateFunction(1, () => {
279                            });
280                        }
281                    }, If);
282                    If.pop();
283                    Column.pop();
284                });
285            }
286        }, If);
287        If.pop();
288    }
289
290    rerender() {
291        this.updateDirtyElements();
292    }
293}
294
295export default {
296    DownloadIconStyle,
297    DownloadDescription,
298    DownloadLayoutDirection,
299    DownloadFileButton
300}