import { useMemo } from 'react'; import { useQuery } from '@tanstack/react-query'; import { api } from '../lib/api'; import type { ApiResponse } from '../lib/api'; import type { BookingService } from './useDoctorBookingServices'; import type { ResourceServiceOffering } from '../types'; /** * سرویس‌های قابلِ رزروِ یک منبع، به همان شکلِ سرویس‌های پزشک. * * نگاشت عمدی است: فرمِ انتخاب سرویس (`ServiceSlotPicker`) یک قرارداد دارد — بخش، * نام، مدت — و ساختنِ نسخهٔ دومش برای منبع یعنی دو فرم که با هم درمی‌روند. * * مدتِ مؤثر مبناست نه `duration_minutes` خام: خالی‌بودنِ ستون یعنی «ارث از سطح * بالاتر»، و نمایشش به‌صورت صفر همان دستگاه را بی‌مدت نشان می‌داد. */ export function useResourceBookingServices(resourceUuid: string | null | undefined) { const q = useQuery>({ queryKey: ['resource-services', resourceUuid], queryFn: () => api.get(`/api/v1/resource/${resourceUuid}/services`), enabled: !!resourceUuid, }); const services: BookingService[] = useMemo( () => (q.data?.data ?? []) .filter(o => o.active && o.service_section) .map(o => ({ uuid: o.service_uuid, name: o.service_name, duration_minutes: o.effective_duration_minutes, price_rials: o.effective_price_rials, service_section: o.service_section!, })), [q.data], ); return { services, isLoading: q.isLoading }; }