/*
 * Copyright (C) 2025 ctecinf.com.br
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package br.com.hobbyslotcar.racedirector;

import br.com.ctecinf.jetty.Config;
import br.com.ctecinf.jetty.JettyException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;

/**
 *
 * @author Cássio Conceição
 * @since 07/03/2025
 * @version 2503
 * @see http://hobbyslotcar.com.br
 */
public class ConfigLanes extends JDialog {

    protected static Config CONFIG = new Config() {
        @Override
        public String getFileName() {
            return "lanes";
        }
    };

    public ConfigLanes() throws JettyException {

        setTitle("Fendas");

        if (CONFIG.keySet().isEmpty()) {
            CONFIG.add("Fenda 1", Color.BLUE.getRGB());
            CONFIG.add("Fenda 2", Color.YELLOW.getRGB());
            CONFIG.add("Fenda 3", Color.GREEN.getRGB());
            CONFIG.add("Fenda 4", Color.RED.getRGB());
            CONFIG.store();
        }

        DefaultListModel model = new DefaultListModel();
        model.addAll(CONFIG.keySet());

        JList lanes = new JList(model);
        lanes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lanes.setPreferredSize(new Dimension(300, 0));
        lanes.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                setBorder(BorderFactory.createEmptyBorder());
                return this;
            }
        });

        JLabel label = new JLabel("Fendas", Img.get("lanes"), SwingConstants.CENTER);

        JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

        JButton button = new JButton("Adicionar", Img.get("list-add"));
        button.addActionListener((ActionEvent e) -> {

        });
        panel.add(button);

        button = new JButton("Remover", Img.get("list-remove"));
        button.addActionListener((ActionEvent e) -> {

        });
        panel.add(button);

        button = new JButton("Fechar", Img.get("window-close"));
        button.addActionListener((ActionEvent e) -> {
            dispose();
        });
        panel.add(button);

        setLayout(new BorderLayout(10, 10));
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        add(label, BorderLayout.NORTH);
        add(new JScrollPane(lanes), BorderLayout.CENTER);
        add(panel, BorderLayout.SOUTH);
        setMinimumSize(new Dimension(600, 600));
        setLocationRelativeTo(null);
    }

}
