1/*
2 * Copyright (c) 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 */
15
16import type { CameraPlatformCapability } from '../../camera/CameraPlatformCapability';
17import type { ActionData } from '../actions/Action';
18import { Action } from '../actions/Action';
19
20export type CameraInitState = {
21  platformCapability: CameraPlatformCapability | undefined,
22  thumbnail: Resource,
23  resourceUri: string,
24  videoUri: string
25}
26
27const initState: CameraInitState = {
28  platformCapability: undefined,
29  thumbnail: $r('app.media.ic_camera_thumbnail_default_white'),
30  resourceUri: '',
31  videoUri: ''
32}
33
34export function cameraInitReducer(state = initState, action: ActionData): CameraInitState {
35  switch (action.type) {
36    case Action.ACTION_INIT_DONE:
37      return {
38        ...state, platformCapability: action.data.platformCapability
39      };
40    case Action.ACTION_UPDATE_THUMBNAIL:
41      return {
42        ...state, thumbnail: action.data.thumbnail, resourceUri: action.data.resourceUri
43      };
44    case Action.ACTION_LOAD_THUMBNAIL:
45      return {
46        ...state, thumbnail: action.data.thumbnail
47      };
48    case Action.ACTION_UPDATE_VIDEO_URI:
49      return {
50        ...state, videoUri: action.data.videoUri
51      };
52    default:
53      return state;
54  }
55}