"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SvgIcon = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _useId = _interopRequireDefault(require("../utilities/useId"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// a type for react icon components that makes the 'title' prop optional & removes 'children' from type

const SvgIcon = _ref => {
  let {
    ariaHidden,
    className,
    children,
    description,
    id,
    inversed,
    title,
    viewBox,
    ...otherProps
  } = _ref;
  const svgClasses = (0, _classnames.default)('ds-c-icon', {
    'ds-c-icon--inverse': inversed
  }, className);
  const rootId = (0, _useId.default)('icon--', id);
  const titleId = `${rootId}__title`;
  const descriptionId = `${rootId}__desc`;
  const ariaLabelledBy = description ? `${titleId} ${descriptionId}` : titleId;
  const isSrVisible = !ariaHidden;
  const screenReaderProps = {};
  if (isSrVisible) {
    screenReaderProps['aria-labelledby'] = ariaLabelledBy;
    screenReaderProps['role'] = 'img';
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", {
    "aria-hidden": ariaHidden,
    className: svgClasses,
    id: id ?? isSrVisible ? rootId : undefined,
    viewBox: viewBox,
    xmlns: "http://www.w3.org/2000/svg",
    ...screenReaderProps,
    ...otherProps,
    children: [isSrVisible && /*#__PURE__*/(0, _jsxRuntime.jsx)("title", {
      id: titleId,
      children: title
    }), isSrVisible && description && /*#__PURE__*/(0, _jsxRuntime.jsx)("desc", {
      id: descriptionId,
      children: description
    }), children]
  });
};
exports.SvgIcon = SvgIcon;
SvgIcon.defaultProps = {
  ariaHidden: true,
  inversed: false
};