import { useEffect, useState } from "react";
import type { Meta, StoryObj } from "@storybook/react";
import { Switch as Control, type SwitchProps } from ".";
import { excludeControls } from "../../utils";

type StoryType = StoryObj<typeof Control>;

const meta: Meta<typeof Control> = {
  title: "Components/Switch",
  component: Control,
  argTypes: excludeControls("className"),
};

const Switch = (args: SwitchProps) => {
  const [checked, setChecked] = useState<boolean | undefined>(args.checked);

  useEffect(() => {
    setChecked(args.checked);
  }, [args.checked]);

  return <Control {...args} checked={checked} />;
};

export const Default: StoryType = {
  render: (args: SwitchProps) => <Switch {...args} />,
  args: {
    checked: false,
  },
};

export default meta;
