/**
 * Created by baoyinghai on 4/5/17.
 */
import React from 'react';


const getIconName = iconName => {
  if (typeof iconName === 'string') {
    return iconName;
  }
  return 'icon-xiangmuguanli_xuanze';
};

export const iconWrapper = (iconName, jsxEle, container, props = {}, style = {}) => {
  const iconNameStr = getIconName(iconName);
  if (!jsxEle) {
    // menu
    return (<i {...props} style={style} className={'ico iconfont ' + iconNameStr + ' menu-icon-alibb'} />);
  }
  if (container) {
    return (
      <container style={style} {...props}>
        <i className={'ico iconfont ' + iconNameStr + ' menu-icon-alibb'} />
        {jsxEle}
      </container>
    );
  }
  return (
    <div style={style} {...props}>
      <i className={'ico iconfont ' + iconNameStr + ' menu-icon-alibb'} />
      {React.cloneElement(jsxEle, { ...props })}
    </div>
  );
};

export const svgWrapper = iconName => {
  return (
    <svg className="svg-icon" aria-hidden="true">
      <use xlinkHref={'#' + iconName} />
    </svg>
  );
};

