package com.eversec.kit.creator.impl.page;

import com.eversec.common.Kv;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * @author: liangxianyou at 2018/8/20 16:08.
 */
public class DetailKit extends PageKit {
    @Override
    public File getFile(String clazz) {
        return new File(filePath(clazz) + "/detail.html");
    }

    @Override
    public String createStr(String clazz, List<Map> fieldList, Map para) {
        Kv kv = createTplData(clazz);
        kv.set("remark", para.get("remark"));
        kv.set("fileDir", getFileDir(clazz));
        kv.set("fieldList", fieldList);

        fieldList.forEach(x->{
            String field  = String.valueOf(x.get("field"));

            if ("2".equals(String.valueOf(x.get("edit")))){
                field =  field +"||"+ x.get("selects");
            }else if ("SELECT_EXT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
                field =  field +"|"+ x.get("selects");
            }else if ("INPUT_DT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
                field =  field +"=dt";
            }else if ("FILE_EXT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
                field =  String.valueOf(x.get("selects"));
            }
            x.put("field", field);
        });

        return engine.getTemplate(tplPath + "front/detailTpl.html").renderToString(kv);
    }
}
