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

export default {
  title: "Components/Tooltip",
  component: Tooltip,
  parameters: {
    docs: {
      page: () => (
        <>
          <Title>Readme</Title>
          <br />
          <Subtitle>
            Note, thise story is explains more about the basic usage of the
            component in your project, how to import and render it. You may find
            examples of code at the story Example.
          </Subtitle>
          <Description>
            Use `Tooltip` when you want to explain user the purpose of some
            elements or blocks. To setup `Tooltip` use next `props`:
          </Description>
          <Description>1. `rigt` to show the `TooltipArrow` right.</Description>
          <Description>2. `left` to how the `TooltipArrow` left.</Description>
          <br />
          <Subtitle>
            To integrate Tooltip for using at your product, please read the
            information below, or check the example code in stories.
          </Subtitle>
          <Description>
            1. `import &#123; Tooltip, TooltipArrow, TooltipInner &#125; from
            'seturon';`
          </Description>
          <Description>2. Set the component on the needed page.</Description>
          <Description>3. Set needed `props` at the component.</Description>
          <br />
          <Subtitle>
            To have more idea about the code and usage of the Tooltip
            components, check it out:
          </Subtitle>
          <NavLink href="http://design.seturon.io/?path=/docs/components-tooltip--example">
            Example
          </NavLink>
        </>
      ),
    },
  },
  args: {
    right: true,
    left: false,
  },
  argTypes: {
    props: {
      description: null,
      table: {
        type: {
          summary: null,
          detail: null,
        },
      },
      control: {
        type: null,
      },
    },
  },
};

export const Readme = (args) => {
  const [hidden, setHidden] = useState(true);

  return (
    <Container dFlex alignItemsCenter justifyContentCenter>
      <Button
        primary
        onMouseEnter={() => setHidden(!hidden)}
        onMouseLeave={() => setHidden(!hidden)}
      >
        Apply the new course
      </Button>
      <Tooltip hidden={hidden} {...args}>
        <TooltipArrow {...args} />
        <TooltipInner {...args}>Press to apply</TooltipInner>
      </Tooltip>
    </Container>
  );
};

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

  return (
    <Container dFlex alignItemsCenter justifyContentCenter>
      <Button
        primary
        onMouseEnter={() => setHidden(!hidden)}
        onMouseLeave={() => setHidden(!hidden)}
      >
        Apply the new course
      </Button>
      <Tooltip hidden={hidden} right>
        <TooltipArrow right />
        <TooltipInner right>Press to apply</TooltipInner>
      </Tooltip>
    </Container>
  );
};

Example.storyName = "Example";

Example.parameters = {
  component: Tooltip,
  docs: {
    page: () => (
      <>
        <Title>Example</Title>
        <Subtitle>Props</Subtitle>
        <Description>
          Note, to use the `Tooltip` component you'll need to make a sepparate
          React compomemt by using `useState` hook
        </Description>
        <Description>
          Use `Tooltip` when you want to explain user the purpose of some
          elements or blocks. To setup `Tooltip` use next `props`:
        </Description>
        <Description>1. `rigt` to show the `TooltipArrow` right.</Description>
        <Description>2. `left` to how the `TooltipArrow` left.</Description>
        <br />
        <Subtitle>
          Check the code below to get an idea of how to use it at your product👇
        </Subtitle>
        <Primary name="Example" />
      </>
    ),
  },
};
