//
//  FriendsNoticeOnceView.swift

//
//  Created by Leon on 2025/8/15.
//

import UIKit

class FriendsNoticeOnceView: UIView {
    var icon: UIImageView!
    var textLabel: LineSpaceLabel!
    var closeButton: UIButton!
    
    var tapCloseAction: (()-> Void)?
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
        setupData()
        setupEvent()
    }

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

    private func setupViews() {
        backgroundColor = .c.cpn
        cornerRadius = 8

        icon = {
            let v = UIImageView()
            v.image = UIImage(named: "icon_pink_heart")
            addSubview(v)
            v.snp.makeConstraints { make in
                make.centerY.equalToSuperview()
                make.leading.equalToSuperview().offset(24)
                make.size.equalTo(CGSize(width: 24, height: 24))
            }
            return v
        }()

        closeButton = {
            let v = UIButton()
            let image = MWIconFont.image(fromIcon: .delete, size: CGSize(width: 12, height: 12), color: .text)
            v.addTarget(self, action: #selector(tapClose), for: .touchUpInside)
            v.contentMode = .center
            v.setImage(image, for: .normal)
            addSubview(v)
            v.snp.makeConstraints { make in
                make.size.equalTo(CGSize(width: 44, height: 44))
                make.centerY.equalToSuperview()
                make.trailing.equalToSuperview().offset(0)
            }
            return v
        }()

        textLabel = {
            let v = LineSpaceLabel()
            let typo = CLSystemToken.typography(token: .tls)
            v.config(typo)
            v.textColor = .text
            addSubview(v)
            v.snp.makeConstraints { make in
                make.leading.equalTo(icon.snp.trailing).offset(16)
                make.trailing.equalTo(closeButton.snp.leading).offset(0)
                make.top.equalToSuperview().offset(12)
                make.bottom.equalToSuperview().offset(-12)
            }
            return v
        }()
    }

    private func setupData() {
        textLabel.text = "The heartbeat value above 12.0℃ can appear in the relationship list"
    }

    private func setupEvent() {
    }

    @objc func tapClose() {
         AppCache.cache(key: CacheKey.friendsHeartBeatShowedOnce.rawValue, value: true)
        tapCloseAction?()
        removeFromSuperview()
    }
}
