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

// Placeholder images for stories
const IMG_PROVIDER =
  'https://images.unsplash.com/photo-1600585154340-be6161a56a0c?w=400&h=240&fit=crop&auto=format';
const IMG_VENUE =
  'https://images.unsplash.com/photo-1497366216548-37526070297c?w=400&h=240&fit=crop&auto=format';
const IMG_CHAPEL =
  'https://images.unsplash.com/photo-1548625149-fc4a29cf7092?w=400&h=240&fit=crop&auto=format';
const IMG_GARDEN =
  'https://images.unsplash.com/photo-1585320806297-9794b3e4eeae?w=400&h=240&fit=crop&auto=format';

const meta: Meta<typeof MiniCard> = {
  title: 'Molecules/MiniCard',
  component: MiniCard,
  tags: ['autodocs'],
  parameters: {
    layout: 'centered',
  },
  decorators: [
    (Story) => (
      <Box sx={{ width: 240 }}>
        <Story />
      </Box>
    ),
  ],
};

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

/** Default — verified provider with image, location, and price */
export const Default: Story = {
  args: {
    title: 'H.Parsons Funeral Directors',
    imageUrl: IMG_PROVIDER,
    verified: true,
    price: 900,
    location: 'Wollongong',
  },
};

/** With all optional fields populated */
export const FullyLoaded: Story = {
  args: {
    title: 'H.Parsons Funeral Directors',
    imageUrl: IMG_PROVIDER,
    verified: true,
    location: 'Wollongong',
    rating: 4.8,
    price: 900,
    badges: [{ label: 'Online Arrangement', color: 'success' }],
    chips: ['Burial', 'Cremation'],
  },
};

/** Unverified provider — no badge in image */
export const Unverified: Story = {
  args: {
    title: 'Smith & Sons Funeral Services',
    imageUrl: IMG_VENUE,
    price: 1200,
    location: 'Sutherland',
  },
};

/** Venue card usage — capacity instead of rating */
export const Venue: Story = {
  args: {
    title: 'Albany Creek Memorial Park',
    imageUrl: IMG_CHAPEL,
    price: 450,
    location: 'Albany Creek',
    capacity: 120,
  },
};

/** Package card usage — custom price label */
export const Package: Story = {
  args: {
    title: 'Essential Cremation Package',
    imageUrl: IMG_GARDEN,
    priceLabel: 'From $2,800',
    badges: [{ label: 'Most Popular', color: 'brand' }],
  },
};

/** Minimal — just title and image */
export const Minimal: Story = {
  args: {
    title: 'Lady Anne Funerals',
    imageUrl: IMG_VENUE,
  },
};

/** Selected state — brand border + warm background */
export const Selected: Story = {
  args: {
    title: 'H.Parsons Funeral Directors',
    imageUrl: IMG_PROVIDER,
    verified: true,
    price: 900,
    location: 'Wollongong',
    selected: true,
  },
};

/** Long title — truncated at 2 lines, hover tooltip shows full text */
export const LongTitle: Story = {
  args: {
    title: 'Botanical Funerals by Ian Allison — Sustainable & Eco-Friendly Services',
    imageUrl: IMG_GARDEN,
    verified: true,
    location: 'Northern Beaches',
    rating: 4.9,
    price: 1200,
  },
};

/** Multiple cards in a responsive grid — mix of verified and unverified */
export const Grid: Story = {
  decorators: [
    (Story) => (
      <Box
        sx={{
          display: 'grid',
          gridTemplateColumns: 'repeat(auto-fill, minmax(200px, 1fr))',
          gap: 2,
          width: 680,
        }}
      >
        <Story />
      </Box>
    ),
  ],
  render: () => (
    <>
      <MiniCard
        title="H.Parsons Funeral Directors"
        imageUrl={IMG_PROVIDER}
        verified
        location="Wollongong"
        rating={4.8}
        price={900}
        chips={['Burial', 'Cremation']}
        onClick={() => {}}
      />
      <MiniCard
        title="Albany Creek Memorial Park"
        imageUrl={IMG_CHAPEL}
        location="Albany Creek"
        capacity={120}
        price={450}
        onClick={() => {}}
      />
      <MiniCard
        title="Lady Anne Funerals"
        imageUrl={IMG_VENUE}
        location="Sutherland Shire"
        onClick={() => {}}
      />
    </>
  ),
};
