//
//  MPPositive_SearchViewController.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/4/19.
//

import UIKit

class MPPositive_SearchViewController: MPPositive_BaseViewController {
    //背景图片
    private lazy var bgImageView:UIImageView = {
        let imageView:UIImageView = .init(image: .init(named: "B_Home_BG'bg"))
        imageView.contentMode = .scaleAspectFill
        return imageView
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        setTitle("")
        configure()
        
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    //配置
    private func configure() {
        let searchView = createSearchView()
        navView.addSubview(searchView)
        searchView.snp.makeConstraints { make in
            make.width.equalTo(339*width)
            make.height.equalTo(32*width)
            make.center.equalToSuperview()
        }
        view.addSubview(bgImageView)
        bgImageView.snp.makeConstraints { make in
            make.top.right.left.equalToSuperview()
            make.height.equalTo(981*width)
        }
    }
    //生成一个顶部搜索框
    private func createSearchView() -> UIView{
        let searchView:UIView = UIView()
        searchView.backgroundColor = .init(hex: "#212121")
        searchView.isUserInteractionEnabled = true
        searchView.layer.masksToBounds = true
        searchView.layer.cornerRadius = 16*width
        //添加一个icon
        let iconImageView = UIImageView(image: .init(named: "Search_ICON'logo"))
        searchView.addSubview(iconImageView)
        iconImageView.snp.makeConstraints { make in
            make.height.width.equalTo(16*width)
            make.left.equalToSuperview().offset(16*width)
            make.centerY.equalToSuperview()
        }
        let label = createLabel("Search songs,artists,playlists", font: .systemFont(ofSize: 14*width, weight: .regular), textColor: .init(hex: "#666666"), textAlignment: .left)
        searchView.addSubview(label)
        label.snp.makeConstraints { make in
            make.left.equalTo(iconImageView.snp.right).offset(8*width)
            make.centerY.equalToSuperview()
        }
        searchView.isUserInteractionEnabled = true
        searchView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(searchClick(_:))))
        return searchView
    }
    //前往搜索结果页
    @objc fileprivate func searchClick(_ sender:UITapGestureRecognizer) {
        let resultVC = MPPositive_SearchResultShowViewController()
        navigationController?.pushViewController(resultVC, animated: false)
    }
}

