import type { Meta, StoryObj } from '@storybook/react';
import Box from '@mui/material/Box';
import { PackageDetail } from './PackageDetail';

const essentials = [
  {
    name: 'Allowance for Coffin',
    price: 1750,
    isAllowance: true,
    info: 'Allowance amount — upgrade options available during arrangement.',
  },
  {
    name: 'Cremation Certificate/Permit',
    price: 350,
    info: 'Statutory medical referee fee required for all cremations in NSW.',
  },
  {
    name: 'Crematorium: Mackay Family Crematorium',
    price: 660,
    info: 'Cremation facility fees at the selected crematorium.',
  },
  {
    name: 'Death Registration Certificate',
    price: 70,
    info: 'Lodgement of death registration with NSW Registry of Births, Deaths & Marriages.',
  },
  {
    name: 'Dressing Fee',
    price: 0,
    priceLabel: 'Complimentary',
    info: 'Dressing and preparation of the deceased — included at no charge.',
  },
  {
    name: 'NSW Government Levy — Cremation',
    price: 45.1,
    info: 'NSW Government cremation levy as set by the Department of Health.',
  },
  {
    name: 'Professional Mortuary Care',
    price: 440,
    info: 'Preparation and care of the deceased.',
  },
  {
    name: 'Professional Service Fee',
    price: 3650.9,
    info: 'Coordination of all funeral arrangements and services.',
  },
  {
    name: 'Transportation Service Fee',
    price: 0,
    priceLabel: 'Complimentary',
    info: 'Transfer of the deceased to the funeral home — included in this package.',
  },
];

const optionals = [
  {
    name: 'Digital Recording of the Funeral Service',
    priceLabel: 'Complimentary',
    info: 'Professional video recording of the funeral service.',
  },
  {
    name: 'Online Notice',
    priceLabel: 'Complimentary',
    info: 'Online death notice published on the funeral home website.',
  },
  {
    name: 'Viewing Fee',
    priceLabel: 'Complimentary',
    info: 'One private family viewing — included at no charge.',
  },
  {
    name: 'Webstreaming of the Funeral Service',
    priceLabel: 'Complimentary',
    info: 'Live webstream of the funeral service for remote attendees.',
  },
];

const extras = {
  heading: 'Extras',
  items: [
    {
      name: 'Allowance for Celebrant',
      price: 550,
      isAllowance: true,
      info: 'Professional celebrant or MC for the funeral service.',
    },
    {
      name: 'Catering',
      priceLabel: 'Price On Application',
      info: 'Catering for the wake or post-service gathering.',
    },
    {
      name: 'Newspaper Notice',
      priceLabel: 'Price On Application',
      info: 'Published death notice in local or national newspaper.',
    },
    {
      name: 'Saturday Service Fee',
      price: 880,
      info: 'Additional fee for services held on a Saturday.',
    },
  ],
};

const termsText =
  '* This package includes a funeral service at a chapel or a church with a funeral procession following to the crematorium. It includes many of the most commonly selected funeral options preselected for you. Many people choose this package for the extended funeral rituals — of course, you can tailor the funeral service to meet your needs and budget as you go through the selections.';

const meta: Meta<typeof PackageDetail> = {
  title: 'Organisms/PackageDetail',
  component: PackageDetail,
  tags: ['autodocs'],
  parameters: {
    layout: 'centered',
  },
  decorators: [
    (Story) => (
      <Box sx={{ maxWidth: 600, width: '100%' }}>
        <Story />
      </Box>
    ),
  ],
};

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

// --- Default -----------------------------------------------------------------

/** Full package detail panel — Essentials, Optionals, Total, then Extras */
export const Default: Story = {
  args: {
    name: 'Traditional Family Cremation Service',
    price: 6966,
    sections: [
      { heading: 'Essentials', items: essentials },
      { heading: 'Optionals', items: optionals },
    ],
    total: 6966,
    extras,
    terms: termsText,
    onArrange: () => alert('Make Arrangement clicked'),
    onCompare: () => alert('Compare clicked'),
  },
};

// --- Compare Loading ---------------------------------------------------------

/** Compare button in loading state — adding to comparison cart */
export const CompareLoading: Story = {
  args: {
    name: 'Traditional Family Cremation Service',
    price: 6966,
    sections: [{ heading: 'Essentials', items: essentials.slice(0, 4) }],
    total: 6966,
    onArrange: () => alert('Make Arrangement'),
    onCompare: () => {},
    compareLoading: true,
  },
};

// --- Without Extras ----------------------------------------------------------

/** Simpler package with essentials and optionals only — no extras */
export const WithoutExtras: Story = {
  args: {
    name: 'Essential Cremation Package',
    price: 4850,
    sections: [
      { heading: 'Essentials', items: essentials.slice(0, 6) },
      { heading: 'Optionals', items: optionals.slice(0, 2) },
    ],
    total: 4850,
    terms: termsText,
    onArrange: () => alert('Make Arrangement'),
    onCompare: () => alert('Compare'),
  },
};
