import * as React from 'react';
import { StickerPackInstallButton } from './StickerPackInstallButton';
import { ConfirmationModal } from '../ConfirmationModal';
import { LocalizerType } from '../../types/Util';
import { StickerPackType } from '../../state/ducks/stickers';
export type OwnProps = {
readonly i18n: LocalizerType;
readonly pack: StickerPackType;
readonly onClickPreview?: (sticker: StickerPackType) => unknown;
readonly installStickerPack?: (packId: string, packKey: string) => unknown;
readonly uninstallStickerPack?: (packId: string, packKey: string) => unknown;
};
export type Props = OwnProps;
export const StickerManagerPackRow = React.memo(
// tslint:disable-next-line max-func-body-length
({
installStickerPack,
uninstallStickerPack,
onClickPreview,
pack,
i18n,
}: Props) => {
const { id, key, isBlessed } = pack;
const [uninstalling, setUninstalling] = React.useState(false);
const clearUninstalling = React.useCallback(() => {
setUninstalling(false);
}, [setUninstalling]);
const handleInstall = React.useCallback(
(e: React.MouseEvent) => {
e.stopPropagation();
if (installStickerPack) {
installStickerPack(id, key);
}
},
[installStickerPack, pack]
);
const handleUninstall = React.useCallback(
(e: React.MouseEvent) => {
e.stopPropagation();
if (isBlessed && uninstallStickerPack) {
uninstallStickerPack(id, key);
} else {
setUninstalling(true);
}
},
[setUninstalling, id, key, isBlessed]
);
const handleConfirmUninstall = React.useCallback(() => {
clearUninstalling();
if (uninstallStickerPack) {
uninstallStickerPack(id, key);
}
}, [id, key, clearUninstalling]);
const handleKeyDown = React.useCallback(
(event: React.KeyboardEvent) => {
if (
onClickPreview &&
(event.key === 'Enter' || event.key === 'Space')
) {
event.stopPropagation();
event.preventDefault();
onClickPreview(pack);
}
},
[onClickPreview, pack]
);
const handleClickPreview = React.useCallback(
(event: React.MouseEvent) => {
if (onClickPreview) {
event.stopPropagation();
event.preventDefault();
onClickPreview(pack);
}
},
[onClickPreview, pack]
);
return (
<>
{uninstalling ? (