package uk.co.patrickhaston.mars;
import uk.co.patrickhaston.pdhdata.PdhError;
import java.awt.BorderLayout;
import java.awt.Dimension;

public class MarsMeeting extends MarsConversation 
{
  public MarsMeeting(MarsFrame f)
  {
    super(f);
    status = INTRODUCTIONS;
  }
  
  public void addPeople()
  {
    MarsPersonFacePanel p = null;
    
    int pId = theFrame.mars.People.getFirstId();
    while (pId != PdhError.NOT_FOUND)
    {
      // Create a picture of the person's face
      p = new MarsPersonFacePanel(theFrame.mars, pId);
      //p.setPreferredSize(new Dimension(66, 100));
      
      // Add their picture to the faces panel
      faces.add(p);
      
      // the the id of the next person
      pId = theFrame.mars.People.getNextId(pId);
    }

    // Assemble the panels
    this.add(faces, BorderLayout.NORTH);
    this.add(speechPanel, BorderLayout.WEST);
    this.add(statementPanel, BorderLayout.EAST);

    theFrame.mars.logEvent("Meeting Panels created.");
    theFrame.mars.logEvent("faces Panels size: w=" + faces.getWidth() + " h=" + faces.getHeight());
    theFrame.mars.logEvent("Meeting Panels assembled.");
    
  }

  public void updateConversation()
  {
    // Find out who's turn it is to speak
    int nextSpeaker = theFrame.mars.People.getNextId(lastSpeaker);
    if (nextSpeaker == PdhError.NOT_FOUND)
    {
      // it's the player's turn to speak, so wait for the player...
      //nextSpeaker = 1;
      switch (status)
      {
        case 1: // Introductions
          // Display list of introductory statements
          // introductions complete - move to next stage
          status = READY;
          break;
        case 2: // Ready
          // Display list of proposals
          status = PROPOSAL_MADE;
          break;
        case 3: // Proposal made
          // Display accept / reject / modify proposal statements
          status = GOODBYES;
          break;
        case 4: // Goodbyes
          // Display goodbye / start new proposal
          // End conversation
          theFrame.endMeeting();
          break;
      }
      nextSpeaker = theFrame.mars.People.getNextId(1);
    }
    saySomething(nextSpeaker);
    
  }
  
  public void saySomething(int speaker)
  {
    switch (status)
    {
      case 1: // Introductions
        speak(speaker, "Hello");
        break;
      case 2: // Ready
        speak(speaker, "I think we should ...");
        break;
      case 3: // Proposal Made
        speak(speaker, "I agree.");
        break;
      case 4: // Goodbyes
        speak(speaker, "Goodbye");
        break;
    }
  }
}
