import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
import java.io.*;
import java.util.List;
import java.util.ArrayList;
/**
 * HwBox is used to display one box worth of data, e.g. a list of assignments
 *
 * <p>
 * Uses 
 * {@link DrawingPanel}
 *
 * @author Fred Kral
 * @version 1.2
 *
 */
 /* Help for (future) line wrap:
    http://stackoverflow.com/questions/4413132/problems-with-newline-in-graphics2d-drawstring
    http://docs.oracle.com/javase/tutorial/2d/text/drawmulstring.html
 */
 
public class HwBox {
      // Another way to do this: give only the list of assignments for the box (not person/course/pDate)

   /** This is the person (teacher/student) that is getting a BillBoard */
   Person person;
   Course courseBox;
   plainDate pDate;
   Graphics g;
   /** These are the coordinates and dimensions of the HwBox */
   int x =  0; // from upper left
   int y =  0; //from upper left
   int dx = 0; // x extent
   int dy = 0; // y extent
   
   boolean today = false;
   
   Color boxColor = new Color(253, 253, 253);
   Color boxColorToday = new Color(240, 240, 220);

   Color defaultColor = new Color(0, 100, 250);


   public HwBox (Person person, plainDate pDate, Course courseBox, 
                  Graphics g, int x, int y, int dx, int dy) {
      this.person = person;
      this.courseBox = courseBox;
      this.pDate = pDate;
      this.g = g;
      this.x = x;
      this.y = y;
      this.dx = dx;
      this.dy = dy;
      g.setFont(BillBoard.headerFont);
      
      /* Today. Strip out the hour and minute information just to be sure. */
      plainDate tDate = new plainDate();
      tDate = tDate.getToday(false); // full today date
      plainDate todayDate = new plainDate( tDate.getDay(), tDate.getMonth(), tDate.getYear() );
      today = pDate.equals(todayDate);
   
      
   }
   
   
   public void clear () {
      if (today) g.setColor(boxColorToday);
      else g.setColor(boxColor);
      
      g.fillRect(x, y, dx, dy);
   }

   public void draw () {
   
      clear();
      
      g.setColor(defaultColor);
   
      
      /* Need list of assignments for this student */
      
      /* Multiple assignments per course per day ? */
      int numAssignments = 0;
      
      /* Loop over each assignment until find the one(s) needed for this HW Box */
      for ( Course course : person.getCourses() ) {
         /* Is it the same course as for this box ? */
         if ( course.equals(courseBox) ) {
         /* Active course */
            if ( course.getActive() ) {
            /* Assignments in the course */
               for ( Assignment assignment : course.getAssignments() ) {
               /* Active assignment */
                  if (assignment.getActiveAssignment()) {
                  /* Date match? */
                     if ( assignment.getPlainDate().equals(pDate) ) {
                       // Date matches
                       
                        assignment.sysPrintValue();
                      
                        /* Color depends on the status of the assignment */
                        if ( ! assignment.getResult().equals("") ) {
                           if ( assignment.getResult().equals("M") )      // missing
                              g.setColor(new Color(200, 80, 80));
                           else if ( assignment.getResult().equals("E") ) // excused
                              g.setColor(new Color(0, 70, 20));
                           else                               // graded or a mistake
                              g.setColor(new Color(50, 180, 80));
                        }
                        else {                                // ungraded or no info
                           g.setColor(new Color(50, 50, 200));
                        }
                     
                     
                        // there can be more than one assigment per course per day
                        g.drawString(
                           numAssignments + 1 + ") " + assignment.getShortAssignmentName(), 
                           x + 4, y + 12 + numAssignments*16);
                        
                        numAssignments++;
                        
                     }
                  }
               }
            }
         }
      }
   }


}// END class