import { WebApplication } from '@/UIModels/Application' import { FeatureStatus, FeatureIdentifier } from '@standardnotes/snjs' import { FunctionComponent } from 'preact' import { useCallback } from 'preact/hooks' import { JSXInternal } from 'preact/src/jsx' import { Icon } from '@/Components/Icon' import { usePremiumModal } from '@/Hooks/usePremiumModal' import { Switch } from '@/Components/Switch' type Props = { application: WebApplication onToggle: (value: boolean) => void onClose: () => void isEnabled: boolean } export const FocusModeSwitch: FunctionComponent = ({ application, onToggle, onClose, isEnabled }) => { const premiumModal = usePremiumModal() const isEntitled = application.features.getFeatureStatus(FeatureIdentifier.FocusMode) === FeatureStatus.Entitled const toggle = useCallback( (e: JSXInternal.TargetedMouseEvent) => { e.preventDefault() if (isEntitled) { onToggle(!isEnabled) onClose() } else { premiumModal.activate('Focused Writing') } }, [isEntitled, onToggle, isEnabled, onClose, premiumModal], ) return ( <> ) }