import React, { useState } from "react";
import {
  Title,
  Subtitle,
  Description,
  Primary,
} from "@storybook/addon-docs/blocks";
import { Button, LinkButton } from "../../../../src/atoms/button";
import { CloseIcon } from "../../../../src/atoms/icon";
import {
  Modal,
  ModalBody,
  ModalFooter,
  ModalHeader,
  ModalTitle,
} from "../../../../src/atoms/modal";
import { NavLink } from "../../../../src/atoms/nav";

export default {
  title: "Components/Modal",
  component: Modal,
  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>
            `Modal` can be used to extend the functionality of the one page, to
            not to redirect the user on the separate pages.
          </Description>
          <br />
          <Subtitle>
            To integrate Modal for using at your product, please read the
            information below, or check the example code in stories.
          </Subtitle>
          <Description>
            1. `import &#123; Modal, ModalBody, ModalFooter, ModalHeader,
            ModalTitle, &#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 Modal components,
            check it out:
          </Subtitle>
          <NavLink href="http://design.seturon.io/?path=/docs/components-modal--example">
            Example
          </NavLink>
        </>
      ),
    },
  },
  args: {
    theme: null,
    TransitionComponent: null,
    ModalWrapperComponent: null,
    ModalDialogComponent: null,
    ModalBackdropComponent: null,
    ModalContentComponent: null,
  },
  argTypes: {
    props: {
      description: null,
      table: {
        type: {
          summary: null,
          detail: null,
        },
      },
      control: {
        type: null,
      },
    },
  },
};

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

  return (
    <div>
      <Modal hidden={!hidden} toggle={() => {}}>
        <ModalHeader>
          <ModalTitle>About this Course</ModalTitle>

          <LinkButton onClick={() => {}}>
            <span aria-hidden="true">
              <CloseIcon width={16} height={16} fill={"#6E7191"} />
            </span>
          </LinkButton>
        </ModalHeader>

        <ModalBody>
          In this course, we'll look at the JavaScript language, and how it
          supports the Object-Oriented pattern, with a focus on the unique
          aspect of how JavaScript approaches OO. We'll explore a brief
          introduction to the jQuery library, which is widely used to do
          in-browser manipulation of the Document Object Model (DOM) and event
          handling. You'll also learn more about JavaScript Object Notation
          (JSON), which is commonly used as a syntax to exchange data between
          code running on the server (i.e. in PHP) and code running in the
          browser (JavaScript/jQuery).
        </ModalBody>

        <ModalFooter>
          <Button sm onClick={() => setHidden(!hidden)}>
            Close
          </Button>
        </ModalFooter>
      </Modal>

      <Button block primary onClick={() => setHidden(!hidden)}>
        Launch Modal
      </Button>
    </div>
  );
};

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

  return (
    <div>
      <Modal hidden={!hidden} toggle={() => {}}>
        <ModalHeader>
          <ModalTitle>About this Course</ModalTitle>

          <LinkButton onClick={() => {}}>
            <span aria-hidden="true">
              <CloseIcon width={16} height={16} fill={"#6E7191"} />
            </span>
          </LinkButton>
        </ModalHeader>

        <ModalBody>
          In this course, we'll look at the JavaScript language, and how it
          supports the Object-Oriented pattern, with a focus on the unique
          aspect of how JavaScript approaches OO. We'll explore a brief
          introduction to the jQuery library, which is widely used to do
          in-browser manipulation of the Document Object Model (DOM) and event
          handling. You'll also learn more about JavaScript Object Notation
          (JSON), which is commonly used as a syntax to exchange data between
          code running on the server (i.e. in PHP) and code running in the
          browser (JavaScript/jQuery).
        </ModalBody>

        <ModalFooter>
          <Button sm onClick={() => setHidden(!hidden)}>
            Close
          </Button>
        </ModalFooter>
      </Modal>

      <Button block primary onClick={() => setHidden(!hidden)}>
        Launch Modal
      </Button>
    </div>
  );
};

Example.storyName = "Example";

Example.parameters = {
  component: Modal,
  docs: {
    page: () => (
      <>
        <Title>Example</Title>
        <Subtitle>Props</Subtitle>
        <Description>
          Note, to use the `Modal` component you'll need to make a sepparate
          React compomemt by using `useState` hook
        </Description>
        <Description>
          `Modal` can be used to extend the functionality of the one page, to
          not to redirect the user on the separate pages.
        </Description>
        <br />
        <Subtitle>
          Check the code below to get an idea of how to use it at your product👇
        </Subtitle>
        <Primary name="Example" />
      </>
    ),
  },
};
