import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { IncludedServicesStep } from './IncludedServicesStep';
import type { IncludedServicesStepValues } from './IncludedServicesStep';
import { Navigation } from '../../organisms/Navigation';
import Box from '@mui/material/Box';

// ─── Helpers ─────────────────────────────────────────────────────────────────

const FALogo = () => (
  <Box sx={{ display: 'flex', alignItems: 'center' }}>
    <Box
      component="img"
      src="/brandlogo/logo-full.svg"
      alt="Funeral Arranger"
      sx={{ height: 28, display: { xs: 'none', md: 'block' } }}
    />
    <Box
      component="img"
      src="/brandlogo/logo-short.svg"
      alt="Funeral Arranger"
      sx={{ height: 28, display: { xs: 'block', md: 'none' } }}
    />
  </Box>
);

const nav = (
  <Navigation
    logo={<FALogo />}
    items={[
      { label: 'FAQ', href: '/faq' },
      { label: 'Contact Us', href: '/contact' },
    ]}
  />
);

const defaultValues: IncludedServicesStepValues = {
  dressing: false,
  viewing: false,
  viewingSameVenue: null,
  prayers: false,
  funeralAnnouncement: true,
};

// ─── Meta ────────────────────────────────────────────────────────────────────

const meta: Meta<typeof IncludedServicesStep> = {
  title: 'Pages/IncludedServicesStep',
  component: IncludedServicesStep,
  tags: ['autodocs'],
  parameters: {
    layout: 'fullscreen',
  },
};

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

// ─── Default ────────────────────────────────────────────────────────────────

/** Default state — funeral announcement on by default */
export const Default: Story = {
  render: () => {
    const [values, setValues] = useState<IncludedServicesStepValues>({ ...defaultValues });
    return (
      <IncludedServicesStep
        values={values}
        onChange={setValues}
        onContinue={() => alert(JSON.stringify(values, null, 2))}
        onBack={() => alert('Back')}
        onSaveAndExit={() => alert('Save')}
        navigation={nav}
      />
    );
  },
};

// ─── All enabled ────────────────────────────────────────────────────────────

/** All inclusions toggled on with viewing sub-option visible */
export const AllEnabled: Story = {
  render: () => {
    const [values, setValues] = useState<IncludedServicesStepValues>({
      dressing: true,
      viewing: true,
      viewingSameVenue: 'yes',
      prayers: true,
      funeralAnnouncement: true,
    });
    return (
      <IncludedServicesStep
        values={values}
        onChange={setValues}
        onContinue={() => alert('Continue')}
        onBack={() => alert('Back')}
        navigation={nav}
      />
    );
  },
};

// ─── Pre-planning ───────────────────────────────────────────────────────────

/** Pre-planning variant with softer copy */
export const PrePlanning: Story = {
  render: () => {
    const [values, setValues] = useState<IncludedServicesStepValues>({ ...defaultValues });
    return (
      <IncludedServicesStep
        values={values}
        onChange={setValues}
        onContinue={() => alert('Continue')}
        onBack={() => alert('Back')}
        isPrePlanning
        navigation={nav}
      />
    );
  },
};
