package com.brilliance.isc.doc.convert;

import com.brilliance.mda.runtime.mda.util.MdaUtils;
import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import org.springframework.util.CollectionUtils;

import java.util.List;

public class FormatSwtHelper implements TemplateMethodModelEx {

    @Override
    public Object exec(List list) throws TemplateModelException {
        if (CollectionUtils.isEmpty(list) || list.get(0) == null) {
            return "<p> </p>";
        }
        String value = ((SimpleScalar)list.get(0)).getAsString();
        if(MdaUtils.isEmpty(value)){
            value = " ";
        }
        value = value.replaceAll("\r?\n","</p><p>");

        String formatValue = "<p>"+value+"</p>";

        return formatValue;
    }
}
