package uk.co.patrickhaston.mars;
import java.awt.*;
import javax.swing.JPanel;
import java.util.Observer;
import java.util.Observable;
import java.util.Date;
import java.text.DateFormat;

public class MarsStatsPanel extends MPanel implements Observer
{
  // contents
  private MarsFrame theFrame = null;
  
  public MarsStatsPanel(MarsFrame frame)
  {
    theFrame = frame;
  }

  public void update(Observable o, Object obj)
  {
    // no code yet
    //this.repaint(100);
    //this.invalidate();
    //this.show();
  }

  public void paintComponent(Graphics g)
  {
    g.setColor(Color.orange);
    String s1 = "";
    String s2 = "";
    String s3 = "";
    String s4 = "";
    String s5 = "";
    String s6 = "";
    if (theFrame.mars.gameDate != null)
    {
      DateFormat fmt = DateFormat.getDateInstance(DateFormat.LONG);
      s1 = fmt.format( theFrame.mars.gameDate.getTime() );
    }
    switch (theFrame.currentView)
    {
      case 1:
        s2 = "Scale 1:" + theFrame.map.getScale();
        double north = theFrame.map.getNorth();
        s3 = "Lat,Long " + north;
        double east = theFrame.map.getEast();
        s3 = s3 + "," + east;
        s4 = "WP : " + theFrame.selectedWayPoint;
        int id = theFrame.mars.Regions.getId(east, north);
        s5 = "Windspeed: " + theFrame.mars.Regions.getWindspeed(id);
        s6 = "Temp " + (theFrame.mars.Regions.getMaxAirTemp(id) - 273) + "'C";
        break;
      case 3:
        Point p = theFrame.settlementView.theView.getActualTile();
        s2 = "";
        if (p != null)
        {
          s2 = "Tile : " + p.x + "," + p.y;

          int c = theFrame.settlementView.theView.getConstructionAt(p);
          s2 = s2 + " c:" + c;
          
          if (c > 0)
          {
            int ct = theFrame.mars.Constructions.getConstructionType(c);
            s2 = s2 + " ct:" + ct;
            
            if (ct > 0)
            {
              s2 = theFrame.mars.ConstructionTypes.getName(ct);
            }
            
            s3 = theFrame.mars.Constructions.getStatusDescription(c);
            s4 = theFrame.mars.Constructions.getMaintenance(c);
          }
        }
        break;
    }
    g.drawString(s1,0,15);
    g.drawString(s2,0,30);
    g.drawString(s3,0,45);
    g.drawString(s4,0,60);
    g.drawString(s5,0,75);
    g.drawString(s6,0,90);
  }
}
