//
//  QSLBaseController.swift
//  QuickSearchLocation
//
//  Created by mac on 2024/4/10.
//

import UIKit
import SnapKit

class QSLBaseController: UIViewController {
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        // 默认隐藏 navbar
        self.navigationController?.setNavigationBarHidden(true, animated: true)
    }
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        // 默认设置背景色为F6F6F6
        self.view.backgroundColor = QSLColor.backGroundColor
        
        setBackButton()
    }
}

extension QSLBaseController {
    
    func setBackButton() {
        
        let backButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100.rpx, height: 25.rpx))
        backButton.title(self.title ?? "")
        backButton.textColor(QSLColor.Color_202020)
        backButton.mediumFont(17)
        backButton.backgroundColor = .clear
        backButton.image(UIImage(named: "public_back_btn"))
        backButton.setImageTitleLayout(.imgLeft, spacing: 4.rpx)
        backButton.addTarget(self, action: #selector(backBtnAction), for: .touchUpInside)
        let item = UIBarButtonItem(customView: backButton)
        self.navigationItem.leftBarButtonItem = item
        self.navigationItem.hidesBackButton = true
    }
}

extension QSLBaseController {
    
    @objc func backBtnAction() {
        self.dismiss(animated: true)
        self.navigationController?.popViewController(animated: true)
    }
}
