import { ComponentMeta, ComponentStory } from '@storybook/react';
import { IntlProvider } from 'react-intl';
import CodeComponent from './code';

/**
 * Code - Storybook Meta
 */
export default {
  title: 'Molecules/Layout/Code',
  component: CodeComponent,
  args: {
    filterOutput: false,
    outputPattern: '#output#',
  },
  argTypes: {
    children: {
      control: {
        type: 'text',
      },
      description: 'The code sample.',
      type: {
        name: 'string',
        required: true,
      },
    },
    filterOutput: {
      control: {
        type: 'boolean',
      },
      description: 'Filter the command line output.',
      table: {
        category: 'Options',
        defaultValue: { summary: false },
      },
      type: {
        name: 'boolean',
        required: false,
      },
    },
    language: {
      control: {
        type: 'text',
      },
      description: 'The code sample language.',
      type: {
        name: 'string',
        required: true,
      },
    },
    plugins: {
      description: 'An array of Prism plugins to activate.',
      type: {
        name: 'object',
        required: false,
        value: {},
      },
    },
    outputPattern: {
      control: {
        type: 'text',
      },
      description: 'The command line output pattern.',
      table: {
        category: 'Options',
        defaultValue: { summary: '#output#' },
      },
      type: {
        name: 'string',
        required: false,
      },
    },
  },
  decorators: [
    (Story) => (
      <IntlProvider locale="en">
        <Story />
      </IntlProvider>
    ),
  ],
} as ComponentMeta<typeof CodeComponent>;

const Template: ComponentStory<typeof CodeComponent> = (args) => (
  <CodeComponent {...args} />
);

const javascriptCodeSample = `
const foo = () => {
  return 'bar';
}
`;

/**
 * Code Stories - Code sample
 */
export const CodeSample = Template.bind({});
CodeSample.args = {
  children: javascriptCodeSample,
  language: 'javascript',
  plugins: ['line-numbers'],
};

const commandLineCode = `
ls -lah
#output#drwxr-x---+ 42 armand armand 4,0K 17 avril 11:15  .
#output#drwxr-xr-x   4 root   root   4,0K 30 mai    2021  ..
#output#-rw-r--r--   1 armand armand 2,0K 21 juil.  2021  .xinitrc
`;

/**
 * Code Stories - Command Line
 */
export const CommandLine = Template.bind({});
CommandLine.args = {
  children: commandLineCode,
  filterOutput: true,
  language: 'bash',
  plugins: ['command-line'],
};
 name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/www.armandphilippot.com/tree/?h=v2.0.0&amp;id=223e164ce8639ac2079d39bb04d7d03f9634ffed'>root</a>/<a href='/www.armandphilippot.com/tree/src?h=v2.0.0&amp;id=223e164ce8639ac2079d39bb04d7d03f9634ffed'>src</a>/<a href='/www.armandphilippot.com/tree/src/components?h=v2.0.0&amp;id=223e164ce8639ac2079d39bb04d7d03f9634ffed'>components</a>/<a href='/www.armandphilippot.com/tree/src/components/PostHeader?h=v2.0.0&amp;id=223e164ce8639ac2079d39bb04d7d03f9634ffed'>PostHeader</a>/<a href='/www.armandphilippot.com/tree/src/components/PostHeader/PostHeader.module.scss?h=v2.0.0&amp;id=223e164ce8639ac2079d39bb04d7d03f9634ffed'>PostHeader.module.scss</a></div><div class='content'>blob: f013651baaa4cc44eae3bc155e081edd4ee73cfb (<a href='/www.armandphilippot.com/plain/src/components/PostHeader/PostHeader.module.scss?h=v2.0.0&amp;id=223e164ce8639ac2079d39bb04d7d03f9634ffed'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
</pre></td>
<td class='lines'><pre><code>