"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _system = require("@wix/wix-ui-icons-common/system");
var _Arc = _interopRequireDefault(require("./components/Arc"));
var _Heading = _interopRequireDefault(require("../Heading"));
var _Tooltip = _interopRequireDefault(require("../Tooltip"));
var _Loader = require("./Loader.constants");
var _LoaderSt = require("./Loader.st.css.js");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Loader/Loader.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 FULL_CIRCLE_ANGLE = 359;
var sizeToSuccessIconMap = {
  tiny: /*#__PURE__*/_react.default.createElement(_system.ToggleOn, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 24,
      columnNumber: 9
    }
  }),
  small: /*#__PURE__*/_react.default.createElement(_system.CircleLoaderCheckSmall, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 25,
      columnNumber: 10
    }
  }),
  medium: /*#__PURE__*/_react.default.createElement(_system.CircleLoaderCheck, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 26,
      columnNumber: 11
    }
  }),
  large: /*#__PURE__*/_react.default.createElement(_system.CircleLoaderCheck, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 27,
      columnNumber: 10
    }
  })
};
var sizeToErrorIconMap = {
  tiny: /*#__PURE__*/_react.default.createElement(_system.FormFieldError, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 31,
      columnNumber: 9
    }
  }),
  small: /*#__PURE__*/_react.default.createElement(_system.FormFieldErrorSmall, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 32,
      columnNumber: 10
    }
  }),
  medium: /*#__PURE__*/_react.default.createElement(_system.FormFieldError, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 33,
      columnNumber: 11
    }
  }),
  large: /*#__PURE__*/_react.default.createElement(_system.FormFieldError, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 34,
      columnNumber: 10
    }
  })
};
var Loader = _ref => {
  var {
    size = 'medium',
    color = 'blue',
    text,
    status = 'loading',
    statusMessage,
    dataHook
  } = _ref;
  var loader = (0, _react.useMemo)(() => {
    var successIcon = sizeToSuccessIconMap[size];
    var errorIcon = sizeToErrorIconMap[size];
    var strokeWidth = _Loader.SIZE_TO_STROKE_WIDTH_MAP[size];
    var sizeInPx = _Loader.SIZES_TO_PIXELS_MAP[size];
    var isTerminalStatus = status === 'success' || status === 'error';
    var lightArcAngle = isTerminalStatus ? FULL_CIRCLE_ANGLE : _Loader.SIZE_TO_ARC_ANGLE_MAP[size].light;
    var darkArcAngle = isTerminalStatus ? FULL_CIRCLE_ANGLE : _Loader.SIZE_TO_ARC_ANGLE_MAP[size].dark;
    return /*#__PURE__*/_react.default.createElement("div", {
      className: _LoaderSt.classes.arcsContainer,
      style: {
        width: "".concat(sizeInPx, "px"),
        height: "".concat(sizeInPx, "px")
      },
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 62,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement(_Arc.default, {
      angle: lightArcAngle,
      className: _LoaderSt.classes.lightArc,
      strokeWidth: strokeWidth,
      viewBoxSize: sizeInPx,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 69,
        columnNumber: 9
      }
    }), /*#__PURE__*/_react.default.createElement(_Arc.default, {
      angle: darkArcAngle,
      className: _LoaderSt.classes.darkArc,
      strokeWidth: strokeWidth,
      viewBoxSize: sizeInPx,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 75,
        columnNumber: 9
      }
    }), isTerminalStatus && /*#__PURE__*/_react.default.createElement("div", {
      className: _LoaderSt.classes.statusIndicator,
      "data-hook": "loader-status-indicator",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 82,
        columnNumber: 11
      }
    }, status === 'success' && successIcon, status === 'error' && errorIcon));
  }, [status, size]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _LoaderSt.st)(_LoaderSt.classes.root, {
      size,
      color,
      status
    }),
    "data-hook": dataHook,
    "data-size": size,
    "data-color": color,
    "data-status": status,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 95,
      columnNumber: 5
    }
  }, statusMessage ? /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
    content: statusMessage,
    appendTo: "window",
    dataHook: "loader-tooltip",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 103,
      columnNumber: 9
    }
  }, loader) : loader, size !== 'tiny' && text && /*#__PURE__*/_react.default.createElement("div", {
    className: _LoaderSt.classes.text,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 114,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement(_Heading.default, {
    size: "extraTiny",
    dataHook: "loader-text",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 115,
      columnNumber: 11
    }
  }, text)));
};
Loader.displayName = 'Loader';
var _default = exports.default = Loader;
//# sourceMappingURL=Loader.js.map