//
//  YHImproveSchemeCell.swift
//  galaxy
//
//  Created by Dufet on 2024/11/16.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit
import AttributedString

class YHImproveSchemeCell: UITableViewCell {

    static let cellReuseIdentifier = "YHImproveSchemeCell"
    
    var rightBtnClick: (() -> Void)?

    lazy var whiteContentView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.clipsToBounds = true
        return view
    }()
    
    lazy var dotLine: YHDashLineView = {
        let view = YHDashLineView(strokeColor: UIColor.init(hex: 0xF7F2ED).cgColor, lineWidth: 0.8, lineDashPattern: [3, 3])
        return view
    }()
    
    lazy var markImgV: UIImageView = {
        let v = UIImageView(image: UIImage(named: "my_scheme_mark"))
        return v
    }()
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.PFSC_B(ofSize: 17)
        label.textColor = .mainTextColor
        label.text = "提升方案"
        return label
    }()
    
    lazy var tips1Label: UILabel = {
        let label = UILabel()
        label.font = UIFont.PFSC_R(ofSize: 14)
        label.textColor = UIColor.mainTextColor
        label.numberOfLines = 0
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 4
        let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle]
        label.attributedText = NSAttributedString(string: "已根据港府甄选条件，为您规划后续提升方案，您可根据实际情况进行提升~", attributes: attributes)
        return label
    }()
    
    lazy var rightBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.titleLabel?.font = UIFont.PFSC_M(ofSize: 12)
        button.backgroundColor = UIColor(hex: 0xd48638).withAlphaComponent(0.08)
        button.contentHorizontalAlignment = .center
        button.setTitle("查看详情", for: .normal)
        button.setImage(UIImage(named: "scheme_button_icon"), for: .normal)
        button.setTitleColor(UIColor(hex: 0xd48638), for: .normal)
        button.layer.cornerRadius = kCornerRadius3
        button.clipsToBounds = true
        button.YH_clickEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 20, right: 20)
        button.addTarget(self, action: #selector(didRightBtnClicked), for: .touchUpInside)
        return button
    }()
    
    @objc func didRightBtnClicked() {
        rightBtnClick?()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    func setupUI() {
        
        selectionStyle = .none
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        contentView.clipsToBounds = true
        
        contentView.addSubview(whiteContentView)
        whiteContentView.addSubview(dotLine)
        whiteContentView.addSubview(markImgV)
        whiteContentView.addSubview(titleLabel)
        whiteContentView.addSubview(tips1Label)
        whiteContentView.addSubview(rightBtn)

        whiteContentView.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.bottom.equalToSuperview()
        }
        
        dotLine.snp.makeConstraints { make in
            make.left.equalTo(24)
            make.right.equalTo(-24)
            make.top.equalTo(0)
            make.height.equalTo(1)
        }
        
        markImgV.snp.makeConstraints { make in
            make.left.equalTo(24)
            make.width.equalTo(4)
            make.height.equalTo(16)
            make.centerY.equalTo(titleLabel)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(26)
            make.height.equalTo(24)
            make.left.equalTo(markImgV.snp.right).offset(8)
            make.right.equalTo(-24)
        }
        
        tips1Label.snp.makeConstraints { make in
            make.left.equalTo(24)
            make.right.equalTo(-24)
            make.top.equalTo(titleLabel.snp.bottom).offset(18)
            make.bottom.equalTo(-32)
        }
        
        rightBtn.snp.makeConstraints { make in
            make.width.equalTo(76)
            make.height.equalTo(27)
            make.right.equalTo(-24)
            make.top.equalTo(titleLabel)
        }
        rightBtn.iconInRight(with: 2)
    }

}
