import { useState, type ReactNode } from "react"
import type { Meta, StoryObj } from "@storybook/react-vite"
import type { DateRange } from "react-day-picker"
import { Calendar } from "@hm-design/ui"
import { StateBoard } from "@/components/story-board"
import { StoryPage, StoryPageHeader, StorySection } from "@/components/story-page"
// The representative "Calendar" Story shows each mode with real, clickable calendars; the same specimens also exist as Stories
// tagged `verification` (hidden from the sidebar). `today` is pinned to 2026-10-02 so the Story looks the same on any day; this
// uses react-day-picker's own `today` prop, not an HM state. Korean is the Calendar default locale.
const today = new Date(2026, 9, 2)
const month = new Date(2026, 9, 1)
const box = (node: ReactNode) =>
{node}
// `showValue={false}` hides the value readout on the representative page; the verification Stories keep it.
function Single({ showValue = true }: { showValue?: boolean }) {
const [date, setDate] = useState(new Date(2026, 9, 15))
return (
{box()}
{showValue ? {`선택: ${date ? date.toLocaleDateString("ko-KR") : "없음"}`} : null}
)
}
function DisabledDates() {
const [date, setDate] = useState()
return box(
)
}
function Range() {
const [range, setRange] = useState({ from: new Date(2026, 9, 8), to: new Date(2026, 9, 14) })
return box()
}
function TwoMonths() {
return box()
}
const sections = [
{ id: "single", label: "Single", node: },
{ id: "disabled", label: "Disabled dates", node: },
{ id: "range", label: "Range", node: },
{ id: "months", label: "Two months", node: },
]
// No `component`: Calendar props are a union of selection modes, so Stories without args would not type-check.
const meta = { title: "Components/Search & Date/Calendar", parameters: { layout: "padded" } } satisfies Meta
export default meta
type Story = StoryObj
const board = (...ids: string[]) => (
ids.includes(s.id)).map((s) => ({ id: s.id, label: s.label, wide: s.id === "months", children: s.node }))} />
)
// Representative Story: the common Story page; the sections group the same specimens.
export const All: Story = {
name: "Calendar",
parameters: { layout: "fullscreen", controls: { disable: true } },
render: () => (
{board("single")}
{board("range", "months")}
{board("disabled")}
),
}
export const SingleSelection: Story = { tags: ["verification"], name: "Single", render: () => }
export const DisabledSelection: Story = { tags: ["verification"], name: "Disabled Dates", render: () => }
export const RangeSelection: Story = { tags: ["verification"], name: "Range", render: () => }