package uk.co.patrickhaston.mars;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.*;

public class MarsDialog extends JPanel 
{
  MarsFrame theFrame = null;
  MarsMessage theMessage = null;
  MarsPerson thePerson = null;
  int p = 0;
  JComboBox activityType = new JComboBox();
//  JButton stopButton = new JButton();
  JLabel talkTo = new JLabel();
  JLabel[] currentActivity = new JLabel[7];
  JLabel jLabel2 = new JLabel();
  JLabel jLabel1 = new JLabel();
  JComboBox activityDetail = new JComboBox();
  
  public MarsDialog(MarsFrame f, int m)
  {
    try
    {
      jbInit(f, m);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }

  }

  private void jbInit(MarsFrame f, int m) throws Exception
  {
    this.setLayout(null);
    //this.getContentPane().setLayout(null);
    this.setPreferredSize(new Dimension(400, 300));
    //this.setTitle("Talk to");
    talkTo.setText("Name");
    theFrame = f;
    p = m;
    if(m > 0)
    {
      thePerson = new MarsPerson((MarsPerson) theFrame.mars.People.elementAt(m));
      talkTo.setText(thePerson.getName());
      for (int i=0; i<7; i++)
      {
        currentActivity[i] = new JLabel();
        int a = thePerson.getActivity(i);
        if (a>0)
        {
          currentActivity[i].setText("Activity - " + ((MarsActivity) 
            theFrame.mars.Activities.elementAt(a)).getDescription());
        }
        else
        {
          currentActivity[i].setText("Activity - None");
        }
        currentActivity[i].setBounds(new Rectangle(25, 15+(i*15), 200, 15));
        this.add(currentActivity[i], null);
      }
    }
    activityType.setBounds(new Rectangle(120, 140, 255, 20));
//    stopButton.setText("Stop Activity");
//    stopButton.setBounds(new Rectangle(145, 85, 115, 25));
    talkTo.setBounds(new Rectangle(25, 0, 285, 15));
    jLabel2.setText("New Activity");
    jLabel2.setBounds(new Rectangle(20, 140, 75, 20));
    jLabel1.setText("detail");
    jLabel1.setBounds(new Rectangle(20, 175, 70, 20));
    activityDetail.setBounds(new Rectangle(120, 175, 255, 20));
    this.add(activityDetail, null);
    this.add(jLabel1, null);
    this.add(jLabel2, null);
    this.add(talkTo, null);
    this.add(activityType, null);
//    this.add(stopButton, null);

    activityType.addActionListener(new ActionListener() 
    {
      public void actionPerformed(ActionEvent e) 
      {
        activityType_ActionPerformed(e);
      }
    });
    for (int i=1; i<theFrame.mars.ActivityTypes.size() -1; i++)
    {
      activityType.addItem(((MarsType) theFrame.mars.ActivityTypes.elementAt(i)).getName());
    }
    setActivityDetail();
  }

  void activityType_ActionPerformed(ActionEvent e)
  {
    setActivityDetail();
  }


  void setActivityDetail()
  {
    activityDetail.removeAllItems();
    switch((activityType.getSelectedIndex() + 1))
    {
      case 1: // Construction
        for (int i=1; i<theFrame.mars.ConstructionTypes.size() - 1; i++)
          activityDetail.addItem(((MarsConstructionType) 
            theFrame.mars.ConstructionTypes.elementAt(i)).getName());
        break;
      case 2: // Research
        for (int i=1; i<theFrame.mars.Technologies.size() - 1; i++)
        {
          if( ((MarsTechnology) theFrame.mars.Technologies.elementAt(i)).enabled = true)
            activityDetail.addItem(((MarsTechnology) 
              theFrame.mars.Technologies.elementAt(i)).name);
        }
        break;
    }
  }
}
