package net.cherokeedictionary.lyx;

import org.apache.commons.lang3.StringUtils;

public class CrossReference {
	private String syllabary;
	private String ref;
	private int forEntry;

	public CrossReference() {
	}

	public CrossReference(int toEntry, String raw_ref, String syllabary) {
		this.forEntry=toEntry;
		this.ref=raw_ref;
		this.syllabary=syllabary;
	}

	public String getLyxCode(boolean nolayout) {
		StringBuilder sb = new StringBuilder();
		if (!nolayout) {
			sb.append("\\begin_layout Standard\n");		
		}
		sb.append("\\series bold\n");
		sb.append(syllabary);
		sb.append("\n");
		sb.append("\\series default\n");
		if (ref.contains("(")) {
			String sub = StringUtils.substringBetween(ref, "(", ")");
			sub=StringUtils.strip(sub);
			sb.append(" \\begin_inset Quotes eld\n\\end_inset\n");
			sb.append(sub);
			sb.append("\n\\begin_inset Quotes erd\n\\end_inset\n");
		}
//		sb.append(" (pg \\begin_inset CommandInset ref\n");
//		sb.append("LatexCommand pageref\n");
//		sb.append("reference \"");
//		sb.append(forEntry);
//		sb.append("\"\n");
//		sb.append("\\end_inset\n");
//		sb.append(")\n");
		if (!nolayout) { 
			sb.append("\\end_layout\n");
		}
		return sb.toString();
	}
	public String getLyxCode() {
		return getLyxCode(false);
	}
}

@@ -883,18 +883,16 @@
 %22);%0A%09%09%7D%0A
-//
 %09%09sb.app
@@ -929,34 +929,32 @@
 dInset ref%5Cn%22);%0A
-//
 %09%09sb.append(%22Lat
@@ -972,26 +972,24 @@
 ageref%5Cn%22);%0A
-//
 %09%09sb.append(
@@ -1001,26 +1001,24 @@
 rence %5C%22%22);%0A
-//
 %09%09sb.append(
@@ -1028,18 +1028,16 @@
 Entry);%0A
-//
 %09%09sb.app
@@ -1045,26 +1045,24 @@
 nd(%22%5C%22%5Cn%22);%0A
-//
 %09%09sb.append(
@@ -1083,10 +1083,8 @@
 %22);%0A
-//
 %09%09sb

enable page numbers for cf's