package xyz.danielcortes.views.autor;

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.Autor;

public class AutorListPanel {

  private JPanel contentPane;
  private JTable autorTable;
  private BaseTableModel<Autor> autorModel;

  public JPanel getContentPane() {
    return contentPane;
  }

  public JTable getAutorTable() {
    return autorTable;
  }

  public BaseTableModel<Autor> getAutorModel() {
    return autorModel;
  }

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

  private void createAutorTable() {
    // @formatter:off
    this.autorModel = new BaseTableModel<>(
        new String[]{"Nombre", "Apellido Paterno", "Apellido Materno", "Nº Libros"},
        (row, rowIndex, colIndex) -> {
          switch (colIndex) {
            case 0: return row.get(rowIndex).getNombre();
            case 1: return row.get(rowIndex).getApellidoPaterno();
            case 2: return row.get(rowIndex).getApellidoMaterno();
            case 3: return row.get(rowIndex).getLibros().size();
            default: return null;
          }
        }
    );
    // @formatter:on
    this.autorTable = new JTable(this.autorModel);
  }

  {
// 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(autorTable);
  }

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

}
