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

import StarRating from '.';

export default {
  title: 'Theme/Molecules/Star Rating',
  component: StarRating,
  argTypes: {
    numOfStars: {
      name: 'numOfStars',
      type: { name: 'number', required: true },
      defaultValue: '',
      description: 'Total number.',
      table: {
        type: { summary: 'one of 5 and 10' },
        defaultValue: { summary: '' },
      },
      control: {
        type: 'inline-radio',
        options: [5, 10],
      },
    },
    rating: {
      name: 'rating',
      type: { name: 'number', required: true },
      defaultValue: '',
      description: 'Rate number/s.',
      table: {
        type: { summary: 'number | array of numbers' },
        defaultValue: { summary: '' },
      },
      control: { type: 'range', min: 0, max: 10, step: 0.5 },
    },
    halfStars: {
      name: 'halfStars',
      type: { name: 'boolean', required: false },
      defaultValue: true,
      description: 'True enables showing half-filled stars.',
      table: {
        type: { summary: 'boolean' },
        defaultValue: { summary: true },
      },
    },
    iconFull: {
      name: 'iconFull',
      type: { name: 'element | component', required: false },
      defaultValue: '',
      description: 'A component to show for full-filled stars.',
      table: {
        type: { summary: 'element | component' },
        defaultValue: { summary: '' },
      },
      control: { type: null },
    },
    iconHalf: {
      name: 'iconHalf',
      type: { name: 'element | component', required: false },
      defaultValue: '',
      description: 'a component to show for half-filled stars.',
      table: {
        type: { summary: 'element | component' },
        defaultValue: { summary: '' },
      },
      control: { type: null },
    },
    iconEmpty: {
      name: 'iconEmpty',
      type: { name: 'element | component', required: false },
      defaultValue: '',
      description: 'A component to show for empty stars.',
      table: {
        type: { summary: 'element | component' },
        defaultValue: { summary: '' },
      },
      control: { type: null },
    },
  },
  parameters: {
    docs: {
      description: {
        component:
          'A component that accepts the rate numbers and the total number and generates a rating div.',
      },
      page: () => (
        <>
          <Title />
          <Description />
          <Primary />
          <ArgsTable story={PRIMARY_STORY} />
        </>
      ),
    },
  },
};

const Template = (args) => <StarRating {...args} />;

export const Default = Template.bind({});
Default.args = {
  numOfStars: 10,
  rating: 6.5,
  halfStars: true,
};
