import { Dispatch, Fragment, SetStateAction, useRef, useState } from 'react' import toast from 'react-hot-toast' import { useTranslation } from 'next-i18next' import { Dialog, Transition } from '@headlessui/react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useClipboard } from 'use-clipboard-copy' import { getBaseUrl } from '../utils/getBaseUrl' import { getStoredToken } from '../utils/protectedRouteHandler' import { getReadablePath } from '../utils/getReadablePath' export default function CustomEmbedLinkMenu({ path, menuOpen, setMenuOpen, }: { path: string menuOpen: boolean setMenuOpen: Dispatch> }) { const { t } = useTranslation() const clipboard = useClipboard() const hashedToken = getStoredToken(path) // Focus on input automatically when menu modal opens const focusInputRef = useRef(null) const closeMenu = () => setMenuOpen(false) const readablePath = getReadablePath(path) const filename = readablePath.substring(readablePath.lastIndexOf('/') + 1) const [name, setName] = useState(filename) return (
{/* This element is to trick the browser into centering the modal contents. */}
{t('Customise direct link')} {t('Change the raw file direct link to a URL ending with the extension of the file.')}{' '} {t('What is this?')}

{t('Filename')}

setName(e.target.value)} />

{t('Default')}

{`${getBaseUrl()}/api/raw/?path=${readablePath}${hashedToken ? `&odpt=${hashedToken}` : ''}`}

{t('Customised')}

{`${getBaseUrl()}/api/name/`} {name} {`/?path=${readablePath}${hashedToken ? `&odpt=${hashedToken}` : ''}`}
) }