18779efd5Sopenharmony_ci/**
28779efd5Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License.
58779efd5Sopenharmony_ci * You may obtain a copy of the License at
68779efd5Sopenharmony_ci *
78779efd5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88779efd5Sopenharmony_ci *
98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and
138779efd5Sopenharmony_ci * limitations under the License.
148779efd5Sopenharmony_ci */
158779efd5Sopenharmony_ci
168779efd5Sopenharmony_ciimport { HiLog } from '../../../../../../common';
178779efd5Sopenharmony_ci
188779efd5Sopenharmony_ciconst TAG = 'SelectSimIdDialog';
198779efd5Sopenharmony_ci
208779efd5Sopenharmony_ci@CustomDialog
218779efd5Sopenharmony_ciexport struct SelectSimIdDialog {
228779efd5Sopenharmony_ci  @Link builder: SelectDialogBuilder;
238779efd5Sopenharmony_ci  private controller: CustomDialogController;
248779efd5Sopenharmony_ci
258779efd5Sopenharmony_ci  aboutToAppear() {
268779efd5Sopenharmony_ci    HiLog.i(TAG, JSON.stringify(this.builder));
278779efd5Sopenharmony_ci  }
288779efd5Sopenharmony_ci
298779efd5Sopenharmony_ci  build() {
308779efd5Sopenharmony_ci    Column() {
318779efd5Sopenharmony_ci      Text(this.builder.title)
328779efd5Sopenharmony_ci        .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
338779efd5Sopenharmony_ci        .fontColor($r('sys.color.ohos_id_color_text_primary'))
348779efd5Sopenharmony_ci        .fontWeight(FontWeight.Bold)
358779efd5Sopenharmony_ci        .alignSelf(ItemAlign.Center)
368779efd5Sopenharmony_ci        .width('100%')
378779efd5Sopenharmony_ci        .height($r('app.float.id_item_height_mid'))
388779efd5Sopenharmony_ci        .padding({ left: $r('app.float.id_card_margin_xxl'), })
398779efd5Sopenharmony_ci      List() {
408779efd5Sopenharmony_ci        ForEach(this.builder.multiSimCardItems, (item, index) => {
418779efd5Sopenharmony_ci          ListItem() {
428779efd5Sopenharmony_ci            Row() {
438779efd5Sopenharmony_ci              Image(item.img)
448779efd5Sopenharmony_ci                .height($r('app.float.id_card_image_mid'))
458779efd5Sopenharmony_ci                .width($r('app.float.id_card_image_mid'))
468779efd5Sopenharmony_ci                .margin({ right: $r('app.float.id_card_margin_large') })
478779efd5Sopenharmony_ci                .onError((event => {
488779efd5Sopenharmony_ci                  HiLog.e(TAG, 'Sim:' + index + ' Image onError' + JSON.stringify(event))
498779efd5Sopenharmony_ci                }))
508779efd5Sopenharmony_ci              Column() {
518779efd5Sopenharmony_ci                Text(item.name)
528779efd5Sopenharmony_ci                  .fontSize($r('sys.float.ohos_id_text_size_body1'))
538779efd5Sopenharmony_ci                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
548779efd5Sopenharmony_ci                  .fontWeight(FontWeight.Medium)
558779efd5Sopenharmony_ci                Text($r('app.string.choose_sub_recommend'))
568779efd5Sopenharmony_ci                  .fontSize($r('sys.float.ohos_id_text_size_body2'))
578779efd5Sopenharmony_ci                  .fontColor($r('sys.color.ohos_dialog_text_alert_transparent'))
588779efd5Sopenharmony_ci                  .fontWeight(FontWeight.Lighter)
598779efd5Sopenharmony_ci                  .visibility(this.builder.lastSimId == index ? Visibility.Visible : Visibility.None);
608779efd5Sopenharmony_ci              }.alignItems(HorizontalAlign.Start)
618779efd5Sopenharmony_ci            }.width('100%')
628779efd5Sopenharmony_ci            .height($r('app.float.id_item_height_large'))
638779efd5Sopenharmony_ci            .justifyContent(FlexAlign.Start)
648779efd5Sopenharmony_ci            .padding({ left: $r('app.float.id_card_margin_xxl'), })
658779efd5Sopenharmony_ci          }.onClick(() => {
668779efd5Sopenharmony_ci            this.confirm(index);
678779efd5Sopenharmony_ci          })
688779efd5Sopenharmony_ci        })
698779efd5Sopenharmony_ci      }.divider({
708779efd5Sopenharmony_ci        strokeWidth: 1
718779efd5Sopenharmony_ci      })
728779efd5Sopenharmony_ci      .scrollBar(BarState.Off)
738779efd5Sopenharmony_ci      .edgeEffect(EdgeEffect.None)
748779efd5Sopenharmony_ci
758779efd5Sopenharmony_ci      Text($r('app.string.cancel'))
768779efd5Sopenharmony_ci        .alignSelf(ItemAlign.Center)
778779efd5Sopenharmony_ci        .textAlign(TextAlign.Center)
788779efd5Sopenharmony_ci        .fontWeight(FontWeight.Medium)
798779efd5Sopenharmony_ci        .fontColor(Color.Blue)
808779efd5Sopenharmony_ci        .fontSize($r('sys.float.ohos_id_text_size_body1'))
818779efd5Sopenharmony_ci        .width('100%')
828779efd5Sopenharmony_ci        .height($r('app.float.id_item_height_mid'))
838779efd5Sopenharmony_ci        .onClick(() => {
848779efd5Sopenharmony_ci          this.cancel()
858779efd5Sopenharmony_ci        });
868779efd5Sopenharmony_ci    }.backgroundColor(Color.White)
878779efd5Sopenharmony_ci  }
888779efd5Sopenharmony_ci
898779efd5Sopenharmony_ci  confirm(slotId: number) {
908779efd5Sopenharmony_ci    this.controller.close()
918779efd5Sopenharmony_ci    if (this.builder.callback) {
928779efd5Sopenharmony_ci      this.builder.callback(slotId);
938779efd5Sopenharmony_ci    }
948779efd5Sopenharmony_ci  }
958779efd5Sopenharmony_ci
968779efd5Sopenharmony_ci  cancel() {
978779efd5Sopenharmony_ci    this.controller.close()
988779efd5Sopenharmony_ci  }
998779efd5Sopenharmony_ci}
1008779efd5Sopenharmony_ci
1018779efd5Sopenharmony_ciclass MultiSimCardItems {
1028779efd5Sopenharmony_ci  name: string | Resource;
1038779efd5Sopenharmony_ci  img: Resource;
1048779efd5Sopenharmony_ci}
1058779efd5Sopenharmony_ci
1068779efd5Sopenharmony_ciinterface Controller {
1078779efd5Sopenharmony_ci  close();
1088779efd5Sopenharmony_ci  open();
1098779efd5Sopenharmony_ci}
1108779efd5Sopenharmony_ci
1118779efd5Sopenharmony_ciexport class SelectDialogBuilder {
1128779efd5Sopenharmony_ci  title: string | Resource;
1138779efd5Sopenharmony_ci  multiSimCardItems: Array<MultiSimCardItems>;
1148779efd5Sopenharmony_ci  lastSimId?: number = -1;
1158779efd5Sopenharmony_ci  callback?: (simId: number) => void;
1168779efd5Sopenharmony_ci  controller?: Controller;
1178779efd5Sopenharmony_ci}
118