//
//  CLTextView.swift

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

import Foundation
import IQTextView

class CLTextView: IQTextView{
    // MARK: - Properties
    private var recordHeightBlock: ((CGRect) -> Void)?
    
    // MARK: - Public Methods
    func updateByPlaceholderSize(_ block: @escaping (CGRect) -> Void) {
        recordHeightBlock = block
    }
    
    func sendTextChangedNoti(){
        NotificationCenter.default.post(
            name: UITextView.textDidChangeNotification,
            object: self)
    }
    
    // MARK: - Overrides
    override func layoutSubviews() {
        super.layoutSubviews()
        if let recordHeightBlock = recordHeightBlock {
            let realFrame = placeholderLabel.frame
            let placeholderShowRect = CGRect(x: realFrame.origin.x, y: realFrame.origin.y, width: realFrame.size.width, height: realFrame.size.height + realFrame.origin.y)
            recordHeightBlock(placeholderShowRect)
        }
    }
    
//    override func paste(_ sender: Any?) {
//        if let pasteboardString = UIPasteboard.general.string?.filterGarbledString {
//            let nowString = "\(text ?? "")\(pasteboardString)"
//            text = nowString
//            delegate?.textViewDidChange?(self)
//            
//        }
//    }
}

// MARK: - Extensions
extension String {
    var filterGarbledString: String? {
        // Assuming filterGarbledString removes invalid characters; implement as needed
        return self
    }
}
