import { Workflow } from '@data-wrangling-components/core';
import { useCallback, useMemo } from 'react';
import { useDownloadCsv, useDownloadWorkflow, useDownloadZip } from '../hooks/downloads.js';
import { useHandleCsvUpload, useHandleJsonUpload, useHandleZipUpload } from '../hooks/uploads.js';
export function useProjectMgmtCommands(workflow, tables, outputTables, onUpdateWorkflowJson, onUpdateTables) {
    const downloadPipeline = useDownloadWorkflow(workflow);
    const downloadCsv = useDownloadCsv(outputTables);
    const downloadZip = useDownloadZip(workflow, tables, outputTables);
    const handleJsonUpload = useHandleJsonUpload(onUpdateWorkflowJson);
    const handleCsvUpload = useHandleCsvUpload(onUpdateTables);
    const handleZipUpload = useHandleZipUpload(onUpdateWorkflowJson, onUpdateTables);
    const commands = useMemo(()=>{
        return [
            {
                key: 'open',
                text: 'Open',
                iconProps: icons.openFile,
                subMenuProps: {
                    items: [
                        {
                            key: 'csv',
                            text: 'CSV table',
                            iconProps: icons.table,
                            onClick: handleCsvUpload
                        },
                        {
                            key: 'json',
                            text: 'Pipeline (.json)',
                            iconProps: icons.code,
                            onClick: handleJsonUpload
                        },
                        {
                            key: 'zip',
                            text: 'Zip project',
                            iconProps: icons.zipFolder,
                            onClick: handleZipUpload
                        }, 
                    ]
                }
            },
            {
                key: 'save',
                text: 'Save',
                iconProps: icons.save,
                subMenuProps: {
                    items: [
                        {
                            key: 'csv',
                            text: 'CSV table',
                            iconProps: icons.table,
                            onClick: downloadCsv
                        },
                        {
                            key: 'json',
                            text: 'Pipeline (.json)',
                            iconProps: icons.code,
                            onClick: downloadPipeline
                        },
                        {
                            key: 'zip',
                            text: 'Zip project',
                            iconProps: icons.zipFolder,
                            onClick: downloadZip
                        }, 
                    ]
                }
            }, 
        ];
    }, [
        downloadPipeline,
        downloadCsv,
        downloadZip,
        handleJsonUpload,
        handleCsvUpload,
        handleZipUpload, 
    ]);
    return commands;
}
export function useOnUpdateWorkflowJson(onUpdateWorkflow) {
    return useCallback((wf)=>onUpdateWorkflow(new Workflow(wf)), [
        onUpdateWorkflow
    ]);
}
const icons = {
    save: {
        iconName: 'Save'
    },
    openFile: {
        iconName: 'OpenFile'
    },
    table: {
        iconName: 'Table'
    },
    code: {
        iconName: 'Code'
    },
    zipFolder: {
        iconName: 'ZipFolder'
    }
};
