import React, { useState } from "react";
import { Meta, Story } from "@storybook/react";
import { AtomCountDown, IContDownProps } from "native/atoms/CountDown";
import { theme } from "data/dataMx";
import { AtomButtonDefault } from "native/atoms/Buttons/Default";

const meta: Meta = {
  title: "React Native/atoms/CountDown",
  component: AtomCountDown,
  argTypes: {
    strokeBgColor: {
      control: {
        type: "select",
      },
      options: Object.keys(theme),
    },
    strokeColor: {
      control: {
        type: "select",
      },
      options: Object.keys(theme),
    },
    onFinish: {
      control: false,
    },
  },
  parameters: {
    controls: { expanded: true },
  },
};

export default meta;

const TemplateCountDown: Story<IContDownProps> = (props) => {
  const [started, setStarted] = useState<boolean>(false);
  return (
    <>
      <AtomButtonDefault
        disabled={started}
        text="Start counter"
        color="primary"
        onPress={() => setStarted(true)}
      />
      {started && (
        <AtomCountDown {...props} onFinish={() => setStarted(false)} />
      )}
    </>
  );
};

// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/react/workflows/unit-testing
export const CountDown = TemplateCountDown.bind({});

CountDown.args = {
  size: 150,
  dataStart: "2022/01/01 16:00:00",
  dataFinish: "2022/01/01 16:00:30",
  strokeBgColor: "neutral500",
  strokeColor: "quaternary500",
  strokeWidth: 6,
  onFinish: () => console.log("DONE!"),
};
