package jguard.client.gui;

import cucky.jGuard.lib.LogFile;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import jguard.client.Client;
import jguard.client.gui.dialog.OnlineClientsDialog;

public class StatusBar extends JPanel {
    
    private JLabel message;
    private JLabel online;
    private JButton btnOnline;

    public StatusBar() {
        super();
        super.setPreferredSize(new Dimension(100, 35));
        
        setLayout(null);
        
        message = new JLabel("Odpojeno");
        message.setBounds(10, 0, 100, 30);
        add(message);
        
        online = new JLabel("");
        online.setBounds(250, 0, 100, 30);
        add(online);
        
        // tlacitko zobrazujici klienty
        try {
            BufferedImage buttonIcon = ImageIO.read(new File("img/online_clients.png"));
            btnOnline = new JButton(new ImageIcon(buttonIcon));
            btnOnline.setFocusPainted(false);
            btnOnline.setContentAreaFilled(false);
            btnOnline.setBorderPainted(false);
            btnOnline.addActionListener(new ActionListener(){  
                @Override
                public void actionPerformed(ActionEvent e) {
                    new OnlineClientsDialog();
                }
            }); 
            btnOnline.setBounds(200, 0, 32, 32);
            add(btnOnline);
        } catch (IOException ex) {
            LogFile.printErr("File not found: image online_clinets.png");
        }
                
    }

    public void setMessage(String text) {
        message.setText(text);        
    }        
    
    public void setOnlineCount(){
        online.setText("Klientu online: " + Client.onlineClients.size());
    }
}
