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
16var __decorate = this && this.__decorate || function (e, o, t, i) {
17    var n, r = arguments.length, l = r < 3 ? o : null === i ? i = Object.getOwnPropertyDescriptor(o, t) : i;
18    if ('object' === typeof Reflect && 'function' === typeof Reflect.decorate) {
19        l = Reflect.decorate(e, o, t, i);
20    } else {
21        for (let s = e.length - 1; s >= 0; s--) {
22            (n = e[s]) && (l = (r < 3 ? n(l) : r > 3 ? n(o, t, l) : n(o, t)) || l);
23        }
24    }
25    return r > 3 && l && Object.defineProperty(o, t, l), l;
26};
27const photoAccessHelper = requireNapi('file.photoAccessHelper');
28const FILTER_MEDIA_TYPE_ALL = 'FILTER_MEDIA_TYPE_ALL';
29const FILTER_MEDIA_TYPE_IMAGE = 'FILTER_MEDIA_TYPE_IMAGE';
30const FILTER_MEDIA_TYPE_VIDEO = 'FILTER_MEDIA_TYPE_VIDEO';
31
32export class PhotoPickerComponent extends ViewPU {
33    constructor(e, o, t, i = -1, n = void 0) {
34        super(e, t, i);
35        'function' === typeof n && (this.paramsGenerator_ = n);
36        this.pickerOptions = void 0;
37        this.onSelect = void 0;
38        this.onDeselect = void 0;
39        this.onItemClicked = void 0;
40        this.onEnterPhotoBrowser = void 0;
41        this.onExitPhotoBrowser = void 0;
42        this.onPickerControllerReady = void 0;
43        this.onPhotoBrowserChanged = void 0;
44        this.onSelectedItemsDeleted = void 0;
45        this.onExceedMaxSelected = void 0;
46        this.onCurrentAlbumDeleted = void 0;
47        this.onVideoPlayStateChanged = void 0;
48        this.__pickerController = new SynchedPropertyNesedObjectPU(o.pickerController, this, 'pickerController');
49        this.proxy = void 0;
50        this.setInitiallyProvidedValue(o);
51        this.declareWatch('pickerController', this.onChanged);
52    }
53
54    setInitiallyProvidedValue(e) {
55        void 0 !== e.pickerOptions && (this.pickerOptions = e.pickerOptions);
56        void 0 !== e.onSelect && (this.onSelect = e.onSelect);
57        void 0 !== e.onDeselect && (this.onDeselect = e.onDeselect);
58        void 0 !== e.onItemClicked && (this.onItemClicked = e.onItemClicked);
59        void 0 !== e.onEnterPhotoBrowser && (this.onEnterPhotoBrowser = e.onEnterPhotoBrowser);
60        void 0 !== e.onExitPhotoBrowser && (this.onExitPhotoBrowser = e.onExitPhotoBrowser);
61        void 0 !== e.onPhotoBrowserChanged && (this.onPhotoBrowserChanged = e.onPhotoBrowserChanged);
62        void 0 !== e.onPickerControllerReady && (this.onPickerControllerReady = e.onPickerControllerReady);
63        void 0 !== e.onSelectedItemsDeleted && (this.onSelectedItemsDeleted = e.onSelectedItemsDeleted);
64        void 0 !== e.onExceedMaxSelected && (this.onExceedMaxSelected = e.onExceedMaxSelected);
65        void 0 !== e.onCurrentAlbumDeleted && (this.onCurrentAlbumDeleted = e.onCurrentAlbumDeleted);
66        void 0 !== e.onVideoPlayStateChanged && (this.onVideoPlayStateChanged = e.onVideoPlayStateChanged);
67        this.__pickerController.set(e.pickerController);
68        void 0 !== e.proxy && (this.proxy = e.proxy);
69    }
70
71    updateStateVars(e) {
72        this.__pickerController.set(e.pickerController);
73    }
74
75    purgeVariableDependenciesOnElmtId(e) {
76        this.__pickerController.purgeDependencyOnElmtId(e);
77    }
78
79    aboutToBeDeleted() {
80        this.__pickerController.aboutToBeDeleted();
81        SubscriberManager.Get().delete(this.id__());
82        this.aboutToBeDeletedInternal();
83    }
84
85    get pickerController() {
86        return this.__pickerController.get();
87    }
88
89    onChanged() {
90        var e;
91        if (!this.proxy) {
92            return;
93        }
94        let o = null === (e = this.pickerController) || void 0 === e ? void 0 : e.data;
95        if (null == o ? void 0 : o.has('SET_SELECTED_URIS')) {
96            this.proxy.send({ selectUris: null == o ? void 0 : o.get('SET_SELECTED_URIS') });
97            console.info('PhotoPickerComponent onChanged: SET_SELECTED_URIS');
98        } else if (null == o ? void 0 : o.has('SET_ALBUM_URI')) {
99            this.proxy.send({ albumUri: null == o ? void 0 : o.get('SET_ALBUM_URI') });
100            console.info('PhotoPickerComponent onChanged: SET_ALBUM_URI');
101        } else if (null == o ? void 0 : o.has('SET_MAX_SELECT_COUNT')) {
102            this.onSetMaxSelectCount(o);
103        } else if (null == o ? void 0 : o.has('SET_PHOTO_BROWSER_ITEM')) {
104            this.onSetPhotoBrowserItem(o);
105        } else if (null == o ? void 0 : o.has('EXIT_PHOTO_BROWSER')) {
106            this.handleExitPhotoBrowser();
107        } else if (null == o ? void 0 : o.has('SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY')) {
108            this.onSetPhotoBrowserUIElementVisibility(o);
109        } else {
110            console.info('PhotoPickerComponent onChanged: other case');
111        }
112    }
113
114    onSetMaxSelectCount(o) {
115        let e = null == o ? void 0 : o.get('SET_MAX_SELECT_COUNT');
116        let t = null == e ? void 0 : e.data;
117        this.proxy.send({
118            totalCount: null == t ? void 0 : t.get(MaxCountType.TOTAL_MAX_COUNT),
119            photoCount: null == t ? void 0 : t.get(MaxCountType.PHOTO_MAX_COUNT),
120            videoCount: null == t ? void 0 : t.get(MaxCountType.VIDEO_MAX_COUNT)
121        });
122        console.info('PhotoPickerComponent onChanged: SET_MAX_SELECT_COUNT');
123    }
124
125    onSetPhotoBrowserItem(o) {
126        let e = null == o ? void 0 : o.get('SET_PHOTO_BROWSER_ITEM');
127        this.proxy.send({
128            itemUri: null == e ? void 0 : e.uri,
129            photoBrowserRange: null == e ? void 0 : e.photoBrowserRange
130        });
131        console.info('PhotoPickerComponent onChanged: SET_PHOTO_BROWSER_ITEM');
132    }
133
134    handleExitPhotoBrowser() {
135        this.proxy.send({ exitPhotoBrowser: true });
136        console.info('PhotoPickerComponent onChanged: EXIT_PHOTO_BROWSER');
137    }
138
139    onSetPhotoBrowserUIElementVisibility(o) {
140        let e = null == o ? void 0 : o.get('SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY');
141        this.proxy.send({
142            elements: null == e ? void 0 : e.elements,
143            isVisible: null == e ? void 0 : e.isVisible
144        });
145        console.info('PhotoPickerComponent onChanged: SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY');
146    }
147
148    initialRender() {
149        this.observeComponentCreation2(((e, o) => {
150            Row.create();
151            Row.height('100%');
152        }), Row);
153        this.observeComponentCreation2(((e, o) => {
154            Column.create();
155            Column.width('100%');
156        }), Column);
157        this.observeComponentCreation2(((e, o) => {
158            var t, i, n, r, l, s, c, p, a, d, h, E, C, T, m, P, _, b, d;
159            SecurityUIExtensionComponent.create({
160                parameters: {
161                    'ability.want.params.uiExtensionTargetType': 'photoPicker',
162                    uri: 'multipleselect',
163                    targetPage: 'photoPage',
164                    filterMediaType: this.convertMIMETypeToFilterType(null === (t = this.pickerOptions) || void 0 === t ? void 0 : t.MIMEType),
165                    maxSelectNumber: null === (i = this.pickerOptions) || void 0 === i ? void 0 : i.maxSelectNumber,
166                    isPhotoTakingSupported: null === (n = this.pickerOptions) || void 0 === n ? void 0 : n.isPhotoTakingSupported,
167                    isEditSupported: !1,
168                    recommendationOptions: null === (r = this.pickerOptions) || void 0 === r ? void 0 : r.recommendationOptions,
169                    preselectedUri: null === (l = this.pickerOptions) || void 0 === l ? void 0 : l.preselectedUris,
170                    isFromPickerView: !0,
171                    isNeedActionBar: !1,
172                    isNeedSelectBar: !1,
173                    isSearchSupported: null === (s = this.pickerOptions) || void 0 === s ? void 0 : s.isSearchSupported,
174                    checkBoxColor: null === (c = this.pickerOptions) || void 0 === c ? void 0 : c.checkBoxColor,
175                    backgroundColor: null === (p = this.pickerOptions) || void 0 === p ? void 0 : p.backgroundColor,
176                    checkboxTextColor: null === (a = this.pickerOptions) || void 0 === a ? void 0 : a.checkboxTextColor,
177                    photoBrowserBackgroundColorMode: null === (d = this.pickerOptions) || void 0 === d ? void 0 : d.photoBrowserBackgroundColorMode,
178                    isRepeatSelectSupported: null === (h = this.pickerOptions) || void 0 === h ? void 0 : h.isRepeatSelectSupported,
179                    maxSelectedReminderMode: null === (E = this.pickerOptions) || void 0 === E ? void 0 : E.maxSelectedReminderMode,
180                    orientation: null === (C = this.pickerOptions) || void 0 === C ? void 0 : C.orientation,
181                    selectMode: null === (T = this.pickerOptions) || void 0 === T ? void 0 : T.selectMode,
182                    maxPhotoSelectNumber: null === (m = this.pickerOptions) || void 0 === m ? void 0 : m.maxPhotoSelectNumber,
183                    maxVideoSelectNumber: null === (P = this.pickerOptions) || void 0 === P ? void 0 : P.maxVideoSelectNumber,
184                    isOnItemClickedSet: !!this.onItemClicked,
185                    isPreviewForSingleSelectionSupported: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.isPreviewForSingleSelectionSupported,
186                    isSlidingSelectionSupported: null === (b = this.pickerOptions) || void 0 === b ? void 0 : b.isSlidingSelectionSupported,
187                    photoBrowserCheckboxPosition: null === (d = this.pickerOptions) || void 0 === d ? void 0 : d.photoBrowserCheckboxPosition,
188                    gridMargin: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.gridMargin,
189                    photoBrowserMargin: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.photoBrowserMargin
190                }
191            });
192            SecurityUIExtensionComponent.height('100%');
193            SecurityUIExtensionComponent.width('100%');
194            SecurityUIExtensionComponent.onRemoteReady((e => {
195                this.proxy = e;
196                console.info('PhotoPickerComponent onRemoteReady');
197            }));
198            SecurityUIExtensionComponent.onReceive((e => {
199                let o = e;
200                this.handleOnReceive(o);
201            }));
202            SecurityUIExtensionComponent.onError((() => {
203                console.info('PhotoPickerComponent onError');
204            }));
205        }), SecurityUIExtensionComponent);
206        Column.pop();
207        Row.pop();
208    }
209
210    handleOnReceive(e) {
211        let o = e.dataType;
212        console.info('PhotoPickerComponent onReceive: dataType = ' + o);
213        if ('selectOrDeselect' === o) {
214            this.handleSelectOrDeselect(e);
215        } else if ('itemClick' === o) {
216            this.handleItemClick(e);
217        } else if ('onPhotoBrowserStateChanged' === o) {
218            this.handleEnterOrExitPhotoBrowser(e);
219        } else if ('remoteReady' === o) {
220            if (this.onPickerControllerReady) {
221                this.onPickerControllerReady();
222                console.info('PhotoPickerComponent onReceive: onPickerControllerReady');
223            }
224        } else if ('onPhotoBrowserChanged' === o) {
225            this.handlePhotoBrowserChange(e);
226        } else if ('onVideoPlayStateChanged' === o) {
227            this.handleVideoPlayStateChanged(e);
228        } else {
229            this.handleOtherOnReceive(e);
230            console.info('PhotoPickerComponent onReceive: other case');
231        }
232        console.info('PhotoPickerComponent onReceive' + JSON.stringify(e));
233    }
234
235    handleOtherOnReceive(e) {
236        let o = e.dataType;
237        if ('exceedMaxSelected' === o) {
238            if (this.onExceedMaxSelected) {
239                this.onExceedMaxSelected(e.maxCountType);
240            }
241        } else if ('selectedItemsDeleted' === o) {
242            if (this.onSelectedItemsDeleted) {
243                this.onSelectedItemsDeleted(e.selectedItemInfos);
244            }
245        } else if ('currentAlbumDeleted' === o) {
246            if (this.onCurrentAlbumDeleted) {
247                this.onCurrentAlbumDeleted();
248            }
249        } else {
250            console.info('PhotoPickerComponent onReceive: other case');
251        }
252    }
253
254    handleSelectOrDeselect(e) {
255        if (e.isSelect) {
256            if (this.onSelect) {
257                this.onSelect(e['select-item-list']);
258                console.info('PhotoPickerComponent onReceive: onSelect');
259            }
260        } else if (this.onDeselect) {
261            this.onDeselect(e['select-item-list']);
262            console.info('PhotoPickerComponent onReceive: onDeselect');
263        }
264    }
265
266    handleItemClick(e) {
267        if (this.onItemClicked) {
268            let o = ClickType.SELECTED;
269            let t = e.clickType;
270            'select' === t ? o = ClickType.SELECTED : 'deselect' === t ? o = ClickType.DESELECTED : console.info('PhotoPickerComponent onReceive: other clickType');
271            let i = new ItemInfo;
272            let n = e.itemType;
273            'thumbnail' === n ? i.itemType = ItemType.THUMBNAIL : 'camera' === n ? i.itemType = ItemType.CAMERA : console.info('PhotoPickerComponent onReceive: other itemType');
274            i.uri = e.uri;
275            i.mimeType = e.mimeType;
276            i.width = e.width;
277            i.height = e.height;
278            i.size = e.size;
279            i.duration = e.duration;
280            let r = this.onItemClicked(i, o);
281            console.info('PhotoPickerComponent onReceive: onItemClicked = ' + o);
282            if (this.proxy) {
283                if ('thumbnail' === n && o === ClickType.SELECTED) {
284                    this.proxy.send({ clickConfirm: i.uri, isConfirm: r });
285                    console.info('PhotoPickerComponent onReceive: click confirm: uri = ' + i.uri + 'isConfirm = ' + r);
286                }
287                if ('camera' === n) {
288                    this.proxy.send({ enterCamera: r });
289                    console.info('PhotoPickerComponent onReceive: enter camera ' + r);
290                }
291            }
292        }
293    }
294
295    handleEnterOrExitPhotoBrowser(e) {
296        let o = e.isEnter;
297        let t = new PhotoBrowserInfo;
298        t.animatorParams = new AnimatorParams;
299        t.animatorParams.duration = e.duration;
300        t.animatorParams.curve = e.curve;
301        o ? this.onEnterPhotoBrowser && this.onEnterPhotoBrowser(t) : this.onExitPhotoBrowser && this.onExitPhotoBrowser(t);
302        console.info('PhotoPickerComponent onReceive: onPhotoBrowserStateChanged = ' + o);
303    }
304
305    handlePhotoBrowserChange(e) {
306        let o = new BaseItemInfo();
307        o.uri = e.uri;
308        if (this.onPhotoBrowserChanged) {
309            this.onPhotoBrowserChanged(o);
310        }
311        console.info('PhotoPickerComponent onReceive: onPhotoBrowserChanged = ' + o.uri);
312    }
313
314    handleVideoPlayStateChanged(e) {
315        if (this.onVideoPlayStateChanged) {
316            this.onVideoPlayStateChanged(e.state);
317            console.info('PhotoPickerComponent onReceive: onVideoPlayStateChanged = ' + JSON.stringify(e));
318        }
319    }
320
321    convertMIMETypeToFilterType(e) {
322        let o;
323        o = e === photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE ?
324            FILTER_MEDIA_TYPE_IMAGE : e === photoAccessHelper.PhotoViewMIMETypes.VIDEO_TYPE ?
325            FILTER_MEDIA_TYPE_VIDEO : FILTER_MEDIA_TYPE_ALL;
326        console.info('PhotoPickerComponent convertMIMETypeToFilterType' + JSON.stringify(o));
327        return o;
328    }
329
330    rerender() {
331        this.updateDirtyElements();
332    }
333}
334let PickerController = class {
335    setData(e, o) {
336        if (o === undefined) {
337            return;
338        }
339        if (e === DataType.SET_SELECTED_URIS) {
340            if (o instanceof Array) {
341                let e = o;
342                if (e) {
343                    this.data = new Map([['SET_SELECTED_URIS', [...e]]]);
344                    console.info('PhotoPickerComponent SET_SELECTED_URIS' + JSON.stringify(e));
345                }
346            }
347        } else if (e === DataType.SET_ALBUM_URI) {
348            let e = o;
349            if (e !== undefined) {
350                this.data = new Map([['SET_ALBUM_URI', e]]);
351                console.info('PhotoPickerComponent SET_ALBUM_URI' + JSON.stringify(e));
352            }
353        } else {
354            console.info('PhotoPickerComponent setData: other case');
355        }
356    }
357
358    setMaxSelected(e) {
359        if (e) {
360            this.data = new Map([['SET_MAX_SELECT_COUNT', e]]);
361            console.info('PhotoPickerComponent SET_MAX_SELECT_COUNT' + JSON.stringify(e));
362        }
363    }
364
365    setPhotoBrowserItem(e, o) {
366        let l = new PhotoBrowserRangeInfo;
367        l.uri = e;
368        let m = o ? o : PhotoBrowserRange.ALL;
369        l.photoBrowserRange = m;
370        this.data = new Map([['SET_PHOTO_BROWSER_ITEM', l]]);
371        console.info('PhotoPickerComponent SET_PHOTO_BROWSER_ITEM ' + JSON.stringify(l));
372    }
373
374    exitPhotoBrowser() {
375        this.data = new Map([['EXIT_PHOTO_BROWSER', true]]);
376        console.info('PhotoPickerComponent EXIT_PHOTO_BROWSER ');
377    }
378
379    setPhotoBrowserUIElementVisibility(e, o) {
380        let m = new PhotoBrowserUIElementVisibility;
381        m.elements = e;
382        m.isVisible = o;
383        this.data = new Map([['SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY', m]]);
384        console.info('PhotoPickerComponent SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY ' + JSON.stringify(m));
385    }
386};
387PickerController = __decorate([Observed], PickerController);
388
389export class PickerOptions extends photoAccessHelper.BaseSelectOptions {
390}
391
392export class BaseItemInfo {
393}
394
395export class ItemInfo extends BaseItemInfo {
396}
397
398export class PhotoBrowserInfo {
399}
400
401export class AnimatorParams {
402}
403
404export class MaxSelected {
405}
406
407class PhotoBrowserRangeInfo {
408}
409
410class PhotoBrowserUIElementVisibility {
411}
412
413export var DataType;
414!function(e) {
415    e[e.SET_SELECTED_URIS = 1] = 'SET_SELECTED_URIS';
416    e[e.SET_ALBUM_URI = 2] = 'SET_ALBUM_URI';
417}(DataType || (DataType = {}));
418
419export var ItemType;
420!function(e) {
421    e[e.THUMBNAIL = 0] = 'THUMBNAIL';
422    e[e.CAMERA = 1] = 'CAMERA';
423}(ItemType || (ItemType = {}));
424
425export var ClickType;
426!function(e) {
427    e[e.SELECTED = 0] = 'SELECTED';
428    e[e.DESELECTED = 1] = 'DESELECTED';
429}(ClickType || (ClickType = {}));
430
431export var PickerOrientation;
432!function(e) {
433    e[e.VERTICAL = 0] = 'VERTICAL';
434    e[e.HORIZONTAL = 1] = 'HORIZONTAL';
435}(PickerOrientation || (PickerOrientation = {}));
436
437export var SelectMode;
438!function(e) {
439    e[e.SINGLE_SELECT = 0] = 'SINGLE_SELECT';
440    e[e.MULTI_SELECT = 1] = 'MULTI_SELECT';
441}(SelectMode || (SelectMode = {}));
442
443export var PickerColorMode;
444!function(e) {
445    e[e.AUTO = 0] = 'AUTO';
446    e[e.LIGHT = 1] = 'LIGHT';
447    e[e.DARK = 2] = 'DARK';
448}(PickerColorMode || (PickerColorMode = {}));
449
450export var ReminderMode;
451!function(e) {
452    e[e.NONE = 0] = 'NONE';
453    e[e.TOAST = 1] = 'TOAST';
454    e[e.MASK = 2] = 'MASK';
455}(ReminderMode || (ReminderMode = {}));
456
457export var MaxCountType;
458!function(e) {
459    e[e.TOTAL_MAX_COUNT = 0] = 'TOTAL_MAX_COUNT';
460    e[e.PHOTO_MAX_COUNT = 1] = 'PHOTO_MAX_COUNT';
461    e[e.VIDEO_MAX_COUNT = 2] = 'VIDEO_MAX_COUNT';
462}(MaxCountType || (MaxCountType = {}));
463
464export var PhotoBrowserRange;
465!function(e) {
466    e[e.ALL = 0] = 'ALL';
467    e[e.SELECTED_ONLY = 1] = 'SELECTED_ONLY';
468}(PhotoBrowserRange || (PhotoBrowserRange = {}));
469
470export var PhotoBrowserUIElement;
471!function(e) {
472    e[e.CHECKBOX = 0] = 'CHECKBOX';
473    e[e.BACK_BUTTON = 1] = 'BACK_BUTTON';
474}(PhotoBrowserUIElement || (PhotoBrowserUIElement = {}));
475
476export var VideoPlayerState;
477!function(e) {
478    e[e.PLAYING = 0] = 'PLAYING';
479    e[e.PAUSED = 1] = 'PAUSED';
480    e[e.STOPPED = 2] = 'STOPPED';
481    e[e.SEEK_START = 3] = 'SEEK_START';
482    e[e.SEEK_FINISH = 4] = 'SEEK_FINISH';
483}(VideoPlayerState || (VideoPlayerState = {}));
484
485export default { PhotoPickerComponent, PickerController, PickerOptions, DataType, BaseItemInfo, ItemInfo, PhotoBrowserInfo, AnimatorParams,
486    MaxSelected, ItemType, ClickType, PickerOrientation, SelectMode, PickerColorMode, ReminderMode, MaxCountType, PhotoBrowserRange, PhotoBrowserUIElement,
487    VideoPlayerState };