package com.its.dsrc.ui;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

public class CtlrSttsTableCellRenderer extends DefaultTableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        String commStts = table.getModel().getValueAt(row, 6).toString();
        if (commStts.equals("Connect")) {
            cell.setBackground(new Color(255, 255, 255, 255));
//            if (column == 7) {
//                String door = table.getModel().getValueAt(row, 7).toString();
//                if (door.equals("열림")) {
//                    cell.setBackground(new Color(255, 0, 0, 176));
//                    cell.setForeground(new Color(255, 255, 255, 255));
//                }
//            }
            if (column == 8) {
                String door = table.getModel().getValueAt(row, 8).toString();
                if (door.equals("열림")) {
                    cell.setBackground(new Color(255, 0, 0, 176));
                    cell.setForeground(new Color(255, 255, 255, 255));
                }
            }
            if (column == 9) {
                String door = table.getModel().getValueAt(row, 9).toString();
                if (door.equals("열림")) {
                    cell.setBackground(new Color(255, 0, 0, 176));
                    cell.setForeground(new Color(255, 255, 255, 255));
                }
            }
            if (column == 10) {
                String heater = table.getModel().getValueAt(row, 10).toString();
                if (heater.equals("가동")) {
                    cell.setBackground(new Color(255, 213, 0, 250));
                    cell.setForeground(new Color(0, 0, 0, 255));
                }
            }
            if (column == 11) {
                String video = table.getModel().getValueAt(row, 11).toString();
                if (video.equals("가동")) {
                    cell.setBackground(new Color(255, 213, 0, 250));
                    cell.setForeground(new Color(0, 0, 0, 255));
                }
            }
        } else if (commStts.equals("Login")) {
            cell.setBackground(new Color(182, 175, 97, 176));
        } else {
            cell.setBackground(new Color(182, 97, 97, 176));
        }

        if (column != 3 && column != 4) {
            setHorizontalAlignment(SwingConstants.CENTER);
        } else {
            setHorizontalAlignment(SwingConstants.LEFT);
        }
        if (column == 0) {
            cell.setBackground(Color.LIGHT_GRAY);
        }

        return cell;
    }
}
