import { memo } from '../../../lib/teact/teact';
import { getActions, withGlobal } from '../../../global';
import type { ApiDisallowedGiftsSettings } from '../../../api/types';
import { selectIsCurrentUserPremium } from '../../../global/selectors';
import useLang from '../../../hooks/useLang';
import useLastCallback from '../../../hooks/useLastCallback';
import Island, { IslandDescription, IslandTitle } from '../../gili/layout/Island';
import ListItem from '../../ui/ListItem';
import Switcher from '../../ui/Switcher';
type StateProps = {
disallowedGifts?: ApiDisallowedGiftsSettings;
isCurrentUserPremium: boolean;
};
const SettingsAcceptedGift = ({
disallowedGifts, isCurrentUserPremium,
}: StateProps) => {
const { showNotification, updateGlobalPrivacySettings } = getActions();
const lang = useLang();
const handleOpenTelegramPremiumModal = useLastCallback(() => {
showNotification({
message: lang('PrivacySubscribeToTelegramPremium'),
action: {
action: 'openPremiumModal',
payload: {},
},
actionText: { key: 'Open' },
icon: 'star',
});
});
const handleLimitedEditionChange = useLastCallback(() => {
if (!isCurrentUserPremium) {
handleOpenTelegramPremiumModal();
return;
}
updateGlobalPrivacySettings({
disallowedGifts: {
...disallowedGifts,
shouldDisallowLimitedStarGifts: !disallowedGifts?.shouldDisallowLimitedStarGifts || undefined,
},
});
});
const handleUnlimitedEditionChange = useLastCallback(() => {
if (!isCurrentUserPremium) {
handleOpenTelegramPremiumModal();
return;
}
updateGlobalPrivacySettings({
disallowedGifts: {
...disallowedGifts,
shouldDisallowUnlimitedStarGifts: !disallowedGifts?.shouldDisallowUnlimitedStarGifts || undefined,
},
});
});
const handleUniqueChange = useLastCallback(() => {
if (!isCurrentUserPremium) {
handleOpenTelegramPremiumModal();
return;
}
updateGlobalPrivacySettings({
disallowedGifts: {
...disallowedGifts,
shouldDisallowUniqueStarGifts: !disallowedGifts?.shouldDisallowUniqueStarGifts || undefined,
},
});
});
const handlePremiumSubscriptionChange = useLastCallback(() => {
if (!isCurrentUserPremium) {
handleOpenTelegramPremiumModal();
return;
}
updateGlobalPrivacySettings({
disallowedGifts: {
...disallowedGifts,
shouldDisallowPremiumGifts: !disallowedGifts?.shouldDisallowPremiumGifts || undefined,
},
});
});
return (
<>
{lang('PrivacyAcceptedGiftTitle')}
{lang('PrivacyGiftLimitedEdition')}
{lang('PrivacyGiftUnlimited')}
{lang('PrivacyGiftUnique')}
{lang('PrivacyGiftPremiumSubscription')}
{lang('PrivacyAcceptedGiftInfo')}
>
);
};
export default memo(withGlobal(
(global): Complete => {
const {
settings: {
byKey: {
disallowedGifts,
},
},
} = global;
return {
disallowedGifts,
isCurrentUserPremium: selectIsCurrentUserPremium(global),
};
},
)(SettingsAcceptedGift));