"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends2=require("babel-runtime/helpers/extends"),_extends3=_interopRequireDefault(_extends2),_defineProperty2=require("babel-runtime/helpers/defineProperty"),_defineProperty3=_interopRequireDefault(_defineProperty2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_react=require("react"),React=_interopRequireWildcard(_react),_reactDom=require("react-dom"),ReactDOM=_interopRequireWildcard(_reactDom),_icon=require("../icon"),_icon2=_interopRequireDefault(_icon),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var __rest=function(e,t){var r={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(a=Object.getOwnPropertySymbols(e);s<a.length;s++)t.indexOf(a[s])<0&&(r[a[s]]=e[a[s]])}return r},Avatar=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var a=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return a.setScale=function(){var e=a.avatarChildren;if(e){var t=e.offsetWidth,r=ReactDOM.findDOMNode(a).getBoundingClientRect().width;r-8<t?a.setState({scale:(r-8)/t}):a.setState({scale:1})}},a.handleImgLoadError=function(){return a.setState({isImgExist:!1})},a.state={scale:1,isImgExist:!0},a}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"componentDidMount",value:function(){this.setScale()}},{key:"componentDidUpdate",value:function(e,t){(e.children!==this.props.children||t.scale!==this.state.scale&&1===this.state.scale)&&this.setScale()}},{key:"render",value:function(){var e,t,r=this,a=this.props,s=a.prefixCls,i=a.shape,l=a.size,n=a.src,o=a.icon,c=a.className,u=__rest(a,["prefixCls","shape","size","src","icon","className"]),f=(0,_classnames2.default)((e={},(0,_defineProperty3.default)(e,s+"-lg","large"===l),(0,_defineProperty3.default)(e,s+"-sm","small"===l),e)),p=(0,_classnames2.default)(s,c,f,(t={},(0,_defineProperty3.default)(t,s+"-"+i,i),(0,_defineProperty3.default)(t,s+"-image",n&&this.state.isImgExist),(0,_defineProperty3.default)(t,s+"-icon",o),t)),d=this.props.children;if(n&&this.state.isImgExist)d=React.createElement("img",{src:n,onError:this.handleImgLoadError});else if(o)d=React.createElement(_icon2.default,{type:o});else{var _=this.avatarChildren;if(_||1!==this.state.scale){var h={msTransform:"scale("+this.state.scale+")",WebkitTransform:"scale("+this.state.scale+")",transform:"scale("+this.state.scale+")",position:"absolute",display:"inline-block",left:"calc(50% - "+Math.round(_.offsetWidth/2)+"px)"};d=React.createElement("span",{className:s+"-string",ref:function(e){return r.avatarChildren=e},style:h},d)}else d=React.createElement("span",{className:s+"-string",ref:function(e){return r.avatarChildren=e}},d)}return React.createElement("span",(0,_extends3.default)({},u,{className:p}),d)}}]),t}(React.Component);(exports.default=Avatar).defaultProps={prefixCls:"dt-avatar",shape:"circle",size:"default"},module.exports=exports.default;