import React, { useState, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { MainLayout } from '@/components/layout/MainLayout.tsx'; import PageHeader from '@/components/layout/PageHeader.tsx'; import ResourceFlowList from '@/components/resource-flow/ResourceFlowList.tsx'; import ResourceFlowWizard from '@/components/resource-flow/ResourceFlowWizard.tsx'; import { Container, Flex, Stack } from '@/components/ui/layout'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card.tsx'; import Button from '@/components/ui/Button.tsx'; import Select from '@/components/ui/Select.tsx'; import { Label, FormField } from '@/components/ui'; import { useTranslation } from '@/hooks/useI18n.tsx'; import { useOrganizations } from '@/hooks/useOrganizations.ts'; import { useNavigation } from '@/hooks/useNavigation.tsx'; import type { BackendOrganization } from '@/schemas/backend/organization'; import type { ResourceDirection } from '@/schemas/backend/resource-flow'; const ResourceFlowsPage = () => { const { t } = useTranslation(); const navigate = useNavigate(); const { handleBackNavigation, handleFooterNavigate } = useNavigation(); const { organizations, isLoading: isLoadingOrgs } = useOrganizations(); const [selectedOrganizationId, setSelectedOrganizationId] = useState(''); const [isWizardOpen, setIsWizardOpen] = useState(false); const [wizardDirection, setWizardDirection] = useState('input'); // Get selected organization details const selectedOrganization = useMemo(() => { return organizations?.find(org => org.ID === selectedOrganizationId) || null; }, [organizations, selectedOrganizationId]); const handleAddResourceFlow = (direction: ResourceDirection) => { if (!selectedOrganizationId) { // If no organization selected, show organization selector or redirect return; } setWizardDirection(direction); setIsWizardOpen(true); }; const handleViewMatches = (resourceId: string) => { navigate(`/resource-flow/${resourceId}/matches`); }; const handleWizardClose = () => { setIsWizardOpen(false); }; const handleWizardSuccess = () => { setIsWizardOpen(false); // Optionally refresh data or show success message }; const organizationOptions = useMemo(() => { return organizations?.map(org => ({ value: org.ID, label: org.Name, })) || []; }, [organizations]); return ( {/* Organization Selector */} {t('resourceFlows.selectOrganization')}