import React from "react";
import {
  Title,
  Subtitle,
  Description,
  Primary,
} from "@storybook/addon-docs/blocks";
import { Button } from "../../../../src/atoms/button";
import {
  FormCheck,
  FormCheckInput,
  FormControl,
  FormControlFile,
  FormControlPlainText,
  FormGroup,
  FormInline,
  FormLabel,
  FormText,
} from "../../../../src/atoms/form";
import { CheckboxImage } from "../../../../src/molecules/checkboxImage";
import { RadioImage } from "../../../../src/molecules/radioImage";
import { NavLink } from "../../../../src/atoms/nav";

export default {
  title: "Components/Form",
  component: FormControl,
  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>
            `Forms` may be used at all of your product to comunicate and collect
            the information form users. To setup `Forms` you may use next
            `props`:
          </Description>
          <Description>1. `FormLabel`</Description>
          <Description>
            - `require` to show the user that this field is required.
          </Description>
          <Description>- `success` fill with color.</Description>
          <Description>- `warning` fill with color.</Description>
          <Description>
            - `danger` fill with color. - `info` fill with color.
          </Description>
          <Description>- `loading` when loading.</Description>
          <Description>2. `FormControl`</Description>
          <Description>- setup the type of the field.</Description>
          <Description>
            - `textarea` in case you need to collect more information.
          </Description>
          <Description>
            - `select` when select. Setup a `placeholder` and `noOptionsMessage``.
          </Description>
          <Description>- `lg` for large size.</Description>
          <Description>- `sm` fro small size.</Description>
          <Description>- `disabled` if disabled.</Description>
          <Description>- `success` fill with color.</Description>
          <Description>- `warning` fill with color.</Description>
          <Description>- `danger` fill with color.</Description>
          <Description>- `info` fill with color.</Description>
          <Description>- `loading` when loading.</Description>
          <Description>3. `FormCheckInput`</Description>
          <Description>- setup the type of the field.</Description>
          <Description>- `disabled` if disabled.</Description>
          <br />
          <Subtitle>
            To integrate Form for using at your product, please read the
            information below, or check the example code in stories.
          </Subtitle>
          <Description>1. `import &#123;`</Description>
          <Description>`FormCheck,`</Description>
          <Description>`FormCheckInput,`</Description>
          <Description>`FormControl,`</Description>
          <Description>`FormControlFile,`</Description>
          <Description>`FormControlPlainText,`</Description>
          <Description>`FormGroup,`</Description>
          <Description>`FormInline,`</Description>
          <Description>`FormLabel,`</Description>
          <Description>`FormText,`</Description>
          <Description>`&#125; from 'seturon';`</Description>
          <Description>or</Description>
          <Description>
            `import &#123; CheckboxImage, RadioImage &#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 Form components,
            check it out:
          </Subtitle>
          <NavLink href="http://design.seturon.io/?path=/docs/components-form--example">
            Example
          </NavLink>
        </>
      ),
    },
  },
  args: {
    require: false,
    muted: false,
    textarea: false,
    disabled: false,
    success: false,
    warning: false,
    danger: false,
    info: false,
    loading: false,
  },
  argTypes: {
    props: {
      description: null,
      table: {
        type: {
          summary: null,
          detail: null,
        },
      },
      control: {
        type: null,
      },
    },
  },
};

export const Readme = (args) => (
  <form>
    <FormGroup>
      <FormLabel {...args}>Email</FormLabel>
      <FormControl {...args} type="email" placeholder="Enter email" />
      <FormText {...args}>
        We&#39;ll never share your email with anyone else.
      </FormText>
    </FormGroup>
    <FormGroup>
      <FormLabel require>Password</FormLabel>
      <FormControl type="password" placeholder="Password" />
    </FormGroup>
    <FormInline>
      <FormCheck m3>
        <FormLabel {...args}>
          <FormCheckInput type="checkbox" {...args} /> Checkbox to check
          <FormText {...args}>Check it</FormText>
        </FormLabel>
      </FormCheck>
    </FormInline>
    <Button block primary lg>
      Enter
    </Button>
  </form>
);

export const Example = () => (
  <>
    <form>
      <FormGroup>
        <FormLabel loading>Email</FormLabel>
        <FormControl loading type="email" placeholder="name@example.com" />
      </FormGroup>
      <FormGroup>
        <FormLabel require>Email</FormLabel>
        <FormControl type="email" placeholder="name@example.com" />
      </FormGroup>
      <FormGroup>
        <FormLabel>Success</FormLabel>
        <FormControl type="email" placeholder="success" success />
      </FormGroup>
      <FormGroup>
        <FormLabel>Warning</FormLabel>
        <FormControl type="email" placeholder="warning" warning />
      </FormGroup>
      <FormGroup>
        <FormLabel>Danger</FormLabel>
        <FormControl type="email" placeholder="danger" danger />
      </FormGroup>
      <FormGroup>
        <FormLabel>Example select</FormLabel>
        <FormControl
          select
          noOptionsMessage={() => "No results found"}
          placeholder="Choose from the list"
          options={[
            { value: "React", label: "React lessons", },
            { value: "Python", label: "Python lessons" },
            { value: "Reacts", label: "React new lessons" },
            { value: "Pythons", label: "Python new lessons" },
          ]}
        />
      </FormGroup>
      <FormGroup>
        <FormLabel>Example textarea</FormLabel>
        <FormControl textarea rows="6" />
      </FormGroup>
      <FormGroup>
        <FormLabel>Example file input</FormLabel>
        <FormControlFile type="file" />
      </FormGroup>
    </form>
    <br />
    <FormInline>
      <FormGroup>
        <FormControlPlainText
          type="text"
          readonly
          disabled
          value="email@example.com"
        />
      </FormGroup>
      <FormGroup mr4>
        <FormControl type="password" placeholder="Password" />
      </FormGroup>
      <Button lg mb3 primary>
        Confirm identity
      </Button>
    </FormInline>
    <br />
    <form>
      <FormCheck>
        <FormLabel>
          <FormCheckInput type="checkbox" /> Default checkbox
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel success>
          <FormCheckInput type="checkbox" /> Success checkbox
          <FormText success>success</FormText>
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel warning>
          <FormCheckInput type="checkbox" /> Warning checkbox
          <FormText warning>warning</FormText>
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel info>
          <FormCheckInput type="checkbox" /> Info checkbox
          <FormText info>info</FormText>
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel>
          <FormCheckInput disabled type="checkbox" /> Disabled checkbox
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel>
          <FormCheckInput type="radio" name="exampleRadios" /> Default radio
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel success>
          <FormCheckInput type="radio" /> Success radio
          <FormText success>success</FormText>
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel warning>
          <FormCheckInput type="radio" /> Warning radio
          <FormText warning>warning</FormText>
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel info>
          <FormCheckInput type="radio" /> Info radio
          <FormText info>info</FormText>
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel>
          <FormCheckInput type="radio" name="exampleRadios" /> Default radio
        </FormLabel>
      </FormCheck>
      <FormCheck>
        <FormLabel>
          <FormCheckInput disabled type="radio" name="exampleRadios" /> Disabled
          radio
        </FormLabel>
      </FormCheck>
    </form>
    <br />
    <form>
      <FormControl mb2 lg type="text" placeholder="Large" />
      <FormControl mb2 type="text" placeholder="Normal" />
      <FormControl mb2 sm type="text" placeholder="Small" />
    </form>
    <br />
    <CheckboxImage
      style={{ width: "15rem" }}
      mb5
      text="success"
      success
      src="https://storage.googleapis.com/seturon-prod/images/254ab6df-1c4e-4781-b4b7-7197722afff2.png"
    />
    <CheckboxImage
      style={{ width: "15rem" }}
      mb5
      text="warning"
      warning
      src="https://storage.googleapis.com/seturon-prod/images/254ab6df-1c4e-4781-b4b7-7197722afff2.png"
    />
    <CheckboxImage
      style={{ width: "15rem" }}
      mb5
      text="default"
      src="https://storage.googleapis.com/seturon-prod/images/254ab6df-1c4e-4781-b4b7-7197722afff2.png"
    />
    <br />
    <RadioImage
      style={{ width: "15rem" }}
      mb5
      text="success"
      success
      src="https://storage.googleapis.com/seturon-prod/images/254ab6df-1c4e-4781-b4b7-7197722afff2.png"
    />
    <RadioImage
      style={{ width: "15rem" }}
      mb5
      text="warning"
      warning
      src="https://storage.googleapis.com/seturon-prod/images/254ab6df-1c4e-4781-b4b7-7197722afff2.png"
    />
    <RadioImage
      style={{ width: "15rem" }}
      mb5
      text="default"
      src="https://storage.googleapis.com/seturon-prod/images/254ab6df-1c4e-4781-b4b7-7197722afff2.png"
    />
  </>
);

Example.storyName = "Example";

Example.parameters = {
  component: FormControl,
  docs: {
    page: () => (
      <>
        <Title>Example</Title>
        <Subtitle>Props</Subtitle>
        <Description>
          `Forms` may be used at all of your product to comunicate and collect
          the information form users. To setup `Forms` you may use next `props`:
        </Description>
        <Description>1. `FormLabel`</Description>
        <Description>
          - `require` to show the user that this field is required.
        </Description>
        <Description>- `success` fill with color.</Description>
        <Description>- `warning` fill with color.</Description>
        <Description>
          - `danger` fill with color. - `info` fill with color.
        </Description>
        <Description>- `loading` when loading.</Description>
        <Description>2. `FormControl`</Description>
        <Description>- setup the type of the field.</Description>
        <Description>
          - `textarea` in case you need to collect more information.
        </Description>
        <Description>
        - `select` when select. Setup a `placeholder` and `noOptionsMessage``.
        </Description>
        <Description>- `lg` for large size.</Description>
        <Description>- `sm` fro small size.</Description>
        <Description>- `disabled` if disabled.</Description>
        <Description>- `success` fill with color.</Description>
        <Description>- `warning` fill with color.</Description>
        <Description>- `danger` fill with color.</Description>
        <Description>- `info` fill with color.</Description>
        <Description>- `loading` when loading.</Description>
        <Description>3. `FormCheckInput`</Description>
        <Description>- setup the type of the field.</Description>
        <Description>- `disabled` if disabled.</Description>
        <br />
        <Subtitle>
          Check the code below to get an idea of how to use it at your product👇
        </Subtitle>
        <Primary name="Example" />
      </>
    ),
  },
};
