{"version":3,"file":"use-api2.mjs","sources":["../../../../../../../../packages/components/editor/src/hooks/use-api.ts"],"sourcesContent":["import { type ComputedRef, unref } from 'vue'\nimport { tavI18n } from '@tav-ui/locales'\nimport { type UseRequestHandleApiDefaultOptions } from '@tav-ui/components/file/src/hooks/use-request'\nimport { type FileUploadApiResponseRecord } from '@tav-ui/components/file/src/components/FileUpload'\nimport {\n  type EditorProps,\n  // type FileUploadImagePropResponse,\n  // type FileUploadImageResponseRecord,\n} from '../typings'\n\nexport function useApi(options: { mergedProps: ComputedRef<EditorProps> }) {\n  const { mergedProps } = options\n\n  //:========================================: api actions :========================================://\n  // function uploadImageVarsApiOptions(apiParams: EditorProps['apiParams']) {\n  //   if (!mergedProps.value.apiUploadImageVars) {\n  //     console.warn('[tavui TaEditor] apiUploadImageVars is undefined')\n  //     return\n  //   }\n\n  //   const options: UseRequestHandleApiDefaultOptions<\n  //     ApiUploadImageVarsParams,\n  //     FileUploadImagePropResponse\n  //   > = {\n  //     api: mergedProps.value.apiUploadImageVars,\n  //     beforeApi: mergedProps.value.beforeApiUploadImageVars,\n  //     afterApi: mergedProps.value.afterApiUploadImageVars,\n  //     apiParams: {\n  //       appId: apiParams.appId,\n  //     },\n  //     // successMessage: () => {\n  //     //   return tavI18n('Tav.file.message.6')\n  //     // },\n  //     failureMessage: () => {\n  //       return tavI18n('Tav.common.httpError')\n  //     },\n  //   }\n\n  //   return options\n  // }\n\n  // function uploadImageApiOptions(apiParams: EditorProps['apiParams'], files: File[]) {\n  //   if (!mergedProps.value.apiUploadImage) {\n  //     console.warn('[tavui TaEditor] apiUploadImage is undefined')\n  //     return\n  //   }\n\n  //   const options: UseRequestHandleApiDefaultOptions<\n  //     ApiUploadImageParams,\n  //     FileUploadImageResponseRecord[]\n  //   > = {\n  //     api: mergedProps.value.apiUploadImage,\n  //     beforeApi: mergedProps.value.beforeApiUploadImage,\n  //     afterApi: mergedProps.value.afterApiUploadImage,\n  //     catchError: mergedProps.value.catchApiUploadImageError,\n  //     apiParams: {\n  //       appId: apiParams.appId,\n  //       files: unref(files),\n  //       isCompress: apiParams.isCompress,\n  //       isScale: apiParams.isScale,\n  //       scaleWidth: apiParams.scaleWidth,\n  //       scaleHeight: apiParams.scaleHeight,\n  //     },\n  //     transformApiParamsToFormData: {\n  //       fileFiledName: 'files',\n  //       filterNames: ['appId'],\n  //     },\n  //     successMessage: () => {\n  //       return tavI18n('Tav.file.message.6')\n  //     },\n  //     failureMessage: () => {\n  //       return tavI18n('Tav.common.httpError')\n  //     },\n  //   }\n\n  //   return options\n  // }\n  function previewFileApiOptions(file: FileUploadApiResponseRecord) {\n    if (!mergedProps.value.apiPreviewFile) {\n      console.warn('[tavui TaEditor] previewApi is undefined')\n      return\n    }\n\n    const options: UseRequestHandleApiDefaultOptions<any, any> = {\n      api: mergedProps.value.apiPreviewFile,\n      apiParams: {\n        url: unref(file).url,\n      },\n      failureMessage: () => {\n        return tavI18n('Tav.common.httpError')\n      },\n    }\n\n    return options\n  }\n  //:========================================: api actions :========================================://\n\n  return {\n    apiActions: {\n      // uploadImageVarsApiOptions,\n      // uploadImageApiOptions,\n      previewFileApiOptions,\n    },\n  }\n}\n\nexport type UseApiReturn = ReturnType<typeof useApi>\n"],"names":[],"mappings":";;;;AAEO,SAAS,MAAM,CAAC,OAAO,EAAE;AAChC,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;AAClC,EAAE,SAAS,qBAAqB,CAAC,IAAI,EAAE;AACvC,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,EAAE;AAC3C,MAAM,OAAO,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;AAC/D,MAAM,OAAO;AACb,KAAK;AACL,IAAI,MAAM,QAAQ,GAAG;AACrB,MAAM,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC,cAAc;AAC3C,MAAM,SAAS,EAAE;AACjB,QAAQ,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG;AAC5B,OAAO;AACP,MAAM,cAAc,EAAE,MAAM;AAC5B,QAAQ,OAAO,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC/C,OAAO;AACP,KAAK,CAAC;AACN,IAAI,OAAO,QAAQ,CAAC;AACpB,GAAG;AACH,EAAE,OAAO;AACT,IAAI,UAAU,EAAE;AAChB,MAAM,qBAAqB;AAC3B,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}