//
//  CWSearchBar.swift
//  ColorfulWallpaper
//
//  Created by nkl on 2024/9/10.
//

import Foundation
import UIKit
import Localize_Swift
import KLExtension

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

    lazy var iconView: UIImageView = .init(image: UIImage(named: "icon_search"))

    lazy var titleLabel: UILabel = .simpleLabel(text: "Search Music".localized(),font: .systemFont14,color: .hexColor("#A8ACAF"))

    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.edges.equalToSuperview()
        }
        iconView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(24)
        }

        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")
    }
}
