package xyz.danielcortes.views.libro;

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

public class LibroListPanel {

  private JTable librosTable;
  private BaseTableModel<Libro> librosModel;
  private JPanel contentPane;

  public JTable getLibrosTable() {
    return librosTable;
  }

  public BaseTableModel<Libro> getLibrosModel() {
    return librosModel;
  }

  public JPanel getContentPane() {
    return contentPane;
  }

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

  private void createLibrosTable() {
    //@formatter:off
    this.librosModel = new BaseTableModel<>(
        new String[]{"Serie", "ISBN", "Titulo", "Precio Referencial"},
        (rows, rowIndex, colIndex) -> {
          switch(colIndex) {
            case 0: return rows.get(rowIndex).getSerie();
            case 1: return rows.get(rowIndex).getIsbn();
            case 2: return rows.get(rowIndex).getTitulo();
            case 3: return rows.get(rowIndex).getPrecioReferencia();
            default: return null;
          }
        }
    );
    //@formatter:on
    this.librosTable = new JTable(this.librosModel);
  }

  {
// 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(10, 10, 10, 10), -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_CAN_GROW,
            GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null,
            new Dimension(400, -1), null, 0, false));
    scrollPane1.setViewportView(librosTable);
  }

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

}
