package edu.tamu.framework.wro4j.processors;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

import org.apache.commons.io.IOUtils;

import ro.isdc.wro.model.resource.ResourceType;
import ro.isdc.wro.model.resource.SupportedResourceType;
import ro.isdc.wro.model.resource.processor.ResourcePostProcessor;
import edu.tamu.framework.service.ThemeManagerService;

@SupportedResourceType(ResourceType.CSS)
public class RepoPostProcessor implements ResourcePostProcessor {
	private ThemeManagerService themeManagerService;
	
	public RepoPostProcessor(ThemeManagerService themeManagerService) {
		super();
		this.themeManagerService = themeManagerService;
	}
	public void process(final Reader reader, final Writer writer) throws IOException {
		//TODO hook into a DB repo to get theme specific SCSS vars

		//add the custom content
/*
		writer.append("/*This filter added these variables to the SCSS:\n\n ");
		writer.append("* $primary: #500000;\n");
		writer.append("* $secondary: #3c0000;\n");
		writer.append("* $linkColor: #337ab7;\n");
		writer.append("* $baseFontSize: 14px;\n");
*/
//		writer.append("/\n\n");

//		writer.append("*/\n\n");
/*		
		writer.append("$primary: #500000;");
		writer.append("$secondary: #3c0000;");
		writer.append("$linkColor: #337ab7;");
		writer.append("$baseFontSize: 14px;");
*/
		/*
		CoreTheme currentTheme = themeManager.getCurrentTheme();
		
		writer.append("/*The RepoPostProcessor added these variables to the SCSS:\n\n ");
		currentTheme.getProperties().forEach(property -> {
			try {
				writer.append("$"+property.getPropertyName().getName()+": "+property.getValue());
				writer.append("* "+property.getPropertyName().getName()+": "+property.getValue()+"\n");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		});
		*/
//		writer.append("*/\n\n");
		
		//read in the merged SCSS and add it after the custom content 
		String resourceText = "/* The custom PostProcessor fetched the following SASS vars from the ThemeManagerService: */\n\n"; 
		resourceText += themeManagerService.getFormattedProperties();
		writer.append(resourceText);
		writer.append(IOUtils.toString(reader));
		reader.close();
		writer.close();
	}  
}

@@ -761,1116 +761,8 @@
 n %7B%0A
-%09%09//TODO hook into a DB repo to get theme specific SCSS vars%0A%0A%09%09//add the custom content%0A/*%0A%09%09writer.append(%22/*This filter added these variables to the SCSS:%5Cn%5Cn %22);%0A%09%09writer.append(%22* $primary: #500000;%5Cn%22);%0A%09%09writer.append(%22* $secondary: #3c0000;%5Cn%22);%0A%09%09writer.append(%22* $linkColor: #337ab7;%5Cn%22);%0A%09%09writer.append(%22* $baseFontSize: 14px;%5Cn%22);%0A*/%0A//%09%09writer.append(%22/%5Cn%5Cn%22);%0A%0A//%09%09writer.append(%22*/%5Cn%5Cn%22);%0A/*%09%09%0A%09%09writer.append(%22$primary: #500000;%22);%0A%09%09writer.append(%22$secondary: #3c0000;%22);%0A%09%09writer.append(%22$linkColor: #337ab7;%22);%0A%09%09writer.append(%22$baseFontSize: 14px;%22);%0A*/%0A%09%09/*%0A%09%09CoreTheme currentTheme = themeManager.getCurrentTheme();%0A%09%09%0A%09%09writer.append(%22/*The RepoPostProcessor added these variables to the SCSS:%5Cn%5Cn %22);%0A%09%09currentTheme.getProperties().forEach(property -%3E %7B%0A%09%09%09try %7B%0A%09%09%09%09writer.append(%22$%22+property.getPropertyName().getName()+%22: %22+property.getValue());%0A%09%09%09%09writer.append(%22* %22+property.getPropertyName().getName()+%22: %22+property.getValue()+%22%5Cn%22);%0A%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09%0A%09%09%7D);%0A%09%09*/%0A//%09%09writer.append(%22*/%5Cn%5Cn%22);%0A%09%09%0A
 %09%09//

remove wip code from post processor