import React from 'react';
import PropTypes from 'prop-types';

// Style
/* istanbul ignore next */
if (typeof window !== 'undefined') require('./style.scss');

const Method = ({ type, width, className, ...attrs }) => (
  <span {...attrs} className={[`Method Method_${type}`, className || ''].join(' ')} style={{ width }}>
    {type === 'options' ? 'optns' : type}
  </span>
);

Method.propTypes = {
  className: PropTypes.string,
  type: PropTypes.oneOf([
    'basic',
    'cnnct',
    'delete',
    'error',
    'fn',
    'head',
    'get',
    'link',
    'options',
    'patch',
    'post',
    'put',
    'trace',
  ]).isRequired,
  width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};

Method.defaultProps = {
  width: 'auto',
};

export default Method;
