<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 value = [];
    export let spatialRepresentationTypes = [];

    $: isReady = $storeMdjs;

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

    const converter = new XmlConverter();

    function onSave(fieldName, fieldValue) {
        $storeMdjs = converter.setValue($storeMdjs, fieldName, [fieldValue]);
    }
</script>

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