package common.item.tool;

import java.util.List;

import common.color.TextColor;
import common.entity.npc.EntityNPC;
import common.init.UniverseRegistry;
import common.item.ItemMagnetic;
import common.item.ItemStack;
import common.util.BlockPos;
import common.world.World;

public class ItemSpaceNavigator extends ItemMagnetic {
	public static String formatImperialTime(World world, boolean days) {
		long time = world.getDayTime();
		long year = time / UniverseRegistry.EARTH_YEAR;
		long frac = (time * 1000L / UniverseRegistry.EARTH_YEAR) % 1000L;
		if(!world.dimension.getType().time) {
			return String.format("%d.%03d.%03d.M%d" + (days ? " T???.??? D???.???.G?" : ""), world.dimension.getTimeQualifier(), 
					frac, year % 1000L, year / 1000L + 1L);
		}
		long day = time / world.dimension.getRotationalPeriod();
		time = time % world.dimension.getRotationalPeriod();
		return String.format("%d.%03d.%03d.M%d" + (days ? " T%03d.%03d D%03d.%03d.G%d" : ""), world.dimension.getTimeQualifier(), 
				frac, year % 1000L, year / 1000L + 1L,
				time / 1000L, time % 1000L, (day / 1000L) % 1000L, day % 1000L, day / 1000000L);
	}
	
    public ItemSpaceNavigator() {
        this.setMaxAmount(1);
        this.setColor(TextColor.DGREEN);
    }
    
    public String getHotbarText(EntityNPC player, ItemStack stack) {
		BlockPos pos = player.getPosition();
		return TextColor.ORANGE + formatImperialTime(player.worldObj, false) + " / " +
				String.format("%s (%d) bei %d, %d, %d", player.worldObj.dimension.getFormattedName(false) + TextColor.ORANGE, 
				player.worldObj.dimension.getDimensionId(), pos.getX(), pos.getY(), pos.getZ());
    }
    
    public void addInformation(ItemStack stack, EntityNPC player, List<String> tooltip) {
		tooltip.add(TextColor.ORANGE + formatImperialTime(player.worldObj, true));
    	String[] dims = TextColor.stripCodes(player.worldObj.dimension.getFormattedName(true)).split(" / ");
    	for(int z = dims.length - 1; z > 0; z--) {
    		tooltip.add(TextColor.ORANGE + dims[z]);
    	}
		BlockPos pos = player.getPosition();
    	tooltip.add(TextColor.ORANGE + String.format("%s (%d) bei %d, %d, %d", player.worldObj.dimension.getFormattedName(false)
    			 + TextColor.ORANGE, player.worldObj.dimension.getDimensionId(), pos.getX(), pos.getY(), pos.getZ()));
    }
}
