//
//  MusicSearchBar.swift
//  PhysicalWallPaper
//
//  Created by nkl on 2024/11/13.
//

import Foundation
import KLExtension
import UIKit

class MusicSearchBar: UIControl {
    lazy var searchView: UIView = {
        let v = UIView()
        v.backgroundColor = .white.withAlphaComponent(0.1)
        v.layer.cornerRadius = 12
        v.layer.masksToBounds = true
        v.isUserInteractionEnabled = false
        return v
    }()

    lazy var iconView: UIImageView = .init(image: .iconSearch)

    lazy var titleLabel: UILabel = .simpleLabel(text: "Search Music", font: .systemFont14, color: .white.withAlphaComponent(0.3))

    override init(frame: CGRect) {
        super.init(frame: frame)
        addChildren()
        makeCOnstraints()
    }

    func addChildren() {
        addSubview(searchView)
        searchView.addSubview(iconView)
        searchView.addSubview(titleLabel)
    }

    func makeCOnstraints() {
        searchView.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview()
            make.verticalEdges.equalToSuperview().inset(4)
        }
        iconView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(16)
        }

        titleLabel.snp.makeConstraints { make in
            make.leading.equalTo(iconView.snp.trailing).offset(8)
            make.trailing.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
        }
    }

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