import { createContext, useContext, ReactNode } from 'react'; import { useAuthServiceContext } from './AuthService'; interface ConfigServiceContextType { getRelatedPersonHeightOffset: () => string; getScrollableTabHeight: () => string; getGridHeight: () => string; getAdjustedHeight: () => string; } const ConfigServiceContext = createContext(undefined); interface ConfigServiceProviderProps { children: ReactNode; } export const ConfigServiceProvider = ({ children }: ConfigServiceProviderProps) => { const { userRole, USER_ROLES } = useAuthServiceContext(); const RELATED_PERSON_OFFSET = '42px - 16px'; // 58px total const BASE_SCROLLABLE_TAB_OFFSET = '36px - 33px'; // 69px total const getRelatedPersonHeightOffset = (): string => { return userRole === USER_ROLES.RELATED_PERSON ? `- ${RELATED_PERSON_OFFSET}` : ''; }; const getScrollableTabHeight = (): string => { return `calc(100% - ${BASE_SCROLLABLE_TAB_OFFSET} ${getRelatedPersonHeightOffset()})`; }; const getGridHeight = (): string => { return userRole === USER_ROLES.RELATED_PERSON ? `calc(100% - ${RELATED_PERSON_OFFSET})` : '100%'; }; const getAdjustedHeight = (): string => { return userRole === USER_ROLES.RELATED_PERSON ? `calc(100% - ${RELATED_PERSON_OFFSET})` : '100%'; }; const value: ConfigServiceContextType = { getRelatedPersonHeightOffset, getScrollableTabHeight, getGridHeight, getAdjustedHeight }; return ( {children} ); }; export const useConfigServiceContext = (): ConfigServiceContextType => { const context = useContext(ConfigServiceContext); if (context === undefined) { throw new Error('useConfigServiceContext must be used within a ConfigServiceProvider'); } return context; };