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/7 10:15.
 */
public class EditKit extends PageKit {
    @Override
    public File getFile(String clazz) {
        return new File(filePath(clazz) + "/edit.html");
    }

    @Override
    public String createStr(String clazz, List<Map> fieldList, Map para) {
        fieldList.forEach(x->{
            x.put("isMust", isMust(x));
        });

        Kv kv = createTplData(clazz);
        kv.set("remark", para.get("remark"));
        kv.set("fileDir", getFileDir(clazz));
        kv.set("fieldList", fieldList);
        kv.set("hasEdit2", hasEdit2(fieldList));

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

    private boolean hasEdit2(List<Map> fieldList) {
        return fieldList.stream().filter(x->"2".equalsIgnoreCase(String.valueOf(x.get("edit")))).count() > 0;
    }
}
