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
20const photoAccessHelper = requireNapi('file.photoAccessHelper');
21const BaseItemInfo = requireNapi('file.PhotoPickerComponent').BaseItemInfo;
22
23const FILTER_MEDIA_TYPE_ALL = 'FILTER_MEDIA_TYPE_ALL';
24const FILTER_MEDIA_TYPE_IMAGE = 'FILTER_MEDIA_TYPE_IMAGE';
25const FILTER_MEDIA_TYPE_VIDEO = 'FILTER_MEDIA_TYPE_VIDEO';
26
27export class RecentPhotoComponent extends ViewPU {
28    constructor(j3, k3, l3, m3 = -1, n3 = undefined, o3) {
29        super(j3, l3, m3, o3);
30        if (typeof n3 === 'function') {
31            this.paramsGenerator_ = n3;
32        }
33        this.recentPhotoOptions = undefined;
34        this.onRecentPhotoCheckResult = undefined;
35        this.onRecentPhotoClick = undefined;
36        this.onRecentPhotoCheckInfo = undefined;
37        this.setInitiallyProvidedValue(k3);
38        this.finalizeConstruction();
39    }
40    setInitiallyProvidedValue(i3) {
41        if (i3.recentPhotoOptions !== undefined) {
42            this.recentPhotoOptions = i3.recentPhotoOptions;
43        }
44        if (i3.onRecentPhotoCheckResult !== undefined) {
45            this.onRecentPhotoCheckResult = i3.onRecentPhotoCheckResult;
46        }
47        if (i3.onRecentPhotoClick !== undefined) {
48            this.onRecentPhotoClick = i3.onRecentPhotoClick;
49        }
50        if (i3.onRecentPhotoCheckInfo !== undefined) {
51            this.onRecentPhotoCheckInfo = i3.onRecentPhotoCheckInfo;
52        }
53    }
54    updateStateVars(h3) {
55    }
56    purgeVariableDependenciesOnElmtId(g3) {
57    }
58    aboutToBeDeleted() {
59        SubscriberManager.Get().delete(this.id__());
60        this.aboutToBeDeletedInternal();
61    }
62    initialRender() {
63        this.observeComponentCreation2((e3, f3) => {
64            Row.create();
65            Row.height('100%');
66        }, Row);
67        this.observeComponentCreation2((c3, d3) => {
68            Column.create();
69            Column.width('100%');
70        }, Column);
71        this.observeComponentCreation2((v2, w2) => {
72            SecurityUIExtensionComponent.create({
73                bundleName: 'com.huawei.hmos.photos',
74                abilityName: 'RecentUIExtensionAbility',
75                parameters: {
76                    'ability.want.params.uiExtensionType': 'recentPhoto',
77                    filterMediaType: this.convertMIMETypeToFilterType(this.recentPhotoOptions?.MIMEType),
78                    period: this.recentPhotoOptions?.period,
79                    photoSource: this.recentPhotoOptions?.photoSource,
80                    isFromPickerView: true,
81                    isRecentPhotoCheckResultSet: this.onRecentPhotoCheckResult ? true : false
82                }
83            });
84            SecurityUIExtensionComponent.height('100%');
85            SecurityUIExtensionComponent.width('100%');
86            SecurityUIExtensionComponent.onRemoteReady(() => {
87                console.info('RecentPhotoComponent onRemoteReady');
88            });
89            SecurityUIExtensionComponent.onReceive((a3) => {
90                let b3 = a3;
91                this.handleOnReceive(b3);
92            });
93            SecurityUIExtensionComponent.onError(() => {
94                console.info('RecentPhotoComponent onError');
95            });
96        }, SecurityUIExtensionComponent);
97        Column.pop();
98        Row.pop();
99    }
100    handleOnReceive(p2) {
101        console.info('RecentPhotoComponent OnReceive:' + JSON.stringify(p2));
102        let q2 = p2.dataType;
103        if (q2 === 'checkResult') {
104            if (this.onRecentPhotoCheckResult) {
105                this.onRecentPhotoCheckResult(p2.isExist);
106            }
107        }
108        else if (q2 === 'select') {
109            if (this.onRecentPhotoClick) {
110                let r2 = new BaseItemInfo();
111                r2.uri = p2.uri;
112                r2.mimeType = p2.mimeType;
113                r2.width = p2.width;
114                r2.height = p2.height;
115                r2.size = p2.size;
116                r2.duration = p2.duration;
117                this.onRecentPhotoClick(r2);
118            }
119            else {
120                console.warn('RecentPhotoComponent onReceive data type is invalid.');
121            }
122        }
123        else if (q2 === 'checkInfo') {
124            if (this.onRecentPhotoCheckInfo) {
125                let s2 = new RecentPhotoInfo();
126                s2.identifier = p2.identifier;
127                s2.dateTaken = p2.dateTaken;
128                this.onRecentPhotoCheckInfo(p2.isExist, s2);
129            }
130        }
131    }
132    convertMIMETypeToFilterType(n2) {
133        let o2;
134        if (n2 === photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE) {
135            o2 = FILTER_MEDIA_TYPE_IMAGE;
136        }
137        else if (n2 === photoAccessHelper.PhotoViewMIMETypes.VIDEO_TYPE) {
138            o2 = FILTER_MEDIA_TYPE_VIDEO;
139        }
140        else {
141            o2 = FILTER_MEDIA_TYPE_ALL;
142        }
143        console.info('RecentPhotoComponent convertMIMETypeToFilterType : ' + JSON.stringify(o2));
144        return o2;
145    }
146    rerender() {
147        this.updateDirtyElements();
148    }
149}
150
151export class RecentPhotoOptions {
152}
153
154export class RecentPhotoInfo {
155}
156
157export let PhotoSource;
158(function (m2) {
159    m2[m2.ALL = 0] = 'ALL';
160    m2[m2.CAMERA = 1] = 'CAMERA';
161    m2[m2.SCREENSHOT = 2] = 'SCREENSHOT';
162})(PhotoSource || (PhotoSource = {}));
163
164export default { RecentPhotoComponent, RecentPhotoOptions, PhotoSource, RecentPhotoInfo };
165