import {
PreferencesGroup,
PreferencesSegment,
Text,
Title,
} from '@/preferences/components';
import { Button } from '@/components/Button';
import { observer } from '@node_modules/mobx-react-lite';
import { WebApplication } from '@/ui_models/application';
import { useEffect, useState } from 'preact/hooks';
import { GetSubscriptionResponse } from '@standardnotes/snjs/dist/@types/services/api/responses';
type Props = {
application: WebApplication;
};
enum PlanName {
CorePlan = 'CORE_PLAN',
PlusPlan = 'PLUS_PLAN',
ProPlan = 'PRO_PLAN',
}
type Subscription = {
cancelled: boolean;
planName: PlanName;
endsAt: number;
};
type SubscriptionInformationProps = {
subscription?: Subscription;
};
type ValidSubscriptionProps = {
subscription: Subscription;
};
const mapPlanNameToString = (planName: PlanName) => {
switch (planName) {
case 'CORE_PLAN':
return 'Core';
case 'PLUS_PLAN':
return 'Plus';
case 'PRO_PLAN':
return 'Pro';
default:
return '';
}
};
const NoSubscription = () => (
<>
You don't have a Standard Notes subscription yet.
>
);
const ActiveSubscription = ({ subscription }: ValidSubscriptionProps) => (
<>
Your{' '}
Standard Notes {mapPlanNameToString(subscription.planName)}
{' '}
subscription will be{' '}
renewed on {new Date(subscription.endsAt).toLocaleString()}
.
null}
/>
null}
/>
null}
/>
>
);
const CancelledSubscription = ({ subscription }: ValidSubscriptionProps) => (
<>
Your{' '}
Standard Notes {mapPlanNameToString(subscription.planName)}
{' '}
subscription has been{' '}
canceled but will remain valid until{' '}
{new Date(subscription.endsAt).toLocaleString()}
. You may resubscribe below if you wish.