//
//  YHPrincipleGroupUploadCell.swift
//  galaxy
//
//  Created by edy on 2024/5/6.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit
import AttributedString

class YHPrincipleGroupUploadCell: UITableViewCell {

    static let cellReuseIdentifier = "YHPrincipleGroupUploadCell"
    let btnTitleColor:UIColor = .brandMainColor
    let uploadBtnSize = CGSize(width: (KScreenWidth-(40)*2), height: 44)

    lazy var grayView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.init(hex: 0xf8f9fb)
        view.layer.cornerRadius = 6.0
        view.clipsToBounds = true
        return view
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.init(hex: 0xF0F0F0)
        return view
    }()
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.PFSC_M(ofSize: 17)
        label.textColor = UIColor.mainTextColor
        label.text = "《赴港居留同意书》"
        return label
    }()
    
    lazy var detailLabel: UILabel = {
        var label = UILabel()
        label.numberOfLines = 0
        let a: ASAttributedString = .init("由你现時所属內地工作单位或负责储存你的記錄的內地有关当局所发出的赴港居留同意书。\n", .font(UIFont.PFSC_R(ofSize: 12)),.foreground(UIColor.init(hex: 0x888F98)))
        let b: ASAttributedString = .init("请【下载模板】，填写信息，贵单位", .font(UIFont.PFSC_R(ofSize: 12)),.foreground(UIColor.mainTextColor))
        let c: ASAttributedString = .init("签字盖章", .font(UIFont.PFSC_R(ofSize: 12)),.foreground(UIColor.init(hex: 0x3570DC)))
        let d: ASAttributedString = .init("后，拍照or扫描上传", .font(UIFont.PFSC_R(ofSize: 12)),.foreground(UIColor.mainTextColor))
        label.attributed.text = a+b+c+d
        return label
    }()
    
    lazy var uploadBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle("上传".local, for: .normal)
        btn.titleLabel?.font = UIFont.PFSC_M(ofSize: 14)
        btn.setTitleColor(UIColor.init(hex: 0x3570DC), for: .normal)
        btn.iconInLeft(spacing: 6)
        btn.setImage(UIImage(named: "form_add_info"), for: .normal)
        btn.addTarget(self, action: #selector(didClickUploadBtn), for: .touchUpInside)
        return btn
    }()
    
    lazy var dotLineLayer:CAShapeLayer = {
        let borderLayer =  CAShapeLayer()
        borderLayer.path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: uploadBtnSize.width, height: uploadBtnSize.height), cornerRadius: 3.0).cgPath
        borderLayer.lineWidth = 1
        //[数组第一个数字表示单个虚线长度，第二个数字表示间隔]
        borderLayer.lineDashPattern = [3,1]  as [NSNumber]?
        //前边是虚线的长度，后边是虚线之间空隙的长度
        borderLayer.lineDashPhase = 0.1
        //实线边框
        borderLayer.fillColor = UIColor.clear.cgColor
        borderLayer.strokeColor = btnTitleColor.cgColor
        return borderLayer
    }()

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    @objc func didClickUploadBtn() {
        
    }
    
    func setupUI() {
        
        self.selectionStyle = .none
        contentView.backgroundColor = UIColor.white
        
        contentView.addSubview(grayView)
        grayView.addSubview(titleLabel)
        grayView.addSubview(lineView)
        grayView.addSubview(detailLabel)
        grayView.addSubview(uploadBtn)
        uploadBtn.layer.addSublayer(dotLineLayer)

        grayView.snp.makeConstraints { make in
            make.left.equalTo(24)
            make.right.equalTo(-24)
            make.top.bottom.equalTo(0)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.top.equalTo(16)
            make.height.equalTo(24)
        }
        
        lineView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(0.5)
            make.top.equalTo(titleLabel.snp.bottom).offset(12)
        }
        
        detailLabel.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.top.equalTo(lineView.snp.bottom).offset(16)
        }
        
        uploadBtn.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.top.equalTo(detailLabel.snp.bottom).offset(16)
            make.height.equalTo(44)
            make.bottom.equalTo(-16)
        }
    }
}
