//
//  DiscoverHeadView.swift

//
//  Created by Leon on 2025/9/8.
//

import JXSegmentedView
import UIKit

class DiscoverHeadView: UIView {
    var banner: DiscoverBanner!
    var leaderboardEntryView: DiscoverHeadLeaderBoardEntryView!
    var heightChangeBlock: ((CGFloat) -> Void)?

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
        setupData()
        setupEvent()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupViews() {
        banner = {
            let v = DiscoverBanner()
            addSubview(v)
            v.snp.makeConstraints { make in
                make.leading.trailing.equalToSuperview()
                make.top.equalToSuperview().offset(UIWindow.statusBarHeight + 24)
            }
            return v
        }()
        
        leaderboardEntryView = {
            let v = DiscoverHeadLeaderBoardEntryView()
            addSubview(v)
            v.snp.makeConstraints { make in
                //make.top.equalToSuperview().offset(UIWindow.statusBarHeight + 24)
                make.top.equalTo(banner.snp.bottom).offset(24)
                make.leading.equalToSuperview().offset(24)
                make.trailing.equalToSuperview().offset(-24)
            }
            return v
        }()
    }

    private func setupData() {
//        #warning("test")
//        leaderboardEntryView.topThreeView.showEmpty(true)
    }

    private func setupEvent() {
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        let maxY = leaderboardEntryView.frame.maxY + 24
        heightChangeBlock?(maxY)
    }
}
