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 */
15import { CameraId } from '../../setting/settingitem/CameraId';
16
17import { ActionData } from '../actions/Action';
18import { Action } from '../actions/Action';
19
20export type CameraState = {
21  cameraPosition: CameraId,
22  curCameraPosition: CameraId,
23  cameraId: string,
24  curCameraName: string,
25  cameraCount: number,
26  shutterIcon: Resource
27}
28
29const initState: CameraState = {
30  cameraPosition: CameraId.BACK,
31  curCameraPosition: CameraId.BACK,
32  cameraId: '',
33  curCameraName: 'BACK',
34  cameraCount: 0,
35  shutterIcon: $r('app.media.ic_circled_filled')
36}
37
38export function cameraReducer(state = initState, action: ActionData): CameraState {
39  switch (action.type) {
40    case Action.ACTION_SET_CAMERA_POSITION:
41      return { ...state, cameraPosition: action.data.cameraPosition };
42    case Action.ACTION_SWITCH_CAMERA:
43      return { ...state, cameraPosition: action.data.cameraId };
44    case Action.ACTION_UPDATE_CAMERA_POSITION:
45      return { ...state, curCameraPosition: action.data.cameraPosition };
46    case Action.ACTION_UPDATE_SHUTTER_ICON:
47      return { ...state, shutterIcon: action.data.shutterIcon };
48    case Action.ACTION_UPDATE_CAMERA_STATUS:
49      return { ...state };
50    default:
51      return state;
52  }
53}