"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _generateDataAttr = require("../utils/generateDataAttr");
var _CloseButtonSt = require("./CloseButton.st.css.js");
var _ButtonCore = _interopRequireDefault(require("../Button/ButtonCore"));
var _ThemeContext = require("../ThemeProvider/ThemeContext");
var _system = require("@wix/wix-ui-icons-common/system");
var _CloseButton = require("./CloseButton.constants");
var _WixDesignSystemIconThemeProvider = require("../WixDesignSystemIconThemeProvider");
var _excluded = ["skin", "size", "disabled", "autoFocus", "className", "dataHook", "children"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/CloseButton/CloseButton.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var CHILD_SIZE = '18px';
var CloseButton = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
  var _themeIcons$CloseButt, _themeIcons$CloseButt2;
  var {
      skin = _CloseButton.SKINS.standard,
      size = _CloseButton.SIZES.small,
      disabled = false,
      autoFocus = false,
      className,
      dataHook,
      children
    } = _ref,
    rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var icons = (0, _WixDesignSystemIconThemeProvider.useIcons)('CloseButton', {
    Close: _system.Close,
    CloseLarge: _system.CloseLarge
  });
  var sizeToIconMap = {
    small: /*#__PURE__*/_react.default.createElement(icons.Close, {
      "data-hook": "close",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 40,
        columnNumber: 14
      }
    }),
    medium: /*#__PURE__*/_react.default.createElement(icons.CloseLarge, {
      "data-hook": "close-medium",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 41,
        columnNumber: 15
      }
    }),
    large: /*#__PURE__*/_react.default.createElement(icons.CloseLarge, {
      "data-hook": "close-large",
      size: "12",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 42,
        columnNumber: 14
      }
    })
  };
  var theme = (0, _react.useContext)(_ThemeContext.ThemeContext);
  var {
    icons: themeIcons
  } = theme || {};
  var closeIcon = (_themeIcons$CloseButt = themeIcons == null || (_themeIcons$CloseButt2 = themeIcons.CloseButton) == null ? void 0 : _themeIcons$CloseButt2[size]) !== null && _themeIcons$CloseButt !== void 0 ? _themeIcons$CloseButt : sizeToIconMap[size];
  var buttonRef = (0, _react.useRef)(null);
  (0, _react.useImperativeHandle)(ref, () => buttonRef.current, []);
  (0, _react.useEffect)(() => {
    if (autoFocus) {
      var _buttonRef$current;
      (_buttonRef$current = buttonRef.current) == null || _buttonRef$current.focus();
    }
  }, [autoFocus]);
  return /*#__PURE__*/_react.default.createElement(_ButtonCore.default, (0, _extends2.default)({
    ref: buttonRef
  }, rest, {
    disabled: disabled,
    className: (0, _CloseButtonSt.st)(_CloseButtonSt.classes.root, {
      skin,
      size
    }, className)
  }, (0, _generateDataAttr.generateDataAttr)({
    skin,
    size
  }, ['skin', 'size']), {
    "data-hook": dataHook,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 61,
      columnNumber: 7
    }
  }), children ? /*#__PURE__*/_react.default.cloneElement(children, {
    size: CHILD_SIZE,
    width: CHILD_SIZE,
    height: CHILD_SIZE
  }) : closeIcon);
});
CloseButton.displayName = 'CloseButton';
var _default = exports.default = CloseButton;
//# sourceMappingURL=CloseButton.js.map