1/**
2 * Copyright (c) 2022 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 { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil';
17import { DataItemType } from '../../../../../../feature/contact/src/main/ets/contract/DataType';
18import StringFormatUtil from '../../util/StringFormatUtil'
19import { Birthday } from '../../../../../../feature/contact/src/main/ets/contract/Birthday';
20
21@Component
22export default struct DetailInfoList {
23  private dataType: DataItemType;
24  private List: string;
25  private hasArrow: boolean;
26
27  build() {
28    Column() {
29      if (!ArrayUtil.isEmpty(JSON.parse(this.List))) {
30        Divider()
31          .color($r("sys.color.ohos_id_color_list_separator"))
32        List() {
33          ForEach(JSON.parse(this.List), (item, index) => {
34            ListItem() {
35              DetailInfoListItem({
36                title: this.dataType == DataItemType.EVENT ?
37                StringFormatUtil.stringFormatDateResource(item.data,
38                  item?.type == Birthday.TYPE_LUNARBIRTHDAY) : item.data,
39                content: item.labelName,
40                hasArrow: this.hasArrow,
41              });
42            }
43          }, item => JSON.stringify(item))
44        }
45        .divider({ strokeWidth: $r("app.float.id_divide_width"), color: $r("sys.color.ohos_id_color_list_separator") })
46        .scrollBar(BarState.Off)
47        .edgeEffect(EdgeEffect.None)
48      }
49    }
50    .width("100%")
51  }
52}
53
54@Component
55struct DetailInfoListItem {
56  private title: string;
57  private content: string;
58  private hasArrow: boolean;
59
60  build() {
61    Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
62      Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Start }) {
63        Text(this.title)
64          .fontSize($r("sys.float.ohos_id_text_size_body1"))
65          .fontColor($r("sys.color.ohos_id_color_text_primary"))
66          .fontWeight(FontWeight.Medium)
67          .textOverflow({ overflow: TextOverflow.Ellipsis })
68          .maxLines(2)
69        Text(this.content)
70          .fontSize($r("sys.float.ohos_id_text_size_body2"))
71          .fontColor($r("sys.color.ohos_id_color_text_tertiary"))
72          .fontWeight(FontWeight.Regular)
73          .margin({ top: $r("app.float.id_card_margin_sm") })
74      }
75      .flexShrink(1)
76
77      Row() {
78        Image($r('app.media.ic_arrow_right_grey'))
79          .align(Alignment.Center)
80          .width($r("app.float.id_card_image_xs"))
81          .height($r("app.float.id_card_image_small"))
82          .visibility(this.hasArrow ? Visibility.Visible : Visibility.Hidden)
83          .opacity(0.2)
84      }
85      .flexShrink(0)
86    }
87    .width('100%')
88    .height($r("app.float.id_item_height_max"))
89  }
90}