import { Meta, StoryObj } from '@storybook/react';

import {
  PlanKey,
  SubscriptionInfo,
  UsagePlanDescription,
  UsagePlanSchema,
} from '@/state/sessionStore';
import { SubscriptionPeriod } from '@/utils/session';

import { AuraSubscriptionCard } from './AuraSubscriptionCard';

const meta: Meta<typeof AuraSubscriptionCard> = {
  title: 'Components/Card/AuraSubscriptionCard',
  component: AuraSubscriptionCard,
  parameters: {
    layout: 'centered',
  },
  tags: ['autodocs'],
};

export default meta;
type Story = StoryObj<typeof AuraSubscriptionCard>;

const mockPlan: UsagePlanSchema = {
  id: '1',
  name: 'Pro Plan',
  plan_key: PlanKey.Pro,
  level: 2,
  features: JSON.stringify([
    { type: 'plus', text: 'Unlimited generations' },
    { type: 'plus', text: 'Priority support' },
    { type: 'plus', text: 'Advanced features' },
    { type: 'minus', text: 'Custom branding' },
  ]),
  monthly_price_usd: 19.99,
  annual_price_usd: 199.99,
  prices: [
    {
      currency: 'usd',
      period_type: 'monthly',
      price: 10.0,
    },
    {
      currency: 'usd',
      period_type: 'annual',
      price: 96.0,
    },
  ],
  usage_plan_features: [
    { name: 'v4' },
    { name: 'cover' },
    { name: 'persona' },
    { name: 'edit_mode' },
  ],
};

const mockCurrentSubscription: SubscriptionInfo = {
  subscription_platform: null,
  is_active: true,
  is_past_due: false,
  credits: 0,
  subscription_type: true,
  subscription_anchor: null,
  subscription_id: null,
  plan: {
    id: '2',
    plan_key: PlanKey.Free,
    level: 1,
    name: 'Free Plan',
    features: '',
    monthly_price_usd: 0,
    annual_price_usd: 0,
    prices: [
      {
        currency: 'usd',
        period_type: 'monthly',
        price: 0,
      },
      {
        currency: 'usd',
        period_type: 'annual',
        price: 0,
      },
    ],
    usage_plan_features: [],
  },
  period: SubscriptionPeriod.Monthly,
  cancel_on: null,
  changing_to: null,
  renews_on: null,
  monthly_usage: 0,
  monthly_limit: 0,
  credit_packs: [],
  audio_upload_limits: {
    min: 0,
    max: 0,
  },
  models: [],
  plan_price: null,
  plan_currency: null,
  plan_currency_price: null,
  payment_method_type: null,
  can_upgrade_immediately: true,
  plans: [],
  accessible_features: [],
  total_credits_left: 0,
  free_persona_clips_remaining: null,
  free_cover_clips_remaining: null,
  free_remasters_remaining: null,
  free_mobile_remasters_remaining: null,
  free_mobile_v4_gens_remaining: null,
  free_web_v4_gens_remaining: null,
  has_been_subscriber_before: false,
  has_valid_school_email: false,
  has_been_student_subscriber_before: false,
  period_end: null,
};

const mockPlanDescription: UsagePlanDescription = {
  billing_period_month: {
    text: 'month',
  },
  billing_period_year: {
    text: 'year',
  },
  plan_display_name: {
    text: 'Pro Plan',
  },
  taxes_message: {
    text: 'Taxes included',
  },
  badge: {
    text: 'Most Popular',
    icon: 'heart',
    className: 'bg-accent-pink text-foreground-primary-on-dark',
  },
  plan_description:
    'Perfect for professional creators who need advanced features and priority support.',
  feature_descriptions: [
    { text: 'Unlimited generations', type: 'plus' },
    { text: 'Priority support', type: 'plus' },
    { text: 'Advanced features', type: 'plus' },
    { text: 'Custom branding', type: 'minus' },
  ],
};

export const Default: Story = {
  args: {
    plan: mockPlan,
    price: 19.99,
    period: SubscriptionPeriod.Monthly,
    features: JSON.parse(mockPlan.features),
    currentSubscription: mockCurrentSubscription,
    setPeriodAnnual: () => {},
    planDescription: mockPlanDescription,
  },
};
