{"version":3,"file":"useSharePath-Vh29oc9Z.mjs","names":[],"sources":["../src/components/composable/share/useSharePath.ts"],"sourcesContent":["import { OrganisationAttributes } from \"../../../stores/class/general/organisation\";\nimport { RouteLocationAsRelativeTyped, useRouter } from \"vue-router\";\nimport { useSeoTitleUrl } from \"../route/useSeoTitleUrl\";\n\nexport const useSharePath = () => {\n    const router = useRouter();\n    const { stringUrlEncode } = useSeoTitleUrl();\n\n    /** Retrieve the URL of the podcastmaker, if any */\n\tfunction getPodcastMakerUrl(attributes?: OrganisationAttributes): string|undefined {\n        if (attributes?.podcastmakerUrl) {\n            return attributes.podcastmakerUrl;\n        }\n\t}\n\n\t/**\n\t * Retrieve the base URL for sharing.\n\t * If the podcastmaker URL is defined, it will be used.\n\t * Otherwise, the frontend URL will be used.\n\t * @param attributes The attributes defined on the organisation, from\n\t                     which the podcastmaker url is extracted\n\t */\n\tfunction getBaseSharePath(attributes?: OrganisationAttributes): string {\n\t    const pmUrl = getPodcastMakerUrl(attributes);\n\t    if (pmUrl) {\n\t        return pmUrl;\n\t    } else {\n\t        return window.location.origin;\n\t    }\n\t}\n\n    /**\n     * Retrieve the full URL to a page, for sharing.\n     * If the podcastmaker URL is set, the link will point to it.\n\t * @param attributes The attributes defined on the organisation, from\n\t                     which the podcastmaker url is extracted\n\t */\n\tfunction getSharePath(route: RouteLocationAsRelativeTyped, attributes?: OrganisationAttributes): string {\n        const resolved = router.resolve(route);\n        // Remove trailing slash\n        const base = getBaseSharePath(attributes).replace(/\\/$/, '');\n        // Remove leading slash\n        const path = resolved.path.replace(/^\\//, '');\n        return base + '/' + path;\n\t}\n\n\ttype GetSmartLinkParam = {\n\t    /** The title of the element displayed by the smartlink page */\n\t    title?: string;\n\t    playlistId: number;\n\t    emissionId?: never;\n\t} | {\n\t    /** The title of the element displayed by the smartlink page */\n\t    title?: string;\n\t    playlistId?: never;\n\t    emissionId: number;\n\t};\n\t/**\n\t * Retrieve the full URL for SmartLinks.\n     * If the podcastmaker URL is set, the link will point to it.\n     * @param params The parameters of the smartlink. The ID of the element is\n                     required, whereas the title is optional, but if specified\n                     it will be included in the URL.\n\t * @param attributes The attributes defined on the organisation, from\n\t                     which the podcastmaker url is extracted\n\t */\n\tfunction getSmartLink(params: GetSmartLinkParam, attributes?: OrganisationAttributes): string {\n\t    const title = params.title ? stringUrlEncode(params.title) : undefined;\n\t    if (params.playlistId) {\n\t        return getSharePath({ name: 'playlist-smartlink', params: { playlistId: params.playlistId, title }}, attributes);\n\t    } else if (params.emissionId) {\n\t        return getSharePath({ name: 'emission-smartlink', params: { emissionId: params.emissionId, title }}, attributes);\n\t    }\n\t}\n\n\treturn {\n\t    getPodcastMakerUrl,\n\t    getSharePath,\n\t    getSmartLink\n\t}\n}\n"],"mappings":";;;AAIA,IAAa,qBAAqB;CAC9B,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,oBAAoB,eAAe;;CAG9C,SAAS,mBAAmB,YAAuD;EAC5E,IAAI,YAAY,iBACZ,OAAO,WAAW;CAE7B;;;;;;;;CASA,SAAS,iBAAiB,YAA6C;EACnE,MAAM,QAAQ,mBAAmB,UAAU;EAC3C,IAAI,OACA,OAAO;OAEP,OAAO,OAAO,SAAS;CAE/B;;;;;;;CAQA,SAAS,aAAa,OAAqC,YAA6C;EACjG,MAAM,WAAW,OAAO,QAAQ,KAAK;EAErC,MAAM,OAAO,iBAAiB,UAAU,EAAE,QAAQ,OAAO,EAAE;EAE3D,MAAM,OAAO,SAAS,KAAK,QAAQ,OAAO,EAAE;EAC5C,OAAO,OAAO,MAAM;CAC3B;;;;;;;;;;CAsBA,SAAS,aAAa,QAA2B,YAA6C;EAC1F,MAAM,QAAQ,OAAO,QAAQ,gBAAgB,OAAO,KAAK,IAAI,KAAA;EAC7D,IAAI,OAAO,YACP,OAAO,aAAa;GAAE,MAAM;GAAsB,QAAQ;IAAE,YAAY,OAAO;IAAY;GAAM;EAAC,GAAG,UAAU;OAC5G,IAAI,OAAO,YACd,OAAO,aAAa;GAAE,MAAM;GAAsB,QAAQ;IAAE,YAAY,OAAO;IAAY;GAAM;EAAC,GAAG,UAAU;CAEvH;CAEA,OAAO;EACH;EACA;EACA;CACJ;AACD"}