import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext'; import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState'; import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow'; import { useRecoilComponentCallbackState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackState'; import { useRecoilCallback } from 'recoil'; import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab'; export const useUpdatePageLayoutTab = (pageLayoutIdFromProps?: string) => { const pageLayoutId = useAvailableComponentInstanceIdOrThrow( PageLayoutComponentInstanceContext, pageLayoutIdFromProps, ); const pageLayoutDraftState = useRecoilComponentCallbackState( pageLayoutDraftComponentState, pageLayoutId, ); const updatePageLayoutTab = useRecoilCallback( ({ set }) => (tabId: string, updates: Partial) => { set(pageLayoutDraftState, (prev) => ({ ...prev, tabs: prev.tabs.map((tab) => tab.id === tabId ? { ...tab, ...updates } : tab, ), })); }, [pageLayoutDraftState], ); return { updatePageLayoutTab }; };