'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _icons = require('@fishx/icons');

var FishxIcons = _interopRequireWildcard(_icons);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var __rest = undefined && undefined.__rest || function (s, e) {
    var t = {};
    for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
    }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
        if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
    }
    return t;
};

function IconFont(props) {
    var type = props.type,
        url = props.url,
        rest = __rest(props, ["type", "url"]);

    var Icon = (0, _react.useMemo)(function () {
        return (0, _icons.createFromIconfontCN)({
            scriptUrl: url
        });
    }, [url]);
    var Component = function Component(_ref) {
        var type = _ref.type;

        if (type) {
            var FishIcon = FishxIcons[type];
            return _react2['default'].createElement(FishIcon, rest);
        } else return null;
    };
    if (url) {
        return _react2['default'].createElement(Icon, (0, _extends3['default'])({ type: type }, rest));
    } else {
        return _react2['default'].createElement(Component, (0, _extends3['default'])({ type: type }, rest));
    }
}
exports['default'] = IconFont;
module.exports = exports['default'];