{"version":3,"file":"useLookups.mjs","names":["useState","useEffect","useCallback","usePromotedLookupMethods","usePromotedMethodEntity","apiMutate","useHandleAxiosSnackbar","ConfigService","Lookup","LookupColumn","LookupValue","LookupWithData","SearchBuilder","PromotedMethodMap","key","apiMethodId","ObjectInfo","name","ObjectInfoSearchPage","pageList","ErrorSnackbar","error","message","preCallBack","callback","resolveMethodId","methods","LookupData","data","Record","keyName","valueName","showError","handleErrorSnackbar","useLookups","apiCatalogId","productId","lookups","setLookups","isLegacyLookups","setIsLegacyLookups","loading","setLoading","productIdArg","String","undefined","productIdOrNull","lookupMethods","methodsLoading","getAllMethodId","getDataMethodId","createMethodId","updateMethodId","deleteMethodId","columnMethods","createColumnMethodId","getAllColumnsMethodId","updateColumnMethodId","deleteColumnMethodId","valueMethods","createValueMethodId","getAllValuesMethodId","updateValueMethodId","deleteValueMethodId","searchForLookupKeyTable","search","addFilter","build","response","integrationV2ApiUrl","method","status","checkLegacyLookups","lookupKeyPage","length","execute","methodId","Promise","T","integrationV1ApiUrl","fetchLookups","transformedLookups","map","lookup","udpLookupUdpLookupKey","createLookup","lookupData","Partial","result","requestBody","updateLookup","id","rest","deleteLookup","Pick","fetchColumns","createLookupColumn","columnData","updateLookupColumn","deleteLookupColumn","fetchValues","createLookupValue","valueData","updateLookupValue","deleteLookupValue","fetchLookupData","lookupId","resolveLookupValue","rawValue","overrideKeyName","overrideValueName","keys","val","match","find","row","methodStatus","lookupCreateAvailable","lookupUpdateAvailable","lookupDeleteAvailable","columnCreateAvailable","columnUpdateAvailable","columnDeleteAvailable","valueCreateAvailable","valueUpdateAvailable","valueDeleteAvailable","refetch"],"sources":["../../../src/udp/lookups/useLookups.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react';\nimport { usePromotedLookupMethods } from '../../hooks/usePromotedLookupMethods';\nimport { usePromotedMethodEntity } from '../../hooks/usePromotedMethodEntity';\nimport { apiMutate } from '../../utilities/useAxiosMutate';\nimport { useHandleAxiosSnackbar } from '../../utilities/apiHelpers';\nimport { ConfigService } from '../../configService';\nimport type { Lookup, LookupColumn, LookupValue, LookupWithData } from '@univerus/udp-stencil-component-library';\nimport { SearchBuilder } from '@univerus/udp-stencil-component-library';\n\ninterface PromotedMethodMap {\n  [key: string]: { apiMethodId?: string } | undefined;\n}\n\ninterface ObjectInfo {\n  name: string;\n}\n\ninterface ObjectInfoSearchPage {\n  pageList: ObjectInfo[];\n}\n\ntype ErrorSnackbar = (\n  error: unknown,\n  message: string,\n  preCallBack: unknown,\n  callback: unknown\n) => void;\n\nconst resolveMethodId = (\n  methods: PromotedMethodMap | undefined,\n  key: string\n): string | undefined => methods?.[key]?.apiMethodId;\n\n/**\n * @deprecated Use {@link LookupWithData} from `@univerus/udp-stencil-component-library` instead.\n */\nexport interface LookupData {\n  data: Record<string, string | number>[];\n  keyName: string;\n  valueName: string;\n}\n\nconst showError = (handleErrorSnackbar: ErrorSnackbar, message: string) =>\n  handleErrorSnackbar(null, message, null, null);\n\nexport const useLookups = (\n  apiCatalogId: string | undefined,\n  productId: string | number | undefined\n) => {\n  const [lookups, setLookups] = useState<Lookup[]>([]);\n  const [isLegacyLookups, setIsLegacyLookups] = useState(false);\n  const [loading, setLoading] = useState(false);\n  const { handleErrorSnackbar } = useHandleAxiosSnackbar() as {\n    handleErrorSnackbar: ErrorSnackbar;\n  };\n\n  const productIdArg = productId != null ? String(productId) : undefined;\n  const productIdOrNull = (productId ?? null) as unknown as string;\n\n  // ── Lookup entity methods ────────────────────────────────────\n  const { data: lookupMethods, loading: methodsLoading } =\n    usePromotedLookupMethods(apiCatalogId, productIdArg) as {\n      data: PromotedMethodMap | undefined;\n      loading: boolean;\n    };\n\n  const getAllMethodId = resolveMethodId(lookupMethods, 'unityBaseGetAllMethod');\n  const getDataMethodId =\n    resolveMethodId(lookupMethods, 'unityBaseGetDataMethod') ??\n    resolveMethodId(lookupMethods, 'unityBaseGetMethod');\n  const createMethodId = resolveMethodId(lookupMethods, 'unityBaseCreateMethod');\n  const updateMethodId = resolveMethodId(lookupMethods, 'unityBaseUpdateMethod');\n  const deleteMethodId = resolveMethodId(lookupMethods, 'unityBaseDeleteMethod');\n\n  // ── LookupColumn entity methods ──────────────────────────────\n  const { data: columnMethods } = usePromotedMethodEntity(\n    'UdpLookupColumn',\n    true,\n    apiCatalogId,\n    productIdOrNull\n  ) as { data: PromotedMethodMap | undefined };\n\n  const createColumnMethodId = resolveMethodId(columnMethods, 'unityBaseCreateMethod');\n  const getAllColumnsMethodId = resolveMethodId(columnMethods, 'unityBaseGetAllMethod');\n  const updateColumnMethodId = resolveMethodId(columnMethods, 'unityBaseUpdateMethod');\n  const deleteColumnMethodId = resolveMethodId(columnMethods, 'unityBaseDeleteMethod');\n\n  // ── LookupValue entity methods ───────────────────────────────\n  const { data: valueMethods } = usePromotedMethodEntity(\n    'UdpLookupValue',\n    true,\n    apiCatalogId,\n    productIdOrNull\n  ) as { data: PromotedMethodMap | undefined };\n\n  const createValueMethodId = resolveMethodId(valueMethods, 'unityBaseCreateMethod');\n  const getAllValuesMethodId = resolveMethodId(valueMethods, 'unityBaseGetAllMethod');\n  const updateValueMethodId = resolveMethodId(valueMethods, 'unityBaseUpdateMethod');\n  const deleteValueMethodId = resolveMethodId(valueMethods, 'unityBaseDeleteMethod');\n\n  // ── Check ObjectInfo table for LookupKey so know if they are using legacy lookups ────────────────────────────────\n  const searchForLookupKeyTable = useCallback(async () => {\n    const search = new SearchBuilder().addFilter(\"Name\", \"LookupKey\").build();\n\n    const response = await apiMutate(\n      ConfigService.integrationV2ApiUrl,\n      `udpObjectInfo/search`,\n      { method: 'post' },\n      { data: search }\n    ) as { status?: number; data?: ObjectInfoSearchPage } | undefined;\n\n    return response?.status === 200 || response?.status === 201 ? response.data ?? null : null;\n  }, []);\n\n  const checkLegacyLookups = useCallback(async () => {\n    const lookupKeyPage = await searchForLookupKeyTable();\n    // If the lookup key table doesn't exist, then we know it's legacy\n    if (!lookupKeyPage || lookupKeyPage.pageList.length === 0) {\n      setIsLegacyLookups(true);\n    }\n  }, [searchForLookupKeyTable]);\n\n  useEffect(() => {\n    void checkLegacyLookups();\n  }, [checkLegacyLookups]);\n\n  // ── Helper: execute a method ─────────────────────────────────\n  const execute = useCallback(\n    async <T = unknown>(\n      methodId: string | undefined,\n      data: Record<string, unknown> = {}\n    ): Promise<T | null> => {\n      if (!methodId) return null;\n      try {\n        const response = (await apiMutate(\n          ConfigService.integrationV1ApiUrl,\n          `apimethod/executeQueryWithParameters/${methodId}`,\n          { method: 'post' },\n          { data }\n        )) as { status?: number; data?: T } | undefined;\n        if (response?.status === 200 || response?.status === 201) {\n          return response.data ?? null;\n        }\n      } catch {\n        return null;\n      }\n      return null;\n    },\n    []\n  );\n\n  // ── Fetch all lookups ────────────────────────────────────────\n  const fetchLookups = useCallback(async () => {\n    if (!getAllMethodId) return;\n    setLoading(true);\n    try {\n      const data = await execute<Lookup[]>(getAllMethodId);\n      const transformedLookups = data?.map((lookup) => {\n        // If the keyName has a value, we assume this is a legacy lookup and transform it to the new format on the fly.\n        if (!!lookup.keyName) {\n          setIsLegacyLookups(true);\n          return {\n            ...lookup,\n            udpLookupUdpLookupKey: [{ name: lookup.keyName }],\n          };\n        }\n        return lookup;\n      });\n      setLookups(transformedLookups ?? []);\n    } catch {\n      showError(handleErrorSnackbar, 'Failed to fetch lookups');\n    } finally {\n      setLoading(false);\n    }\n  }, [getAllMethodId, execute, handleErrorSnackbar]);\n\n  useEffect(() => {\n    void fetchLookups();\n  }, [fetchLookups]);\n\n  // ── CRUD: Lookup ─────────────────────────────────────────────\n  const createLookup = useCallback(\n    async (lookupData: Partial<Lookup>) => {\n      const result = await execute<Lookup>(createMethodId, { requestBody: lookupData });\n      if (!result) showError(handleErrorSnackbar, 'Failed to create lookup');\n      return result;\n    },\n    [createMethodId, execute, handleErrorSnackbar]\n  );\n\n  const updateLookup = useCallback(\n    async (lookupData: { id: string;[key: string]: unknown }) => {\n      const { id, ...rest } = lookupData;\n      const result = await execute<Lookup>(updateMethodId, { id, requestBody: rest });\n      if (!result) showError(handleErrorSnackbar, 'Failed to update lookup');\n      return result;\n    },\n    [updateMethodId, execute, handleErrorSnackbar]\n  );\n\n  const deleteLookup = useCallback(\n    async (lookupData: Pick<Lookup, 'id'>) => {\n      const result = await execute<Lookup>(deleteMethodId, { id: lookupData.id });\n      if (!result) showError(handleErrorSnackbar, 'Failed to delete lookup');\n      return result;\n    },\n    [deleteMethodId, execute, handleErrorSnackbar]\n  );\n\n  // ── CRUD: LookupColumn ──────────────────────────────────────\n  const fetchColumns = useCallback(\n    async (): Promise<LookupColumn[]> => {\n      const result = await execute<LookupColumn[]>(getAllColumnsMethodId);\n      return result ?? [];\n    },\n    [getAllColumnsMethodId, execute]\n  );\n\n  const createLookupColumn = useCallback(\n    async (columnData: Partial<LookupColumn>) => {\n      const result = await execute<LookupColumn>(createColumnMethodId, { requestBody: columnData });\n      if (!result) showError(handleErrorSnackbar, 'Failed to create lookup column');\n      return result;\n    },\n    [createColumnMethodId, execute, handleErrorSnackbar]\n  );\n\n  const updateLookupColumn = useCallback(\n    async (columnData: { id: string;[key: string]: unknown }) => {\n      const { id, ...rest } = columnData;\n      const result = await execute<LookupColumn>(updateColumnMethodId, { id, requestBody: rest });\n      if (!result) showError(handleErrorSnackbar, 'Failed to update lookup column');\n      return result;\n    },\n    [updateColumnMethodId, execute, handleErrorSnackbar]\n  );\n\n  const deleteLookupColumn = useCallback(\n    async (columnData: Pick<LookupColumn, 'id'>) => {\n      const result = await execute<LookupColumn>(deleteColumnMethodId, { id: columnData.id });\n      if (!result) showError(handleErrorSnackbar, 'Failed to delete lookup column');\n      return result;\n    },\n    [deleteColumnMethodId, execute, handleErrorSnackbar]\n  );\n\n  // ── CRUD: LookupValue ───────────────────────────────────────\n  const fetchValues = useCallback(\n    async (): Promise<LookupValue[]> => {\n      const result = await execute<LookupValue[]>(getAllValuesMethodId);\n      return result ?? [];\n    },\n    [getAllValuesMethodId, execute]\n  );\n\n  const createLookupValue = useCallback(\n    async (valueData: Partial<LookupValue>) => {\n      const result = await execute<LookupValue>(createValueMethodId, { requestBody: valueData });\n      if (!result) showError(handleErrorSnackbar, 'Failed to create lookup value');\n      return result;\n    },\n    [createValueMethodId, execute, handleErrorSnackbar]\n  );\n\n  const updateLookupValue = useCallback(\n    async (valueData: { id: string;[key: string]: unknown }) => {\n      const { id, ...rest } = valueData;\n      const result = await execute<LookupValue>(updateValueMethodId, { id, requestBody: rest });\n      if (!result) showError(handleErrorSnackbar, 'Failed to update lookup value');\n      return result;\n    },\n    [updateValueMethodId, execute, handleErrorSnackbar]\n  );\n\n  const deleteLookupValue = useCallback(\n    async (valueData: Pick<LookupValue, 'id'>) => {\n      const result = await execute<LookupValue>(deleteValueMethodId, { id: valueData.id });\n      if (!result) showError(handleErrorSnackbar, 'Failed to delete lookup value');\n      return result;\n    },\n    [deleteValueMethodId, execute, handleErrorSnackbar]\n  );\n\n  // ── Lookup resolution ─────────────────────────────────────────\n  /**\n   * Fetch a single lookup's full data (rows + keyName/valueName) by ID.\n   */\n  const fetchLookupData = useCallback(\n    async (lookupId: string): Promise<LookupWithData | null> => {\n      return execute<LookupWithData>(getDataMethodId, { id: lookupId });\n    },\n    [getDataMethodId, execute]\n  );\n\n  /**\n   * Resolve a raw value through a lookup.\n   * Returns the display value, or the raw value if resolution fails.\n   *\n   * @param lookupId - The lookup to resolve against\n   * @param rawValue - The raw value to look up (matched against keyName)\n   * @param overrideKeyName - Optional override for which field to match on\n   * @param overrideValueName - Optional override for which field to return\n   */\n  const resolveLookupValue = useCallback(\n    async (\n      lookupId: string,\n      rawValue: string | number,\n      overrideKeyName?: string,\n      overrideValueName?: string\n    ): Promise<string | number> => {\n      if (rawValue == null) return rawValue;\n      const lookupData = await fetchLookupData(lookupId);\n      if (!lookupData?.data) return rawValue;\n\n      const keys = lookupData.udpLookupUdpLookupKey ?? (lookupData.keyName ? [{ name: lookupData.keyName }] : []);\n      const key: string = overrideKeyName ?? keys[0]?.name ?? '';\n      const val: string = overrideValueName ?? lookupData.valueName;\n      if (!key || !val) return rawValue;\n\n      const match = lookupData.data.find(\n        (row) => String(row[key]) === String(rawValue)\n      );\n      return match ? match[val] : rawValue;\n    },\n    [fetchLookupData]\n  );\n\n  // ── Method availability ──────────────────────────────────────\n  const methodStatus = {\n    lookupCreateAvailable: !!createMethodId,\n    lookupUpdateAvailable: !!updateMethodId,\n    lookupDeleteAvailable: !!deleteMethodId,\n    columnCreateAvailable: !!createColumnMethodId,\n    columnUpdateAvailable: !!updateColumnMethodId,\n    columnDeleteAvailable: !!deleteColumnMethodId,\n    valueCreateAvailable: !!createValueMethodId,\n    valueUpdateAvailable: !!updateValueMethodId,\n    valueDeleteAvailable: !!deleteValueMethodId,\n  };\n\n  return {\n    lookups,\n    loading: loading || methodsLoading,\n    refetch: fetchLookups,\n    methodStatus,\n    // Lookup CRUD\n    createLookup,\n    updateLookup,\n    deleteLookup,\n    // Column CRUD\n    fetchColumns,\n    createLookupColumn,\n    updateLookupColumn,\n    deleteLookupColumn,\n    // Value CRUD\n    fetchValues,\n    createLookupValue,\n    updateLookupValue,\n    deleteLookupValue,\n    // Lookup resolution\n    fetchLookupData,\n    resolveLookupValue,\n    // Legacy flag\n    isLegacyLookups,\n  };\n};\n"],"mappings":";;;;;;;;AA4BA,MAAMyB,mBACJC,SACAZ,QACuBY,UAAUZ,MAAMC;AAWzC,MAAMiB,aAAaC,qBAAoCX,YACrDW,oBAAoB,MAAMX,SAAS,MAAM,KAAK;AAEhD,MAAaY,cACXC,cACAC,cACG;CACH,MAAM,CAACC,SAASC,cAActC,SAAmB,EAAE,CAAC;CACpD,MAAM,CAACuC,iBAAiBC,sBAAsBxC,SAAS,MAAM;CAC7D,MAAM,CAACyC,SAASC,cAAc1C,SAAS,MAAM;CAC7C,MAAM,EAAEiC,wBAAwB3B,wBAAwB;CAIxD,MAAMqC,eAAeP,aAAa,OAAOQ,OAAOR,UAAU,GAAGS,KAAAA;CAC7D,MAAMC,kBAAmBV,aAAa;CAGtC,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