/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { InfoItem } from './model/DataSourcePrefetching';
import { PageViewModel } from './model/PageViewModel';
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
import { CommonDataSource } from './model/CommonDataSource';

@Entry
@Component
export struct LazyForEachCount {
  @State hotCommendList:CommonDataSource<InfoItem> = new CommonDataSource<InfoItem>([])
  aboutToAppear(): void {
    this.hotCommendList.addData(this.hotCommendList.totalCount(),PageViewModel.getItems())
  }
  build() {
    Column() {
      List({ space: 16 }) {
        LazyForEach(this.hotCommendList, (item: InfoItem,index) => {
          ListItem() {
            Column({ space: 12 }) {
              ImageKnifeComponent({
                imageKnifeOption:{
                  loadSrc: item.albumUrl,
                  placeholderSrc:$r('app.media.loading')
                }
              }).width(100).height(100)
              Text(`${index}`)
            }.border({ width: 5 , color: '#000000'})
          }
        })
      }
      .cachedCount(30)
      .width('100%')
      .height('100%')
      .margin({ left: 10, right: 10 })
      .layoutWeight(1)
    }
  }
}