//
//  SpeakEleHomeViewCtr.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/3.
//

import UIKit
import SnapKit

class SpeakEleHomeViewCtr: SpeakEleBaseViewCtr {

    @IBOutlet weak var headerBoard: UIView!
    lazy var mainScrollview: UIScrollView = {
        let sView = UIScrollView()
        sView.isUserInteractionEnabled = true
        sView.isScrollEnabled = true
      
        return sView
    }()
    
    lazy var levellb: UILabel = {
        let lLabel = UILabel()
        lLabel.text = "Entry-level"
        lLabel.font = UIFont.montserrat(.regular ,size: 16)
        lLabel.textColor = UIColor.init(with: "#000000", alpha: 0.4)
        return lLabel
    }()
    
    lazy var leftline: UIView = {
       let lineView = UIView()
        lineView.backgroundColor = UIColor.init(with: "#000000", alpha: 0.4)
       return lineView
   }()
    
    lazy var rightline: UIView = {
       let lineV = UIView()
        lineV.backgroundColor = UIColor.init(with: "#000000", alpha: 0.4)
       return lineV
   }()
    
    lazy var topButton: UIButton = {
       let button = UIButton.init(type: .custom)
        button.setImage(UIImage(named: "sp-home-Back-Top"), for: .normal)
       return button
   }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
       makeUI()
        makeLessonUI()
        Print("输出状态栏高度\(statusBarHeight)")
 
    }
    var index = 4
    var lessonIndex = 9
    func makeUI() {
        
        self.view.insertSubview(mainScrollview, belowSubview: headerBoard)
        self.view.addSubview(topButton)
        mainScrollview.addSubview(levellb)
        mainScrollview.addSubview(leftline)
        mainScrollview.addSubview(rightline)
        
        mainScrollview.snp.makeConstraints { make in
            make.top.equalTo(statusBarHeight + 137.0)
            make.left.equalTo(24)
            make.right.equalTo(-24)
            make.bottom.equalTo(-100)
        }
        
        levellb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(24)
        }
        
        leftline.snp.makeConstraints { make in
            make.centerY.equalTo(levellb)
            make.right.equalTo(levellb.snp.left).offset(-8)
            make.left.equalTo(16)
            make.height.equalTo(0.6)
        }
        
        rightline.snp.makeConstraints { make in
            make.left.equalTo(levellb.snp.right).offset(8)
            make.centerY.equalTo(levellb)
            make.right.equalTo(self.view.snp.right).offset(-40)
            make.height.equalTo(0.6)
        }
        
        topButton.snp.makeConstraints { make in
            make.bottom.equalTo(-(tabbarHeight + 26))
            make.right.equalTo(self.view.snp.right).offset(-16)
            make.width.height.equalTo(48)
        }
    }

    func makeLessonUI() {
        let btnW = 96, btnH = 176
        mainScrollview.contentSize = CGSize(width: mainScrollview.bounds.width, height: 1000)
        for num in 0...index {
            let bx =  num % 2 == 0 ? -160 : -20
            let backV = UIImageView(frame: CGRect(x: Int((Dev.screenW))/2 + bx, y: num * 158 + 100, width: 141, height: 162))
            let iname = num % 2 == 0 ? "sp-home-xuxianL" : "sp-home-xuxianR"
            backV.image = UIImage(named: iname)
            mainScrollview.addSubview(backV)
        }
        
        for num in 0...lessonIndex {
            let lview = SpeakEleLessionView()
            lview.setColor(type: num)
            if num == 0 {
                lview.frame = CGRect(x: Int((Dev.screenW))/2-70, y: 55, width: btnW, height: btnH)
            } else if num == 1{
                lview.frame = CGRect(x: Int((Dev.screenW))/2-70, y: 55 + 56 + 96, width: btnW, height: btnH)
            } else if num % 4 == 0{
                lview.frame = CGRect(x: Int((Dev.screenW))/2-195, y: 120 + num * 80, width: btnW, height: btnH)
            } else if num % 2 == 0{
                lview.frame = CGRect(x: Int((Dev.screenW))/2+61, y: 120 + num * 80, width: btnW, height: btnH)
            } else {
                lview.frame = CGRect(x: Int((Dev.screenW))/2-70, y: 120 + num * 80, width: btnW, height: btnH)
            }

            mainScrollview.addSubview(lview)
        }

    }
}
