//
//  LNJoinUsMultiLineTextInputView.swift
//  Gami
//
//  Created by OneeChan on 2026/1/20.
//

import Foundation
import UIKit
import SnapKit


class LNSkillFieldMultiLineEditView: LNSkillFieldBaseEditView {
    private let inputField = LNCommonTextView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupViews()
    }
    
    override func update(_ field: LNSkillEditField) {
        super.update(field)
        
        if let text = field.value as? String {
            inputField.setText(text)
        }
        if let size = field.validate.size {
            inputField.maxInput = size.max
        }
        needReview = false
    }
    
    required init(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension LNSkillFieldMultiLineEditView: UITextViewDelegate {
    func textViewDidChange(_ textView: UITextView) {
        field?.value = textView.text
        needReview = true
        
        delegate?.onSkillFieldBaseEditViewInputChanged(view: self)
    }
}

extension LNSkillFieldMultiLineEditView {
    private func setupViews() {
        inputField.delegate = self
        container.addSubview(inputField)
        inputField.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.height.equalTo(130)
        }
    }
}
