#!/bin/bash

# Check if the input file is provided
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <input-file>"
    exit 1
fi

input_file="$1"


cat << EOF

<lumed-form-mdc #form="ngForm"
                name="form-data-demo"
                ngForm
                [form]="form">
    <lumed-data-form name="Form DATA"
                     [modelPrototype]="modelPrototype"
                     [disabledFields]="[]"
                     [model]="model"
                     (eventChannel)="onEvent(\$event)"
                     [templates]="{
EOF

$(dirname "$0")/enculumedParseMetadata.bash "$input_file" | while IFS= read -r line; do
    IFS=':' read -r name type lookup <<< "$line"
    if [[ -n "$type" ]]; then
        echo "                          $name : ${name}Template,"
    fi
done

cat << EOF
                    }"
                    (submitted)="onEvent(\$event)">
    </lumed-data-form>
</lumed-form-mdc>

EOF

$(dirname "$0")/enculumedParseMetadata.bash "$input_file" | while IFS= read -r line; do
    IFS=':' read -r name type lookup <<< "$line"
    if [[ -n "$type" ]] && [[ -n "$lookup" ]]; then
cat << EOF

<ng-template #${name}Template
             let-dataContext="dataContext">
    <lumed-data-field name="${name}Field"
                      [modelPrototype]="modelPrototype"
                      displayAdapterType="${type}"
                      memberName="${name}"
                      lookupProviderKey="$lookup"
                      [model]="dataContext.model" />
</ng-template>

EOF
    elif [[ -n "$type" ]]; then
cat << EOF

<ng-template #${name}Template
             let-dataContext="dataContext">
    <lumed-data-field name="${name}Field"
                      [modelPrototype]="modelPrototype"
                      displayAdapterType="${type}"
                      memberName="${name}"
                      lookupProviderKey="$lookup"
                      [model]="dataContext.model" />
</ng-template>

EOF
    fi
done








