import _defineProperty from"@babel/runtime/helpers/defineProperty";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["preview","maxHeight","content","size","lessIcon","lessLabel","children","moreIcon","moreLabel","className","lineClamp","buttonIndent","buttonAlign","style"];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"./Spoiler.css";import React,{forwardRef}from"react";import{Text}from"../Text";import{getElementSize}from"../../hooks/useComponentSize";import{useFlag}from"../../hooks/useFlag";import{useForkRef}from"../../hooks/useForkRef";import{useRefs}from"../../hooks/useRefs";import{useResizeObserved}from"../../hooks/useResizeObserved";import{cnMixSpace}from"../../mixs/MixSpace";import{cn}from"../../utils/bem";import{SpoilerButton}from"./SpoilerButton";import{defaultSpoilerPropButtonAlign,defaultSpoilerPropSize}from"./types";export var cnSpoiler=cn("Spoiler");var spoilerOffsetMap={xs:"xs",s:"s",m:"m",l:"m"},getContent=function(a){var b=a.children,c=a.content,d=a.preview,e=a.lineClamp;return e?["lineClamp",b,b]:b?["blur",b,b]:["toggle",d,c]};export var Spoiler=forwardRef(function(a,b){var c=a.preview,d=a.maxHeight,e=a.content,f=a.size,g=void 0===f?defaultSpoilerPropSize:f,h=a.lessIcon,i=a.lessLabel,j=a.children,k=a.moreIcon,l=a.moreLabel,m=a.className,n=a.lineClamp,o=a.buttonIndent,p=a.buttonAlign,q=void 0===p?defaultSpoilerPropButtonAlign:p,r=a.style,s=_objectWithoutProperties(a,_excluded),t=useFlag(),u=_slicedToArray(t,2),v=u[0],w=u[1],x=getContent(a,v),y=_slicedToArray(x,3),z=y[0],A=y[1],B=y[2],C=useRefs(3),D=useResizeObserved(C,getElementSize),E=D[1].height>D[0].height;return React.createElement("div",Object.assign({},s,{className:cnSpoiler({size:g},[m]),ref:useForkRef([b,C[2]]),style:_objectSpread(_objectSpread(_objectSpread(_objectSpread({},r),"number"==typeof d&&_defineProperty({},"--spoiler-content-max-height","".concat(d,"px"))),"number"==typeof n&&_defineProperty({},"--spoiler-content-line-clamp",n)),"number"==typeof D[2].width&&_defineProperty({},"--spoiler-content-width","".concat(D[2].width,"px")))}),React.createElement(Text,{ref:C[0],className:cnSpoiler("Content",{mode:z,hidden:v||!E}),size:g},A),React.createElement(Text,{ref:C[1],className:cnSpoiler("Content",{hidden:!v&&E}),size:g},B),E&&React.createElement("div",{className:cnSpoiler("ButtonWrapper",{align:q},[cnMixSpace({mT:"undefined"==typeof o?spoilerOffsetMap[g]:o})])},React.createElement(SpoilerButton,{className:cnSpoiler("Button"),lessIcon:h,lessLabel:i,moreIcon:k,moreLabel:l,onClick:w.toggle,open:v,size:g})))});
//# sourceMappingURL=Spoiler.js.map