var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, colog } from './Shared/helper.js';
import style from './CIcon.module.css';

//component - CoreUI / CIconRaw

var CIconRaw = function CIconRaw(props) {
  var className = props.className,
      name = props.name,
      content = props.content,
      customClasses = props.customClasses,
      size = props.size,
      src = props.src,
      title = props.title,
      use = props.use,
      attributes = _objectWithoutProperties(props, ['className', 'name', 'content', 'customClasses', 'size', 'src', 'title', 'use']);

  // methods

  var toCamelCase = function toCamelCase(str) {
    return str.replace(/([-_][a-z0-9])/ig, function ($1) {
      return $1.toUpperCase().replace('-', '');
    });
  };

  //vars

  var iconName = function () {
    var iconNameIsKebabCase = name && name.includes('-');
    return iconNameIsKebabCase ? toCamelCase(name) : name;
  }();
  var titleCode = function () {
    return title ? '<title>' + title + '</title>' : '';
  }();
  var code = function () {
    if (content) {
      return content;
    } else if (React.icons) {
      return React.icons[iconName] ? React.icons[iconName] : React.icons['cil' + iconName] ? React.icons['cil' + iconName] : colog('Not existing icon: ' + iconName);
    }
    return content;
  }();
  var iconCode = function () {
    return Array.isArray(code) ? code[1] || code[0] : code;
  }();
  var scale = function () {
    return Array.isArray(code) && code.length > 1 ? code[0] : '64 64';
  }();
  var viewBox = function () {
    return attributes.viewBox || '0 0 ' + scale;
  }();
  var computedSize = function () {
    var addCustom = !size && (attributes.width || attributes.height);
    return size === 'custom' || addCustom ? 'custom-size' : size;
  }();
  //console.log(iconName, computedSize)
  /*
    computedClasses () {
        const size = this.computedSize
        return this.customClasses || ['c-icon', { [`c-icon-${size}`]: size }]
      }
  */

  //render

  var class1 = mapToCssModules(classNames(className, 'c-icon', computedSize ? 'c-icon-' + computedSize : ''));

  var class2 = mapToCssModules(classNames('c-icon', computedSize ? 'c-icon-' + computedSize : ''), style);

  var classes = customClasses || class1 + ' ' + class2;

  //console.log(code, viewBox, classes, titleCode+' - '+iconCode);
  //v-html={titleCode+iconCode}

  return React.createElement(
    React.Fragment,
    null,
    !src && !use ? React.createElement('svg', _extends({}, attributes, {
      xmlns: 'http://www.w3.org/2000/svg',
      viewBox: viewBox,
      className: classes,
      role: 'img',
      dangerouslySetInnerHTML: { __html: titleCode + iconCode }
    })) : src ? React.createElement('img', _extends({}, attributes, {
      src: src,
      role: 'img'
    })) : use ? React.createElement(
      'svg',
      _extends({}, attributes, {
        xmlns: 'http://www.w3.org/2000/svg',
        className: classes,
        role: 'img'
      }),
      React.createElement('use', { href: use })
    ) : ''
  );
};

CIconRaw.propTypes = process.env.NODE_ENV !== "production" ? {
  tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  className: PropTypes.string,
  //
  name: PropTypes.string,
  content: PropTypes.oneOfType([String, Array]),
  size: PropTypes.oneOf(['custom', 'custom-size', 'sm', 'lg', 'xl', '2xl', '3xl', '4xl', '5xl', '6xl', '7xl', '8xl', '9xl']),
  customClasses: PropTypes.oneOfType([String, Array, Object]),
  src: PropTypes.string,
  title: PropTypes.string,
  use: PropTypes.string
} : {};

CIconRaw.defaultProps = {};

export default CIconRaw;