import _defineProperty from"@babel/runtime/helpers/defineProperty";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["alt","src","getImageSettings","subscribeToRef"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import React,{forwardRef,useMemo}from"react";import{getLastPoint,useBreakpoints}from"../../hooks/useBreakpoints";import{useTheme}from"../Theme";import{defaultGetImageSettings,getConvertedImages,getSrcHash}from"./helper";export var Picture=forwardRef(function(a,b){var c,d=a.alt,e=void 0===d?"":d,f=a.src,g=a.getImageSettings,h=void 0===g?defaultGetImageSettings:g,i=a.subscribeToRef,j=_objectWithoutProperties(a,_excluded),k=useTheme(),l=k.theme,m=useMemo(function(){var a=getConvertedImages(f,h);return[a,a.reduce(function(b,a){var c=a.size,d=void 0===c?0:c;return _objectSpread(_objectSpread({},b),{},_defineProperty({},d,d))},{})]},[getSrcHash(f)]),n=_slicedToArray(m,2),o=n[0],p=n[1],q=+(null!==(c=getLastPoint(useBreakpoints({map:p,isActive:!0,ref:i})))&&void 0!==c?c:-1),r=useMemo(function(){return o.filter(function(a){var b=a.size,c=a.theme;return(!c||l.color.primary===c)&&("number"!=typeof b||q===b)}).sort(function(c,a){return c.descriptor&&a.descriptor?+c.descriptor.replace(/[^0-9.]+/g,"")<+a.descriptor.replace(/[^0-9.]+/g,"")?-1:1:0})},[q,l,o]),s=useMemo(function(){var a;if(0===r.length)return[];if(1<r.length){var b;return[null===(b=r[0])||void 0===b?void 0:b.src,r.map(function(a){var b=a.src,c=a.descriptor;return"".concat(b," ").concat(c)}).join(",")]}return[null===(a=r[0])||void 0===a?void 0:a.src]},[r]),t=_slicedToArray(s,2),u=t[0],v=t[1];return u?React.createElement("img",Object.assign({},j,{ref:b,alt:e,src:u,srcSet:v})):null});
//# sourceMappingURL=Picture.js.map