package Taquilla.View;

import DataAccess.Implementations.ShowDao;
import Elements.Show;
import Taquilla.View.Helpers.GUI;
import Taquilla.View.Helpers.JFrameHelper;

import javax.swing.*;
import java.util.ArrayList;

public class ShowsView {
    public GUI gui;

    public ShowsView() {
        JFrame frame = JFrameHelper.createFrame();
        gui = JFrameHelper.createCenteredGUI("Shows");
        JComboBox<String> startDateCombo = new JComboBox<>();
        addDatesToComboBox(startDateCombo);
        gui.addLabeledField("startDateCombo", "Start date: ", startDateCombo);

        JComboBox<String> endDateCombo = new JComboBox<>();
        addDatesToComboBox(endDateCombo);
        gui.addLabeledField("endDateCombo", "End date: ", endDateCombo);

        JFrameHelper.addSeparator(gui, 200);

        addShowsDetails(gui);

        JFrameHelper.showFrameAndGui(frame, gui);
    }

    public static void main(String[] args) {
        new ShowsView();
    }

    private static void addDatesToComboBox(JComboBox<String> comboBox) {
        ShowDao showDao = new ShowDao();
        ArrayList<Show> shows = new ArrayList<>(showDao.findAll());
        ArrayList<String> dates = new ArrayList<>();
        for (Show show : shows) {
            String dateText = show.getDate().toString();
            if (dates.isEmpty()) {
                comboBox.addItem(dateText);
                dates.add(dateText);
            } else {
                Boolean hasDate = false;
                for (String date : dates) {
                    if (dateText.equals(date)) {
                        hasDate = true;
                        break;
                    }
                }
                if (!hasDate) {
                    comboBox.addItem(dateText);
                    dates.add(dateText);
                }
            }
        }
    }

    private static void addShowsDetails(GUI gui) {
        ShowDao showDao = new ShowDao();
        ArrayList<Show> shows = new ArrayList<>(showDao.findAll());
        for (Show show : shows) {
            gui.add(new JTextArea(show.getPlay().getName()));
            JFrameHelper.addSeparator(gui, 5);
            gui.add(new JTextArea(show.getDate().toString()));
            JFrameHelper.addSeparator(gui, 5);
            gui.add(new JTextArea(show.getTime().toString()));
            JFrameHelper.addSeparator(gui, 200);
        }
    }
}

@@ -182,16 +182,60 @@
 wing.*;%0A
+import javax.swing.table.DefaultTableModel;%0A
 import j
@@ -852,27 +852,80 @@
     
-addShowsDetails(gui
+JTable table = createShowsDetailsTable();%0A        gui.add(%22table%22, table
 );%0A%0A
@@ -1937,38 +1937,37 @@
     %7D%0A%0A    p
-rivate
+ublic
  static 
 void addShow
@@ -1958,39 +1958,305 @@
 tic 
-void addShowsDetails(GUI gui) %7B
+JTable createShowsDetailsTable() %7B%0A        DefaultTableModel model = new DefaultTableModel();%0A        JTable table = new JTable(model);%0A%0A        model.addColumn(%22Play%22);%0A        model.addColumn(%22Date%22);%0A        model.addColumn(%22Time%22);%0A%0A        model.addRow(new String%5B%5D%7B%22PLAY%22, %22DATE%22, %22TIME%22%7D);%0A
 %0A   
@@ -2407,38 +2407,83 @@
         
-gui.add(new JTextArea(
+String%5B%5D showDetails = new String%5B3%5D;%0A            showDetails%5B0%5D = 
 show.get
@@ -2498,18 +2498,16 @@
 etName()
-))
 ;%0A      
@@ -2516,77 +2516,25 @@
     
-JFrameHelper.addSeparator(gui, 5);%0A            gui.add(new JTextArea(
+showDetails%5B1%5D = 
 show
@@ -2546,34 +2546,32 @@
 ate().toString()
-))
 ;%0A            JF
@@ -2572,77 +2572,25 @@
     
-JFrameHelper.addSeparator(gui, 5);%0A            gui.add(new JTextArea(
+showDetails%5B2%5D = 
 show
@@ -2610,18 +2610,16 @@
 String()
-))
 ;%0A      
@@ -2628,54 +2628,67 @@
     
-JFrameHelper.addSeparator(gui, 200);%0A        %7D
+model.addRow(showDetails);%0A        %7D%0A%0A        return table;
 %0A   

fix shows table