package org.example.demo.praktikum3;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class ChatWindow extends JFrame {
    private JTextArea textArea;
    private MessageReceiver receiver;

    private JPanel inputPanel;
    private JTextField messageInput;
    private JButton messageSubmit;
    private MessageSender sender;

    public ChatWindow(MessageReceiver receiver, MessageSender sender) {
        textArea = new JTextArea();
        this.add(BorderLayout.NORTH, textArea);
        receiver.setText(textArea);

        inputPanel = new JPanel();
        inputPanel.setLayout(new FlowLayout());
        this.add(BorderLayout.SOUTH, inputPanel);

        messageInput = new JTextField(20);
        inputPanel.add(messageInput);

        messageSubmit = new JButton("Submit");
        messageSubmit.addActionListener(e -> {
            sender.sendMessage(messageInput.getText());
        });
        inputPanel.add(messageSubmit);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
