import React, { useState } from "react";
import {
  Title,
  Subtitle,
  Description,
  Primary,
} from "@storybook/addon-docs/blocks";
import { H3 } from "../../../../src/atoms/base";
import { Container } from "../../../../src/atoms/container";
import { Transition } from "../../../../src/atoms/base";
import { Button } from "../../../../src/atoms/button";
import { NavLink } from "../../../../src/atoms/nav";

export default {
  title: "Components/Transition",
  component: Transition,
  parameters: {
    docs: {
      page: () => (
        <>
          <Title>Readme</Title>
          <br />
          <Subtitle>
            To integrate Transition for your using at your product, please read
            the information below, and check the example code at the story.
          </Subtitle>
          <Description>
            1. `import &#123; Transition &#125; from 'seturon';`
          </Description>
          <Description>
            2. Set the component on the needed page and use `useState` hook for
            setting up.
          </Description>
          <Description>3. Set needed `props` at the component.</Description>
          <br />
          <Subtitle>
            To have more idea about the code and usage of the Transition
            components, check it out:
          </Subtitle>
          <NavLink href="http://design.seturon.io/?path=/docs/components-transition--example">
            Example
          </NavLink>
          <Primary name="Readme" />
        </>
      ),
    },
  },
  args: {
    primary: true,
  },
  argTypes: {
    props: {
      description: null,
      table: {
        type: {
          summary: null,
          detail: null,
        },
      },
      control: {
        type: null,
      },
    },
  },
};

const TransitionComponent = (props) => {
  const [hidden, setHidden] = useState(false);

  return (
    <Container>
      <Button block {...props} onClick={() => setHidden(!hidden)}>
        Toggle
      </Button>
      <Container p4>
        <Transition hidden={hidden} {...props}>
          <H3>
            Last but certainly not least, we will get a thorough introduction to
            the most ubiquitous, popular, and incredibly powerful language of
            the web: Javascript.
          </H3>
        </Transition>
      </Container>
    </Container>
  );
};

export const Readme = (args) => (
  <TransitionComponent
    {...args}
    delay={100}
    duration={1000}
    timingFunc="linear"
  />
);

export const Example = () => {
  const [hidden, setHidden] = useState(false);

  return (
    <Container>
      <Button mb5 block primary onClick={() => setHidden(!hidden)}>
        Toggle
      </Button>
      <Transition hidden={hidden} hideOnExit>
        <H3>
          Last but certainly not least, we will get a thorough introduction to
          the most ubiquitous, popular, and incredibly powerful language of the
          web: Javascript.
        </H3>
      </Transition>
      <Button block primary onClick={() => setHidden(!hidden)}>
        Toggle
      </Button>
      <Transition hidden={hidden} hideOnExit>
        <H3>
          Last but certainly not least, we will get a thorough introduction to
          the most ubiquitous, popular, and incredibly powerful language of the
          web: Javascript.
        </H3>
      </Transition>
    </Container>
  );
};

Example.storyName = "Example";

Example.parameters = {
  component: Transition,
  docs: {
    page: () => (
      <>
        <Title>Example</Title>
        <Subtitle>Props</Subtitle>
        <Description>
          Note, to use the `Transition` component you'll need to make a
          sepparate React compomemt by using `useState` hook
        </Description>
        <Description>
          To setup the `Transition` animation you may use the next `props`:
        </Description>
        <Description>1. `delay`</Description>
        <Description>2. `duration`</Description>
        <Description>3. `timingFunc`</Description>
        <Description>4. `hideOnExit` - set for collapsing the content</Description>
        <br />
        <Subtitle>
          Check the code below to get an idea of how to use it at your product👇
        </Subtitle>
        <Primary name="Example" />
      </>
    ),
  },
};
