import { openUrl } from '@tauri-apps/plugin-opener';
import { useLicense } from '@yaakapp-internal/license';
import { differenceInDays } from 'date-fns';
import { formatDate } from 'date-fns/format';
import { useState } from 'react';
import { useToggle } from '../../hooks/useToggle';
import { pluralizeCount } from '../../lib/pluralize';
import { CargoFeature } from '../CargoFeature';
import { Banner } from '../core/Banner';
import { Button } from '../core/Button';
import { Icon } from '../core/Icon';
import { Link } from '../core/Link';
import { PlainInput } from '../core/PlainInput';
import { Separator } from '../core/Separator';
import { HStack, VStack } from '../core/Stacks';
import { LocalImage } from '../LocalImage';
export function SettingsLicense() {
return (
);
}
function SettingsLicenseCmp() {
const { check, activate, deactivate } = useLicense();
const [key, setKey] = useState('');
const [activateFormVisible, toggleActivateFormVisible] = useToggle(false);
if (check.isPending) {
return null;
}
const renderBanner = () => {
if (!check.data) return null;
switch (check.data.status) {
case 'active':
return Your license is active 🥳;
case 'trialing':
return (
{pluralizeCount('day', differenceInDays(check.data.data.end, new Date()))}
{' '}
left to evaluate Yaak for commercial use.
Personal use is always free, forever.
Contact Support
Learn More
);
case 'personal_use':
return (
Your commercial-use trial has ended.
You may continue using Yaak for personal use free, forever.
A license is required for commercial use.
Contact Support
Learn More
);
case 'inactive':
return (
Your license is invalid. Please Sign In{' '}
for more details
);
case 'expired':
return (
Your license expired{' '}
{formatDate(check.data.data.periodEnd, 'MMMM dd, yyyy')}. Please{' '}
Resubscribe to continue receiving
updates.
{check.data.data.changesUrl && (
<>
What's new in latest builds
>
)}
);
case 'past_due':
return (
Your payment method needs attention.
To re-activate your license, please{' '}
update your billing info.
);
case 'error':
return (
License check failed: {check.data.data.message} (Code: {check.data.data.code})
);
}
};
return (