package gov.va.isaac.gui.conceptview;

import java.io.IOException;
import java.net.URL;
import java.util.UUID;
import javax.inject.Named;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import gov.va.isaac.gui.util.Images;
import gov.va.isaac.interfaces.gui.constants.ConceptViewMode;
import gov.va.isaac.interfaces.gui.constants.SharedServiceNames;
import gov.va.isaac.interfaces.gui.views.EmbeddableViewI;
import gov.va.isaac.interfaces.gui.views.PopupViewI;
import gov.va.isaac.interfaces.gui.views.commonFunctionality.ConceptViewI;
import gov.va.isaac.util.Utility;
import gov.vha.isaac.ochre.api.component.concept.ConceptSnapshot;
import org.glassfish.hk2.api.PerLookup;
import org.jvnet.hk2.annotations.Service;

@Service @Named(value=SharedServiceNames.DIAGRAM_STYLE)
@PerLookup
public class ConceptView implements PopupViewI, EmbeddableViewI, ConceptViewI  {

	private ConceptViewController controller;

	public ConceptView() throws IOException {
		super();
		URL resource = ConceptViewController.class.getResource("ConceptView.fxml");
		FXMLLoader loader = new FXMLLoader(resource);
		loader.load();
		controller = loader.getController();
	}
	@Override
	public void showView(Window parent) {
		Stage s = new Stage();
		s.initOwner(parent);
		s.initModality(Modality.NONE);
		s.initStyle(StageStyle.DECORATED);

		s.setScene(new Scene(controller.getRoot()));
		s.getIcons().add(Images.CONCEPT_VIEW.getImage());
		s.getScene().getStylesheets().add(ConceptViewController.class.getResource("/isaac-shared-styles.css").toString());
		
		// Title will change after concept is set.
		s.titleProperty().bind(controller.getTitle());
		s.show();
		//doesn't come to the front unless you do this (on linux, at least)
		Platform.runLater(() -> {s.toFront();});
	} 
	
	@Override
	public Region getView() {
		return controller.getRoot();
	}

	@Override
	public void setConcept(int conceptId) {
		Utility.execute(() -> controller.setConcept(conceptId));
	}

	@Override
	public void setConcept(UUID conceptUuid) {
		Utility.execute(() -> controller.setConcept(conceptUuid));
	}
	@Override
	public void viewDiscarded() {
		// TODO need to stop any background operations, dispose of any javaFX hooks that might cause leaks
	}
	@Override
	public UUID getConceptUuid()
	{
		ConceptSnapshot cs = controller.getConceptSnapshot();
		return (cs == null ? null : cs.getPrimordialUuid());
	}
	@Override
	public int getConceptNid()
	{
		ConceptSnapshot cs = controller.getConceptSnapshot();
		return (cs == null ? Integer.MIN_VALUE : cs.getNid());
	}
	@Override
	public void setViewMode(ConceptViewMode mode)
	{
		throw new UnsupportedOperationException();
	}
	@Override
	public ConceptViewMode getViewMode()
	{
		throw new UnsupportedOperationException();
	}
}

@@ -34,16 +34,425 @@
 iew;%0D%0A%0D%0A
+import gov.va.isaac.gui.util.Images;%0D%0Aimport gov.va.isaac.interfaces.gui.constants.ConceptViewMode;%0D%0Aimport gov.va.isaac.interfaces.gui.constants.SharedServiceNames;%0D%0Aimport gov.va.isaac.interfaces.gui.views.EmbeddableViewI;%0D%0Aimport gov.va.isaac.interfaces.gui.views.commonFunctionality.PopupConceptViewI;%0D%0Aimport gov.va.isaac.util.Utility;%0D%0Aimport gov.vha.isaac.ochre.api.component.concept.ConceptSnapshot;%0D%0A
 import j
@@ -468,24 +468,24 @@
 Exception;%0D%0A
-
 import java.
@@ -522,36 +522,8 @@
 D;%0D%0A
-import javax.inject.Named;%0D%0A
 impo
@@ -783,456 +783,26 @@
 ort 
-gov.va.isaac.gui.util.Images;%0D%0Aimport gov.va.isaac.interfaces.gui.constants.ConceptViewMode;%0D%0Aimport gov.va.isaac.interfaces.gui.constants.SharedServiceNames;%0D%0Aimport gov.va.isaac.interfaces.gui.views.EmbeddableViewI;%0D%0Aimport gov.va.isaac.interfaces.gui.views.PopupViewI;%0D%0Aimport gov.va.isaac.interfaces.gui.views.commonFunctionality.ConceptViewI;%0D%0Aimport gov.va.isaac.util.Utility;%0D%0Aimport gov.vha.isaac.ochre.api.component.concept.ConceptSnapshot
+javax.inject.Named
 ;%0D%0Ai
@@ -994,20 +994,8 @@
 ents
- PopupViewI,
  Emb
@@ -1008,16 +1008,21 @@
 eViewI, 
+Popup
 ConceptV

fix an interface change oops