<script>

    import { storeMdjs } from "@/stores/mdjs.store";
    import { XmlConverter } from "@/libs/xml-converter/xml-converter";

    import InputField from "./elements/InputField.svelte";

    export let field;
    export let list;

    $: isReady = $storeMdjs;

    $: value = $storeMdjs ? converter.getValue($storeMdjs, field.name, field.space)[0] : "";

    const converter = new XmlConverter();

    function onSave(field, value, space) {
        space = space || "md";
        $storeMdjs = converter.setValue($storeMdjs, field, [value], space);
    }
</script>

{#if isReady}
    <InputField
        label={field.label}
        type={field.type}
        {value}
        help={field.help}
        error={field.error}
        field={field.name}
        {list}
        {onSave}
        strong={true}
    />
{/if}

<style>
</style>
