import { Meta, StoryObj } from "@storybook/react"
import { addDays } from "date-fns"
import React, { useState } from "react"
import { DateTimePicker, DateTimePickerProps } from "./DateTimePicker"

type Story = StoryObj<typeof DateTimePicker>

const meta: Meta<typeof DateTimePicker> = {
  title: "Design System/DateTimePicker",
  component: DateTimePicker,
}

export default meta

const Template = (args: DateTimePickerProps) => {
  const [date, setDate] = useState<Date | undefined>(args.selected)

  const onSelect = (date: Date | undefined) => {
    args.onSelect?.(date)
    setDate(date)
  }

  return <DateTimePicker {...args} selected={date} onSelect={onSelect} />
}

export const Default: Story = {
  render: Template,
}

export const Preselected: Story = {
  render: Template,
  args: {
    selected: addDays(new Date(), 2),
  },
}

export const Small: Story = {
  render: Template,
  args: {
    size: "sm",
  },
}

export const DisabledDays: Story = {
  render: Template,
  args: {
    disabled: {
      before: new Date(),
      after: addDays(new Date(), 2),
    },
  },
}

export const DisabledButton: Story = {
  args: {
    disabled: true,
  },
}

export const Error: Story = {
  render: Template,
  args: {
    error: true,
  },
}
