package xyz.danielcortes.views.categoria;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import java.awt.Dimension;
import java.awt.Insets;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import xyz.danielcortes.framework.BaseTableModel;
import xyz.danielcortes.models.Categoria;

public class CategoriaListPanel {

  private JPanel contentPane;
  private JTable categoriaTable;
  private BaseTableModel<Categoria> categoriaModel;

  public JPanel getContentPane() {
    return contentPane;
  }

  public JTable getCategoriaTable() {
    return categoriaTable;
  }

  public BaseTableModel<Categoria> getCategoriaModel() {
    return categoriaModel;
  }

  private void createUIComponents() {
    this.createCategoriaTable();
  }

  private void createCategoriaTable() {
    // @formatter:off
    this.categoriaModel = new BaseTableModel<>(
        new String[]{"Nombre", "Nº Libros"},
        (row, rowIndex, colIndex) -> {
          switch (colIndex) {
            case 0: return row.get(rowIndex).getNombre();
            case 1: return row.get(rowIndex).getLibros().size();
            default: return null;
          }
        }
    );
    // @formatter:on
    this.categoriaTable = new JTable(this.categoriaModel);
  }

  {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
    $$$setupUI$$$();
  }

  /**
   * Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
   * call it in your code!
   *
   * @noinspection ALL
   */
  private void $$$setupUI$$$() {
    createUIComponents();
    contentPane = new JPanel();
    contentPane.setLayout(new GridLayoutManager(1, 1, new Insets(20, 20, 20, 20), -1, -1));
    final JScrollPane scrollPane1 = new JScrollPane();
    contentPane.add(scrollPane1,
        new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
            GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW,
            GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null,
            new Dimension(400, -1), null, 0, false));
    scrollPane1.setViewportView(categoriaTable);
  }

  /**
   * @noinspection ALL
   */
  public JComponent $$$getRootComponent$$$() {
    return contentPane;
  }
}
