#!/bin/bash

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

input_file="$1"


cat << EOF
<!--
<shared-preset-filters key="$input_file"
                       [presetFilters]="presetFilters"
                       [(currentFilter)]="filter"
                       [ignoredFields]="[]"
                       [filterCtor]="filterCtor"
                       (presetFilterSelected)="onEvent(\$event)"
                       (customPresetFilterSelected)="onEvent(\$event)"
                       (customPresetFilterAdded)="onEvent(\$event)" />
-->
<lumed-template-drawer-container>
    <lumed-display-filter-drawer-button [filterCtor]="filterCtor"
                                        [defaultFilter]="defaultFilter"
                                        (applyFilter)="onEvent(\$event)"
                                        (filterChange)="onEvent(\$event)"
                                        [(filter)]="filter">
        <ng-template #customFilterBox
                     let-filter>
            <lumed-filter-box 
                              [showVertical]="true"
                              [isCollapsedEnabled]="true"
                              [areFiltersButtonsEnabled]="true"
                              [focusFirstErrorOnValidate]="true"
                              [resetFilterAfterInit]="true"
                              (filterReset)="onEvent(\$event)"
                              (onFilterChange)="onEvent(\$event)"
                              name="that-filter-box">
                <lumed-filter-source [source]="filter"
                                     [defaultValues]="defaultFilter"
                                     [collapsedMembers]="[]" />

EOF

$(dirname "$0")/enculumedParseMetadata.bash "$input_file" | while IFS= read -r line; do
    IFS=':' read -r name type lookup <<< "$line"
    if [[ "$type" == "none" ]]; then
cat << EOF
                <lumed-filter-field [model]="filter"
                                    [defaultFilter]="defaultFilter"
                                    label="Unmapped $name"
                                    [isSticky]="true"
                                    memberName="$name" />

EOF
    fi
done

cat << EOF
            </lumed-filter-box>
        </ng-template>
    </lumed-display-filter-drawer-button>

EOF

if [ "$#" -ge 1 ]; then
    $(dirname "$0")/enculumedMakeTable.bash "$2" | sed 's/^/    /'
else
    echo "    TABLE HERE"
fi


cat << EOF

<lumed-template-drawer-container>
EOF









