//
//  LNRoomMessageInputView.swift
//  Gami
//
//  Created by OneeChan on 2026/3/11.
//

import Foundation
import UIKit
import SnapKit


class LNRoomMessageInputView: UIView {
    private weak var roomSession: LNRoomSession?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupViews()
    }
    
    func update(_ room: LNRoomSession?) {
        roomSession = room
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension LNRoomMessageInputView {
    private func setupViews() {
        onTap { [weak self] in
            guard let self else { return }
            let panel = LNCommonInputPanel()
            panel.handler = { [weak self] message in
                guard let self else { return }
                guard let roomSession else { return }
                roomSession.sendChatMessage(text: message) { success in }
            }
            panel.popup(self)
        }
        
        backgroundColor = .fill.withAlphaComponent(0.15)
        layer.cornerRadius = 15
        snp.makeConstraints { make in
            make.width.equalTo(140)
            make.height.equalTo(32)
        }
        
        let titleLabel = UILabel()
        titleLabel.text = .init(key: "A00325") + "..."
        titleLabel.font = .body_s
        titleLabel.textColor = .text_1.withAlphaComponent(0.8)
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview().inset(10)
            make.centerY.equalToSuperview()
        }
    }
}
