import React from 'react';
import {
  Title,
  Description,
  Primary,
  Stories,
  PRIMARY_STORY,
  ArgsTable,
} from '@storybook/addon-docs/blocks';

import CountNumber from '.';

export default {
  title: 'Theme/Molecules/Counter/Count Number',
  component: CountNumber,
  argTypes: {
    end: {
      name: 'end',
      type: { name: 'number', required: true },
      defaultValue: null,
      description: 'The number that the counter should end on.',
      table: {
        type: { summary: 'number' },
        defaultValue: { summary: null },
      },
    },
    start: {
      name: 'start',
      type: { name: 'number', required: false },
      defaultValue: 0,
      description: 'The number that the counter should start on.',
      table: {
        type: { summary: 'number' },
        defaultValue: { summary: 0 },
      },
    },
    increase: {
      name: 'increase',
      type: { name: 'boolean', required: false },
      defaultValue: true,
      description:
        'By default, the counter will increase, or count up. If you would like to create a count down, set this to false.',
      table: {
        type: { summary: 'boolean' },
        defaultValue: { summary: true },
      },
    },
    delay: {
      name: 'delay',
      type: { name: 'number', required: false },
      defaultValue: 0,
      description: 'Delay the counter to slow down the count up or count down.',
      table: {
        type: { summary: 'number' },
        defaultValue: { summary: 0 },
      },
    },
  },
  parameters: {
    docs: {
      description: {
        component:
          'The count number component is the inner component of `<Counter />`. It can be used to count a number up or down, depending on the context. Counting up is usually used for displaying how many articles or reviews a site has. Counting down can be used for a timer, for example a redirect timer in a splash page.',
      },
      page: () => (
        <>
          <Title />
          <Description />
          <Primary />
          <ArgsTable story={PRIMARY_STORY} />
          <Stories />
        </>
      ),
    },
  },
};

const DownTemplate = (args) => <CountNumber {...args} />;

export const CountDown = DownTemplate.bind({});
CountDown.args = {
  end: 0,
  start: 10,
  increase: false,
  delay: 1000,
};

const UpTemplate = (args) => <CountNumber {...args} />;

export const CountUp = UpTemplate.bind({});
CountUp.args = {
  end: 350,
};
