import type { Meta, StoryObj } from "@storybook/react";
import { excludeControls } from "../../utils";
import { StoryContainer } from "../../utils/StoryContainer";
import type { DateFieldProps } from "./DateField";
import { DateField } from "./DateField";

type StoryType = StoryObj<typeof DateField>;

const meta: Meta<typeof DateField> = {
  title: "Forms/DateField",
  component: DateField,
  argTypes: {
    ...excludeControls(
      "description",
      "validationState",
      "type",
      "labelElementType",
      "inputElementType",
    ),
  },
  args: {
    isReadOnly: false,
  },
  decorators: [
    Story => (
      <StoryContainer>
        <Story />
      </StoryContainer>
    ),
  ],
};

export const Default: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Claim date",
    isDisabled: false,
    errorMessage: "",
    isRequired: false,
  },
};

export const DefaultValue: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Claim date",
    isDisabled: false,
    defaultValue: "2025-04-01",
    isRequired: true,
  },
};

export const WithErrorMessage: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Limited Dates (2025 - dd/mm/yyyy)",
    isRequired: true,
    min: "01/01/2025",
    max: "31/12/2025",
    format: "dd/mm/yyyy",
    errorMessage: "This is a custom error message.",
  },
};

export const LimitedDates: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Limited Dates (2025)",
    isRequired: true,
    min: "2025-01-01",
    max: "2025-12-31",
  },
};

export const LimitedDatesWithCustomFormat: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Limited Dates (2025 - dd/mm/yyyy)",
    isRequired: true,
    min: "01/01/2025",
    max: "31/12/2025",
    format: "dd/mm/yyyy",
  },
};

export const InvalidMin: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Invalid Min Date",
    isDisabled: false,
    errorMessage: "",
    isRequired: true,
    min: "garbage",
  },
};

export const InvalidMax: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Invalid Max Date",
    isDisabled: false,
    errorMessage: "",
    isRequired: true,
    max: "garbage",
  },
};

export const MaxBeforeMin: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Max before Min",
    isDisabled: false,
    errorMessage: "",
    isRequired: true,
    min: "2023-01-01",
    max: "2022-12-31",
  },
};

export const ReadOnly: StoryType = {
  render: (args: DateFieldProps) => <DateField {...args} />,
  args: {
    label: "Claim date",
    isReadOnly: true,
    defaultValue: "2025-04-01",
  },
};

export default meta;
