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 { ActionData } from '../actions/Action';
17import { Action } from '../actions/Action';
18
19export type PreviewState = {
20  surfaceId: number,
21  xComponentWidth: number,
22  xComponentHeight: number,
23  isShowPreview: boolean,
24  isShowFlashBlack: boolean,
25}
26
27const initState: PreviewState = {
28  surfaceId: 0,
29  xComponentWidth: 0,
30  xComponentHeight: 0,
31  isShowPreview: false,
32  isShowFlashBlack: false,
33}
34
35export function previewReducer(state = initState, action: ActionData): PreviewState {
36  switch (action.type) {
37    case Action.ACTION_UPDATE_SURFACE_ID:
38      return { ...state, surfaceId: action.data.surfaceId };
39    case Action.ACTION_PREPARE_SURFACE:
40      return { ...state, surfaceId: action.data.surfaceId };
41    case Action.ACTION_CHANGE_X_COMPONENT_SIZE:
42      return { ...state, xComponentWidth: action.data.xComponentWidth, xComponentHeight: action.data.xComponentHeight };
43    case Action.ACTION_UPDATE_SHOW_PREVIEW_FLAG:
44      return { ...state, isShowPreview: action.data.isShowPreview };
45    case Action.ACTION_UPDATE_SHOW_FLASH_BLACK_FLAG:
46      return { ...state, isShowFlashBlack: action.data.isShowFlashBlack };
47    default:
48      return state;
49  }
50}