const items = ref([]) const isLoading = ref(false) const isInitialized = ref(false) export function useTeamOrders() { const { t } = useI18n() const { execute } = useGraphQL() const filters = computed(() => [ { key: 'all', label: t('ordersList.filters.all') }, { key: 'pending', label: t('ordersList.filters.pending') }, { key: 'processing', label: t('ordersList.filters.processing') }, { key: 'in_transit', label: t('ordersList.filters.in_transit') }, { key: 'delivered', label: t('ordersList.filters.delivered') } ]) const selectedFilter = ref('all') const filteredItems = computed(() => { if (selectedFilter.value === 'all') return items.value return items.value.filter(order => order.status === selectedFilter.value) }) const routesForMap = computed(() => filteredItems.value .map(order => ({ uuid: order.uuid, name: order.name, status: order.status, stages: (order.stages || []) .filter((s: any) => s.stageType === 'transport' && s.sourceLatitude && s.sourceLongitude && s.destinationLatitude && s.destinationLongitude) .map((s: any) => ({ fromLat: s.sourceLatitude, fromLon: s.sourceLongitude, toLat: s.destinationLatitude, toLon: s.destinationLongitude, fromName: s.sourceLocationName, toName: s.destinationLocationName, transportType: s.transportType })) })) .filter(order => order.stages.length > 0) ) const load = async () => { isLoading.value = true try { const { GetTeamOrdersDocument } = await import('~/composables/graphql/team/orders-generated') const data = await execute(GetTeamOrdersDocument, {}, 'team', 'orders') items.value = data?.getTeamOrders || [] isInitialized.value = true } catch (e) { console.error('Failed to load orders', e) } finally { isLoading.value = false } } const init = async () => { if (!isInitialized.value && items.value.length === 0) { await load() } } const getStatusVariant = (status: string) => { const variants: Record = { pending: 'warning', processing: 'primary', in_transit: 'info', delivered: 'success', cancelled: 'error' } return variants[status] || 'muted' } const getStatusText = (status: string) => { const texts: Record = { pending: t('ordersDetail.status.pending'), processing: t('ordersDetail.status.processing'), in_transit: t('ordersDetail.status.in_transit'), delivered: t('ordersDetail.status.delivered'), cancelled: t('ordersDetail.status.cancelled') } return texts[status] || status || t('ordersDetail.status.unknown') } return { items, filteredItems, isLoading, filters, selectedFilter, routesForMap, load, init, getStatusVariant, getStatusText } }