//
//  UniversalInstructionsController.swift

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

import UIKit

class UniversalInstructionsController: CLBaseViewController, UIScrollViewDelegate {
    var scrollContainer: LTScrollContainer!
    var titleView: TitleView!
    var descLabel: LineSpaceLabel!

    // -- Config
    var pageTitle: String = ""

    // -- Content:
    var content: String = ""

    override func viewDidLoad() {
        super.viewDidLoad()

        setupViews()

        navigationView.alpha0Title = pageTitle
        titleView.title = pageTitle

        descLabel.text = content
    }

    private func setupViews() {
        scrollContainer = {
            let v = LTScrollContainer()
            view.addSubview(v)
            v.scrollView.delegate = self
            v.snp.makeConstraints { make in
                make.leading.trailing.bottom.equalToSuperview()
                make.top.equalTo(navigationView.snp.bottom)
            }
            return v
        }()

        titleView = {
            let v = TitleView()
            scrollContainer.stack.addArrangedSubview(v)
            v.snp.makeConstraints { make in
                make.leading.trailing.equalToSuperview()
            }
            return v
        }()

        descLabel = {
            let v = LineSpaceLabel()
            let typo = CLSystemToken.typography(token: .tbl)
            v.paragraphSpace = 16
            v.config(typo)
            scrollContainer.stack.addArrangedSubview(v)
            v.snp.makeConstraints { make in
                make.leading.equalToSuperview().offset(24)
                make.trailing.equalToSuperview().offset(-24)
            }
            return v
        }()
    }

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        NaviAlphaHandle.changeNaviTitleAlpha(scrollView: scrollView, titleLabel: navigationView.titleLabel)
    }
}
