"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
var _exportNames = {
  ICON_SIZE_12: true,
  ICON_SIZE_16: true,
  ICON_SIZE_24: true,
  ICON_SIZE_32: true,
  ICON_SIZE_48: true,
  ICON_SIZE_64: true,
  ICON_SIZE_96: true,
  ICON_SIZE_128: true,
  ICON_SIZE_192: true
};
exports.default = exports.ICON_SIZE_96 = exports.ICON_SIZE_64 = exports.ICON_SIZE_48 = exports.ICON_SIZE_32 = exports.ICON_SIZE_24 = exports.ICON_SIZE_192 = exports.ICON_SIZE_16 = exports.ICON_SIZE_128 = exports.ICON_SIZE_12 = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _constants = require("../../constants");

var _oldIconNames = _interopRequireDefault(require("./oldIconNames"));

var _symbols = _interopRequireDefault(require("./images/symbols.svg"));

var _constants2 = require("./constants");

Object.keys(_constants2).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _constants2[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _constants2[key];
    }
  });
});

var _utils = require("./utils");

var _OnDarkContext = _interopRequireDefault(require("../OnDarkContext"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
const ICON_SIZE_12 = '12';
exports.ICON_SIZE_12 = ICON_SIZE_12;
const ICON_SIZE_16 = '16';
exports.ICON_SIZE_16 = ICON_SIZE_16;
const ICON_SIZE_24 = '24';
exports.ICON_SIZE_24 = ICON_SIZE_24;
const ICON_SIZE_32 = '32';
exports.ICON_SIZE_32 = ICON_SIZE_32;
const ICON_SIZE_48 = '48';
exports.ICON_SIZE_48 = ICON_SIZE_48;
const ICON_SIZE_64 = '64';
exports.ICON_SIZE_64 = ICON_SIZE_64;
const ICON_SIZE_96 = '96';
exports.ICON_SIZE_96 = ICON_SIZE_96;
const ICON_SIZE_128 = '128';
exports.ICON_SIZE_128 = ICON_SIZE_128;
const ICON_SIZE_192 = '192';
exports.ICON_SIZE_192 = ICON_SIZE_192;
const oldIconSizes = {
  sm: ICON_SIZE_16,
  md: ICON_SIZE_32,
  lg: ICON_SIZE_48,
  xl: ICON_SIZE_64,
  xxl: ICON_SIZE_96
};

const getHref = (name, size) => {
  let iconSize = '16';

  if ((size === '12' || size === '24') && _constants2.NAMES_12.indexOf(name) !== -1) {
    iconSize = '12';
  }

  return `${_symbols.default}#${name}:${iconSize}`;
};

/**
 * `Icons` are small symbolic images used for two things: to help quickly find the right control on the screen and to
 * bring user attention to something that requires consideration. In the former case, `Icon` typically acts as a part
 * of a [Button](#!/Button) and helps differentiate this particular [Button](#!/Button) from others. `Icons` come in several
 * standard sizes.
 * @since 0.0.35
 */
const Icon = ({
  baseClassName = `${_constants.CLS_PREFIX}icon`,
  className,
  name,
  src,
  size,
  intent,
  animation,
  rotate,
  flipHorizontal = false,
  flipVertical = false,
  children,
  alt = '',
  ...props
}) => {
  const newSize = size && oldIconSizes[size] || size;
  const newName = name ? _oldIconNames.default[name] || name : null;
  return /*#__PURE__*/_react.default.createElement("span", (0, _extends2.default)({
    className: (0, _classnames.default)(baseClassName, {
      [`${baseClassName}--size-${newSize}`]: newSize,
      [`${baseClassName}--intent ${baseClassName}--${intent}`]: intent,
      [`${baseClassName}--animation-${animation}`]: animation,
      [`${baseClassName}--rotate-${rotate}`]: rotate,
      [`${baseClassName}--flip-horizontal`]: flipHorizontal,
      [`${baseClassName}--flip-vertical`]: flipVertical,
      [`${baseClassName}--on-dark`]: (0, _react.useContext)(_OnDarkContext.default)
    }, className)
  }, props), newName ? /*#__PURE__*/_react.default.createElement("svg", {
    focusable: "false"
  }, /*#__PURE__*/_react.default.createElement("use", {
    href: getHref(newName, newSize)
  })) : src && /*#__PURE__*/_react.default.createElement("img", {
    src: src,
    alt: alt
  }) || children);
};

Icon.create = _utils.create;
var _default = Icon;
exports.default = _default;