package com.gitrekt.resort.controller;

import com.gitrekt.resort.model.entities.GuestFeedback;
import com.gitrekt.resort.model.services.GuestFeedbackService;
import com.gitrekt.resort.view.GuestFeedbackListItem;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;

/**
 * Handles the functionality of FeedbackReportScreen.fxml
 */
public class FeedbackReportScreenController 
        implements Initializable {
    
    @FXML
    private Button backButton;
    
    @FXML
    private ListView<GuestFeedback> guestFeedbackListView;
    
    private ObservableList<GuestFeedback> guestFeedbackList;
    
    private GuestFeedbackService guestFeedbackService;
    
    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        guestFeedbackList = FXCollections.observableArrayList();
        guestFeedbackListView.setItems(guestFeedbackList);
        guestFeedbackListView.setCellFactory( 
            param -> new GuestFeedbackListItem(this)
        );
        
        guestFeedbackListView.setPlaceholder(
            new Label("No unresolved feedback")
        );
        
        this.guestFeedbackService = new GuestFeedbackService();
        loadFeedback();
    }
    
    /**
     * @param item The data item to hide from the screen.
     */
    public void hideItem(GuestFeedback item) {
        guestFeedbackList.remove(item);
    }
    
    @FXML
    private void onBackButtonClicked() throws IOException {
        ScreenManager.getInstance().switchToScreen(
            "/fxml/ReportsHomeScreen.fxml"
        );
    }
    
    @FXML
    private void onRefreshButtonClicked() {
        loadFeedback();
    }
    
    private void loadFeedback() {
        // Clear any existing items from the list
        guestFeedbackList.clear();
        
        // Retrieve new items
        guestFeedbackList.addAll(
            guestFeedbackService.getUnresolvedGuestFeedback()
        );
    }
    
}

@@ -434,44 +434,8 @@
 le;%0A
-import javafx.scene.control.Button;%0A
 impo
@@ -544,33 +544,31 @@
  of 
-F
+f
 eedback
-R
+ r
 eport
-S
+ s
 creen.
-fxml
 %0A */
@@ -612,25 +612,16 @@
 troller 
-%0A        
 implemen
@@ -643,58 +643,8 @@
 e %7B%0A
-    %0A    @FXML%0A    private Button backButton;%0A    
 %0A   
@@ -709,20 +709,16 @@
 stView;%0A
-    
 %0A    pri
@@ -775,72 +775,8 @@
 st;%0A
-    %0A    private GuestFeedbackService guestFeedbackService;%0A    
 %0A   
@@ -803,16 +803,21 @@
 zes the 
+FXML 
 controll
@@ -1078,22 +1078,8 @@
 ory(
- %0A            
 para
@@ -1114,36 +1114,18 @@
 em(this)
-%0A        );%0A        
+);
 %0A       
@@ -1162,29 +1162,16 @@
 eholder(
-%0A            
 new Labe
@@ -1201,92 +1201,11 @@
 ck%22)
-%0A        );%0A        %0A        this.guestFeedbackService = new GuestFeedbackService(
 );
+%0A
 %0A   
@@ -1227,28 +1227,24 @@
 ck();%0A    %7D%0A
-    
 %0A    /**%0A   
@@ -1391,36 +1391,125 @@
 ve(item);%0A    %7D%0A
+%0A
     
+/**%0A     * Returns to the reports home screen.%0A     *%0A     * @throws IOException%0A     */
 %0A    @FXML%0A    p
@@ -1614,29 +1614,16 @@
 oScreen(
-%0A            
 %22/fxml/R
@@ -1644,38 +1644,109 @@
 en.fxml%22
+);
 %0A    
+%7D%0A%0A
     
-);
+/**
 %0A    
-%7D
+ * Loads and displays updated guest feedback from the database.
 %0A    
+ */
 %0A    @FX
@@ -1826,96 +1826,193 @@
   %7D%0A
+%0A
     
-%0A    private void loadFeedback() %7B%0A        // Clear any existing items from the list
+/**%0A     * Loads updated guest feedback from the database.%0A     */%0A    private void loadFeedback() %7B%0A        GuestFeedbackService guestFeedbackService = new GuestFeedbackService();
 %0A   
@@ -2047,47 +2047,8 @@
 ();%0A
-        %0A        // Retrieve new items%0A
     
@@ -2080,21 +2080,8 @@
 All(
-%0A            
 gues
@@ -2125,25 +2125,16 @@
 edback()
-%0A        
 );%0A    %7D
@@ -2134,15 +2134,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

Refactor feedback report screen controller