"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SvgIcon = void 0;
var _compat = _interopRequireDefault(require("preact/compat"));
var _classnames = _interopRequireDefault(require("classnames"));
var _useId = _interopRequireDefault(require("../utilities/useId"));
var _excluded = ["ariaHidden", "className", "children", "description", "id", "inversed", "title", "viewBox"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
// a type for react icon components that makes the 'title' prop optional & removes 'children' from type

var SvgIcon = function SvgIcon(_ref) {
  var ariaHidden = _ref.ariaHidden,
    className = _ref.className,
    children = _ref.children,
    description = _ref.description,
    id = _ref.id,
    inversed = _ref.inversed,
    title = _ref.title,
    viewBox = _ref.viewBox,
    otherProps = _objectWithoutProperties(_ref, _excluded);
  var svgClasses = (0, _classnames.default)('ds-c-icon', {
    'ds-c-icon--inverse': inversed
  }, className);
  var rootId = (0, _useId.default)('icon--', id);
  var titleId = "".concat(rootId, "__title");
  var descriptionId = "".concat(rootId, "__desc");
  var ariaLabelledBy = description ? "".concat(titleId, " ").concat(descriptionId) : titleId;
  var isSrVisible = !ariaHidden;
  var screenReaderProps = {};
  if (isSrVisible) {
    screenReaderProps['aria-labelledby'] = ariaLabelledBy;
    screenReaderProps['role'] = 'img';
  }
  return /*#__PURE__*/_compat.default.createElement("svg", _extends({
    "aria-hidden": ariaHidden,
    className: svgClasses,
    id: (id !== null && id !== void 0 ? id : isSrVisible) ? rootId : undefined,
    viewBox: viewBox,
    xmlns: "http://www.w3.org/2000/svg"
  }, screenReaderProps, otherProps), isSrVisible && /*#__PURE__*/_compat.default.createElement("title", {
    id: titleId
  }, title), isSrVisible && description && /*#__PURE__*/_compat.default.createElement("desc", {
    id: descriptionId
  }, description), children);
};
exports.SvgIcon = SvgIcon;
SvgIcon.defaultProps = {
  ariaHidden: true,
  inversed: false
};