<!--
    常规的全页展示数据表格
-->
<script lang="ts">

    import type {FunFilter} from "@ticatec/uniface-element/ListBox";

    import type {ActionsColumn, DataColumn, IndicatorColumn} from "@ticatec/uniface-element/DataTable";
    import {FullListDataManager} from "@ticatec/app-data-manager";
    import {onMount} from "svelte";
    import type {FullListDataService} from "@ticatec/app-data-service";
    import i18nRes from "../i18nRes";
    import type {PageInitialize} from "@ticatec/uniface-micro-frame/common";
    import LoadDataErrorPage from "../common/LoadDataErrorPage.svelte";
    import SimpleDataTableBoard from "./SimpleDataTableBoard.svelte";
    import type {GetRowFontStyle} from "@ticatec/uniface-element/types";

    export let dataManager: FullListDataManager<FullListDataService>;
    export let initializeData: PageInitialize | undefined = undefined;
    export let indicatorColumn: IndicatorColumn;
    export let columns: Array<DataColumn>;
    export let actionsColumn: ActionsColumn | undefined = undefined;
    export let selectedRows: Array<any> = [];
    export let list: Array<any>;
    export let filterFun: FunFilter | null = null;
    export let busyIndicator: string | null = null;
    export let rowHeight: number = null as unknown as number;
    export let roundTable: boolean = false;
    export let emptyIndicator: string | undefined = undefined;
    export let getRowFontStyle: GetRowFontStyle | undefined = undefined;

    let loaded: boolean = false;
    let error: any;

    export const loadList = async () => {
        window.Indicator.show(busyIndicator ?? 'Loading...');
        try {
            await dataManager.loadData();
            list = dataManager.list;
        } finally {
            window.Indicator.hide();
        }
    }

    onMount(async () => {
        window.Indicator.show(busyIndicator ?? i18nRes.app.busyIndicator);
        try {
            await initializeData?.();
            await dataManager.loadData();
            list = dataManager.list;
        } catch (ex) {
            console.error('Module loading with error', ex);
            error = ex;
        } finally {
            loaded = true;
            window.Indicator?.hide();
        }
    })

</script>
{#if loaded}
    {#if error}
        <LoadDataErrorPage message={error}/>
    {:else }
        <SimpleDataTableBoard {filterFun} {rowHeight} {roundTable} {emptyIndicator} {getRowFontStyle} {indicatorColumn} {columns}
                               {actionsColumn} bind:selectedRows {list}>
        </SimpleDataTableBoard>
    {/if}
{/if}