"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = AvatarBehaviour;

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

var _skeletonCustomization = _interopRequireDefault(require("../../customization-cornor/skeletonCustomization"));

var _Avatar = _interopRequireWildcard(require("./Avatar.propTypes"));

var _reducerHandler = _interopRequireDefault(require("../../libraries/reducerHandler"));

var _Avatar2 = _interopRequireDefault(require("./Avatar.reducers"));

var _Avatar3 = _interopRequireDefault(require("./Avatar.hooks"));

var avatarConstants = _interopRequireWildcard(require("./Avatar.actionConstants"));

var _excluded = ["renderComponent"];

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(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; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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; }

function AvatarBehaviour(props) {
  var _useCommonReducer = (0, _reducerHandler["default"])(_Avatar2["default"], props.reducer, {
    showAvatar: props.photoUrl ? true : false
  }),
      _useCommonReducer$sta = _useCommonReducer.state,
      state = _useCommonReducer$sta === void 0 ? {} : _useCommonReducer$sta,
      dispatch = _useCommonReducer.dispatch;

  var renderProps = {
    onError: function onError() {
      dispatch({
        type: avatarConstants.INVALID_PHOTOURL_PUSH
      });
    },
    onLoad: function onLoad() {
      dispatch({
        type: avatarConstants.VALID_PHOTOURL_PUSH
      });
    },
    getContent: _Avatar3["default"].getContent,
    getAbbr: _Avatar3["default"].getAbbr,
    showAvatar: state.showAvatar
  };

  var renderComponent = props.renderComponent,
      basicProps = _objectWithoutProperties(props, _excluded);

  return /*#__PURE__*/_react["default"].createElement(_skeletonCustomization["default"], {
    basicProps: basicProps,
    renderProps: renderProps,
    component: renderComponent
  });
}

AvatarBehaviour.propTypes = _Avatar["default"];
AvatarBehaviour.defaultProps = _Avatar.defaultProps;
AvatarBehaviour.propsDescription = _Avatar.propsDescription;