//
//  LNJoinUsReviewViewController.swift
//  Gami
//
//  Created by OneeChan on 2026/1/20.
//

import Foundation
import UIKit
import SnapKit


extension UIView {
    func pushToJoinUsReview(_ animated: Bool = true) {
        let vc = LNJoinUsReviewViewController()
        
        let fromJoin = navigationController?.viewControllers.last is LNJoinUsViewController
        if fromJoin, var viewControllers = navigationController?.viewControllers {
            viewControllers.removeLast()
            viewControllers.append(vc)
            navigationController?.setViewControllers(viewControllers, animated: true)
        } else {
            navigationController?.pushViewController(vc, animated: true)
        }
    }
}


class LNJoinUsReviewViewController: LNViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupViews()
    }
}

extension LNJoinUsReviewViewController {
    private func setupViews() {
        navigationBarColor = .clear
        
        title = .init(key: "B00031")
        
        let bg = UIImageView()
        bg.image = .icJoinUsReviewBg
        bg.backgroundColor = .white
        view.addSubview(bg)
        bg.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview()
            make.top.equalTo(fakeNaviBgView)
        }
        
        let infoView = buildInfoView()
        view.addSubview(infoView)
        infoView.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview()
            make.centerY.equalToSuperview().multipliedBy(0.75)
        }
    }
    
    private func buildInfoView() -> UIView {
        let container = UIView()
        
        let icon = UIImageView()
        icon.image = .icJoinUsReview
        container.addSubview(icon)
        icon.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        
        let titleLabel = UILabel()
        titleLabel.text = .init(key: "B00061")
        titleLabel.font = .heading_h3
        titleLabel.textColor = .text_5
        titleLabel.numberOfLines = 0
        titleLabel.textAlignment = .center
        container.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview().inset(32)
            make.top.equalTo(icon.snp.bottom).offset(10)
        }
        
        let descLabel = UILabel()
        descLabel.text = .init(key: "B00062")
        descLabel.font = .body_s
        descLabel.textColor = .text_5
        descLabel.numberOfLines = 0
        descLabel.textAlignment = .center
        container.addSubview(descLabel)
        descLabel.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview().inset(32)
            make.bottom.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(4)
        }
        
        return container
    }
}

#if DEBUG

import SwiftUI

struct LNJoinUsReviewViewControllerPreview: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> some UIViewController {
        LNJoinUsReviewViewController()
    }
    
    func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
}

#Preview(body: {
    LNJoinUsReviewViewControllerPreview()
})
#endif
