package model.component.visual;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import api.IComponent;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import utility.SingleProperty;

/**
 * Component to hold an imagePath.
 *
 * @author Rhondu Smithwick
 */
public class ImagePath implements IComponent {

	private static final String PROPERTIES_DIR = "spriteProperties.";
	/**
	 * The singleProperty.
	 */
	private SingleProperty<String> imagePath;
	//private ObjectProperty<ImageView> imageViewProperty = new SimpleObjectProperty<ImageView>();	
	private final String spriteName;
	

	public ImagePath() {
		this("resources/RhonduSmithwick.JPG");

	}

	/**
	 * Construct with no animation.
	 *
	 * @param imagePath
	 *            starting value
	 */


	public ImagePath(String imagePath) { // TODO: place default in resource file
		this("resources/RhonduSmithwick.JPG", "Rhodu");
        ImageView imageView = new ImageView(new Image(new File(imagePath).toURI().toString()));
       // imageViewProperty.set(imageView);
		this.imagePath = new SingleProperty<>("ImagePath", imagePath);
		//this.imageViewProperty.get().setPreserveRatio(true);
	}

	// TODO: IMPORTANT NOTE: I forgot to account for columns!
	/**
	 * Construct with starting values.
	 *
	 * @param imagePath
	 *            String path to image
	 * @param imageWidth
	 *            width of image
	 * @param imageHeight
	 *            height of image
	 * @param spritesheetPath
	 *            String path to spritesheet
	 * @param width
	 *            width of viewport
	 * @param height
	 *            height of viewport
	 * @param offsetX
	 *            offset in x-direction
	 * @param offsetX
	 *            offset in y-direction
	 */
	public ImagePath(String spritesheetPath, String spriteName) {
		this.imagePath = new SingleProperty<>("SpritesheetPath", spritesheetPath);
		this.spriteName = spriteName;
		File resource = new File(spritesheetPath);
		Image image = new Image(resource.toURI().toString());
		//this.imageViewProperty.set(new ImageView(image));
		//this.imageViewProperty.get().setPreserveRatio(true);
	}

	/**
	 * Get the imagePath property.
	 *
	 * @return impagePath string property
	 */



//	public SimpleObjectProperty<Double> imageWidthProperty() {
//		return imageSizeProperty.property1();
//	}
//
//	public SimpleObjectProperty<Double> imageHeightProperty() {
//		return imageSizeProperty.property2();
//	}

	/*public double getImageWidth() {
		return imageViewProperty.get().getBoundsInParent().getWidth();
	}

	public void setImageWidth(double imageWidth) {
		this.imageViewProperty.get().setFitWidth(imageWidth);
		System.out.println("Image height set to: " + this.getImageHeight());
	}

	public double getImageHeight() {
		return imageViewProperty.get().getBoundsInParent().getHeight();
	}

	public void setImageHeight(double imageHeight) {
		this.imageViewProperty.get().setFitHeight(imageHeight);
		System.out.println("Image height set to: " + this.getImageWidth());
	}*/

	@Override
	public List<SimpleObjectProperty<?>> getProperties() {
		return imagePath.getProperties();
	}


	//public ImageView getImageView() {	
		//return imageViewProperty.get();
	//}

	public String getSpriteSheet(){
		return this.imagePath.property1().get();
	}
	
	public String getSpriteName(){
		return this.spriteName;
	}

	public String getSpriteProperties() {
		return PROPERTIES_DIR + this.spriteName;

	}

	public String getImagePath() {
		return imagePath.property1().get();
	}


}
@@ -51,33 +51,8 @@
 le;%0A
-import java.util.Arrays;%0A
 impo
@@ -70,17 +70,16 @@
 l.List;%0A
-%0A
 import a
@@ -97,53 +97,8 @@
 nt;%0A
-import javafx.beans.property.ObjectProperty;%0A
 impo
@@ -512,16 +512,46 @@
 gePath;%0A
+%09private ImageView imageView;%0A
 %09//priva
@@ -980,26 +980,16 @@
         
-ImageView 
 imageVie
@@ -1058,16 +1058,58 @@
 ng()));%0A
+        imageView.setPreserveRatio(true);%0A
        /
@@ -2096,26 +2096,24 @@
 tring());%0A%09%09
-//
 this.imageVi
@@ -2114,28 +2114,19 @@
 mageView
-Property.set
+ = 
 (new Ima
@@ -2139,31 +2139,24 @@
 (image));%0A%09%09
-//this.
 imageViewPro
@@ -2148,38 +2148,24 @@
 %0A%09%09imageView
-Property.get()
 .setPreserve
@@ -2493,18 +2493,16 @@
 %0A//%09%7D%0A%0A%09
-/*
 public d
@@ -2539,38 +2539,24 @@
 rn imageView
-Property.get()
 .getBoundsIn
@@ -2626,29 +2626,24 @@
 eWidth) %7B%0A%09%09
-this.
 imageViewPro
@@ -2635,38 +2635,24 @@
 %0A%09%09imageView
-Property.get()
 .setFitWidth
@@ -2792,30 +2792,16 @@
 mageView
-Property.get()
 .getBoun
@@ -2878,29 +2878,24 @@
 Height) %7B%0A%09%09
-this.
 imageViewPro
@@ -2887,38 +2887,24 @@
 %0A%09%09imageView
-Property.get()
 .setFitHeigh
@@ -2991,18 +2991,16 @@
 h());%0A%09%7D
-*/
 %0A%0A%09@Over
@@ -3102,18 +3102,16 @@
 ;%0A%09%7D%0A%0A%0A%09
-//
 public I
@@ -3139,18 +3139,16 @@
 () %7B%09%0A%09%09
-//
 return i
@@ -3159,27 +3159,11 @@
 View
-Property.get()
 ;%0A%09
-//
 %7D%0A%0A%09

fix some imagepath stuf