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 { SettingManager } from '../../../setting/SettingManager'
17import { Log } from '../../../utils/Log'
18import { SetResolution } from './SetResolution'
19import { SetToggle } from './SetToggle'
20import { BaseData } from '../model/BaseData'
21import { SettingData, SettingGroupItem } from '../model/SettingData'
22
23@Component
24export struct SettingItem {
25  private TAG: string = '[SettingItem]:';
26  @Link settingsList: SettingGroupItem[];
27  @Link closeFlag: Boolean;
28  private item: SettingGroupItem = {};
29  private index: number = 0;
30  private WH_100_100: string = "100%";
31
32  aboutToAppear() {
33    Log.info(`${this.TAG} aboutToAppear start`)
34    Log.info(`${this.TAG} aboutToAppear ${JSON.stringify(this.item.settingChildren)}`)
35    Log.info(`${this.TAG} aboutToAppear end`)
36  }
37
38  build() {
39    Flex({ direction: FlexDirection.Column,
40      alignItems: ItemAlign.Center,
41      justifyContent: FlexAlign.SpaceBetween }) {
42      Column() {
43        Row() {
44          Text(this.item.settingTitle)
45            .margin({ top: $r('app.float.margin_value_20'),
46              left: $r('sys.float.ohos_id_card_margin_start'),
47              bottom: $r('app.float.margin_value_8') })
48            .fontColor($r('app.color.font_color_FFFFFF'))
49            .opacity($r('app.float.opacity_6'))
50            .fontSize($r('app.float.font_14'))
51            .fontWeight(FontWeight.Medium)
52        }
53        .width(this.WH_100_100)
54        .height(this.WH_100_100)
55      }
56      .width(this.WH_100_100)
57      .height(48)
58
59      Column() {
60        List() {
61          ForEach(this.item.settingChildren, (itemValue: SettingData) => {
62            ListItem() {
63              Column() {
64                if (itemValue.selectType === "radio") {
65                  SetResolution({
66                    closeFlag: $closeFlag,
67                    settingsList: $settingsList,
68                    itemValue: itemValue
69                  })
70                }
71                if (itemValue.selectType === "toggle") {
72                  SetToggle({
73                    settingsList: $settingsList,
74                    itemValue: itemValue
75                  })
76                }
77              }
78            }
79          })
80        }
81        .listDirection(Axis.Vertical)
82        .divider({ strokeWidth: 0.5, color: '#33FFFFFF', startMargin: 56, endMargin: 12 })
83        .borderRadius($r('sys.float.ohos_id_corner_radius_card'))
84        .backgroundColor('#202224')
85        .padding({ top: 4, bottom: 4 })
86      }.width(this.WH_100_100)
87    }
88  }
89}