{"version":3,"file":"withGTServerSideProps.mjs","names":[],"sources":["../../src/pages-dir/withGTServerSideProps.ts"],"sourcesContent":["import type {\n  GetServerSideProps,\n  GetServerSidePropsContext,\n  PreviewData,\n} from 'next';\nimport type { ParsedUrlQuery } from 'querystring';\nimport { getTranslationsSnapshot } from 'gt-react';\nimport { parseLocale } from './parseLocale';\nimport { parseEnableI18n } from './parseEnableI18n';\n\ntype GTServerSideProps = {\n  locale: string;\n  enableI18n: boolean;\n  translations: Awaited<ReturnType<typeof getTranslationsSnapshot>>;\n};\n\nexport type WithGTServerSideProps<\n  Props extends Record<string, unknown> = Record<string, unknown>,\n> = Props & GTServerSideProps;\n\nexport function withGTServerSideProps<\n  Props extends Record<string, unknown> = Record<string, unknown>,\n  Params extends ParsedUrlQuery = ParsedUrlQuery,\n  Preview extends PreviewData = PreviewData,\n>(\n  getServerSideProps?: GetServerSideProps<Props, Params, Preview>\n): GetServerSideProps<WithGTServerSideProps<Props>, Params, Preview> {\n  return async (context: GetServerSidePropsContext<Params, Preview>) => {\n    const result = getServerSideProps\n      ? await getServerSideProps(context)\n      : { props: {} as Props };\n\n    if (!('props' in result)) {\n      return result;\n    }\n\n    const props = await result.props;\n    const locale = parseLocale(context);\n    const enableI18n = parseEnableI18n(context);\n\n    return {\n      props: {\n        ...props,\n        locale,\n        enableI18n,\n        translations: await getTranslationsSnapshot(locale),\n      },\n    };\n  };\n}\n"],"mappings":";;;;AAoBA,SAAgB,sBAKd,oBACmE;AACnE,QAAO,OAAO,YAAwD;EACpE,MAAM,SAAS,qBACX,MAAM,mBAAmB,QAAQ,GACjC,EAAE,OAAO,EAAE,EAAW;AAE1B,MAAI,EAAE,WAAW,QACf,QAAO;EAGT,MAAM,QAAQ,MAAM,OAAO;EAC3B,MAAM,SAAS,YAAY,QAAQ;EACnC,MAAM,aAAa,gBAAgB,QAAQ;AAE3C,SAAO,EACL,OAAO;GACL,GAAG;GACH;GACA;GACA,cAAc,MAAM,wBAAwB,OAAO;GACpD,EACF"}