import './button.scss';

export const createButton =
  ({
    elementType = 'a',
    color = 'primary',
    size = 'regular',
    link = '#',
    preventClick = true,
    label,
    icon,
    iconPosition,
    onClick,
  }) => {
    const btn = document.createElement(elementType);
    btn.innerHTML = label;
    btn.addEventListener('click', onClick);
    const classes = ['btn', color, 'btn-' + size];
    if (iconPosition && iconPosition !== 'none' && icon) {
      classes.push(iconPosition);
      classes.push('icon-' + icon);
    }
    btn.className = classes.join(' ');
    if (link && elementType === 'a') {
      btn.href = link;
    }

    if (preventClick) {
      btn.addEventListener('click', (e) => {
        e.preventDefault();
      })
    }

    return btn;
  };

