export class AnswerBodyControl {
	constructor(levyCaseConf, warningCaseConf, nonlevyCaseConf) {
		this.levy = new DatasetControl(levyCaseConf);
		this.warning = new DatasetControl(warningCaseConf);
		this.nonlevy = new DatasetControl(nonlevyCaseConf);
	}
}

export const MACRO_STRING = {
	MACRO_SEQ : "[@일련번호]",
	MACRO_TELNO : "[@전화번호]",
	MACRO_PIC_NM : "[@담당자성명]"
};

export function fnMacroStringInsert(objId, addText) {
	var insertObj = document.getElementById(objId);
    var textVal = insertObj.value;
    var setPosition = insertObj.selectionStart;
   	var beforeTxt = textVal.substring(0, setPosition);
    var afterTxt = textVal.substring(insertObj.selectionEnd, textVal.length);
    insertObj.value = beforeTxt + addText + afterTxt;
    setPosition = setPosition + addText.length;
    insertObj.selectionStart = setPosition;
   	insertObj.selectionEnd = setPosition;
   	insertObj.focus();
}

export function fnMacroWordsReplace(header, footer, body, telno, picNm) {
	var result = header + "\n\n" + body + "\n\n" + footer;
	result = result.replaceAll("＠", "@");
	
	var seq = 1;
	var splited = result.split(MACRO_STRING.MACRO_SEQ);
	var seqCount = splited.length - 1;
	if(seqCount > 0){
		for(; seq <= seqCount; seq++){
			result = result.replace(MACRO_STRING.MACRO_SEQ, seq);
		}
	}
	
	result = result.replaceAll(MACRO_STRING.MACRO_TELNO, telno);
	result = result.replaceAll(MACRO_STRING.MACRO_PIC_NM, picNm);
	
	return result;
}