import {escapeText, noSpaceTmp} from "../../common"

export const articleTemplate = ({front, body, back}) =>
    `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.3 20210610//EN" "https://jats.nlm.nih.gov/archiving/1.3/JATS-archivearticle1-3.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/" xmlns:mml="http://www.w3.org/1998/Math/MathML">${front}${body}${back}</article>`

export const bookPartWrapperTemplate = ({front, body, back}) =>
    `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book-part-wrapper PUBLIC "-//NLM//DTD BITS Book Interchange DTD v2.1 20220202//EN" "https://jats.nlm.nih.gov/extensions/bits/2.1/BITS-book2-1.dtd">
<book-part-wrapper dtd-version="2.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/">
    <book-part book-part-type="chapter" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/" xmlns:mml="http://www.w3.org/1998/Math/MathML">${front}${body}${back}</book-part>
</book-part-wrapper>`

export const darManifest = ({images, title, type}) =>
    noSpaceTmp`<?xml version="1.0" encoding="UTF-8"?>
	<!DOCTYPE manifest PUBLIC "DarManifest 0.1.0" "http://darformat.org/DarManifest-0.1.0.dtd">
<dar>
    <!-- Generated by Fidus Writer -->
    <documents>
        <document id="manuscript" name="${escapeText(title)}" type="${type}" path="manuscript.xml" />
    </documents>
    <assets>${images
        .map(
            image =>
                `<asset id="${image.filename.split(".")[0]}" mime-type="image/${
                    image.filename.split(".")[1] === "png"
                        ? "png"
                        : image.filename.split(".")[1] === "svg"
                          ? "svg+xml"
                          : "jpeg"
                }" name="${image.title}" path="${image.filename}"/>`
        )
        .join("")}</assets>
</dar>`
