//
//  YHDavidTestViewController.swift
//  galaxy
//
//  Created by davidhuangA on 2024/1/10.
//  Copyright © 2024 www.davidhuang.com. All rights reserved.
//

import UIKit

class YHDavidTestViewController: YHBaseViewController {
    lazy var items = {
        return [AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配，专属方案获批率更高")]
    }()
    
    lazy var collectView = {
        // 设置布局方向
        let flowLayout = UICollectionViewFlowLayout()
        let margin = 20.0
        let gap = 20.0
        let itemWidth = floor((KScreenWidth-2*margin-gap)/2.0)
        flowLayout.itemSize = CGSize(width: itemWidth, height: 306.0)
        flowLayout.minimumInteritemSpacing = 20.0
        flowLayout.minimumLineSpacing = 20.0
        flowLayout.scrollDirection = .vertical
        
        let collectinoView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
        collectinoView.contentInset = UIEdgeInsets(top: 0, left: margin, bottom: 0, right: margin)
        collectinoView.backgroundColor = UIColor.white
        collectinoView.register(YHAboutUsAdvantageCell.self, forCellWithReuseIdentifier:YHAboutUsAdvantageCell.cellReuseIdentifier)
        collectinoView.register(YHDavidTestCollectionViewCell.self, forCellWithReuseIdentifier:YHDavidTestCollectionViewCell.cellReuseIdentifier)
        collectinoView.delegate = self
        collectinoView.dataSource = self
        return collectinoView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
}

extension YHDavidTestViewController {
    
    func setupUI() {
        gk_navTitle = "David的测试UI"
        view.backgroundColor = .white
        view.addSubview(collectView)
        
        collectView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalToSuperview().offset(k_Height_NavigationtBarAndStatuBar)
        }
    }
}



extension YHDavidTestViewController: UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return items.count
    }
        
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHDavidTestCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHDavidTestCollectionViewCell
        return cell

    }
        
    private func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        print("index is \(indexPath.row)")
    }
}
