//
//  YHSelectLookHeadView.swift
//  galaxy
//
//  Created by EDY on 2024/11/26.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHSelectLookHeadView: UIView {
    typealias Block = () -> ()
    var block: Block?
    var itemButton: UIButton!
    
    var selectIndex = 0 {
        didSet {
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .white
        setUpView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpView() {
        backgroundColor = .white
        itemButton = {
            let button = UIButton(type: .custom)
            button.titleLabel?.font = UIFont.PFSC_M(ofSize: 12)
            button.contentHorizontalAlignment = .center
            button.setTitle("全部产品", for: .normal)
            button.setImage(UIImage(named: "home_select_icon"), for: .normal)
            button.setTitleColor(UIColor(hex: 0x6d788a), for: .normal)
            button.setTitleColor(UIColor.brandMainColor, for: .selected)
            button.setImage(UIImage(named: "home_select_icon_select"), for: .selected)
            button.setBackgroundColor(color: UIColor.contentBkgColor, forState: .normal)
            button.setBackgroundColor(color: UIColor(hex: 0xebf0f9), forState: .selected)
            button.addTarget(self, action: #selector(itemClick), for: .touchUpInside)
            button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
            return button
        }()
        addSubview(itemButton)
        itemButton.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.top.equalTo(12)
            make.height.equalTo(26)
//            make.width.equalTo(92)
        }
        itemButton.iconInRight(with: 0.5)
    }
    
    @objc func itemClick() {
        itemButton.isSelected = true
        if let block = self.block {
            block()
        }
    }
}
