import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["className","as","fileExtension","withPictogram","loading","fileName","errorText","loadingText","loadingProgress","fileDescription","size","onClick","actions","buttonTitle","buttonIcon","onButtonClick"];import"./Attachment.css";import React from"react";import{Button}from"../Button";import{File}from"../File";import{Text}from"../Text";import{cnMixFlex}from"../../mixs/MixFlex";import{cn}from"../../utils/bem";import{isDefined}from"../../utils/type-guards";import{forwardRefWithAs}from"../../utils/types/PropsWithAsAttributes";import{attachmentPropSizeDefault}from"./types";var cnAttachment=cn("Attachment"),fileSizeMap={xs:"s",s:"s",m:"m"},textSizeMap={xs:"xs",s:"s",m:"s"},descriptionSizeMap={xs:"xs",s:"xs",m:"s"},Attachment=forwardRefWithAs(function(a,b){var c=a.className,d=a.as,e=void 0===d?"div":d,f=a.fileExtension,g=a.withPictogram,h=a.loading,i=a.fileName,j=a.errorText,k=a.loadingText,l=void 0===k?"Loading":k,m=a.loadingProgress,n=a.fileDescription,o=a.size,p=void 0===o?attachmentPropSizeDefault:o,q=a.onClick,r=a.actions,s=void 0===r?[]:r,t=a.buttonTitle,u=a.buttonIcon,v=a.onButtonClick,w=_objectWithoutProperties(a,_excluded),x=[v&&u?{onClick:v,icon:u,title:t}:void 0].concat(_toConsumableArray(s)).filter(isDefined),y=!(!(null!==x&&void 0!==x)||!x.length);return React.createElement(e,Object.assign({},w,{onClick:q,className:cnAttachment({size:p,hoverEffect:!!((null===x||void 0===x?void 0:x.length)||q),cursor:q?"pointer":void 0,withActions:y,error:!!j},[cnMixFlex({flex:"flex",gap:"xs"}),c]),ref:b}),g&&React.createElement(File,{className:cnAttachment("File"),extension:f,loading:h,loadingWithProgressSpin:!0,loadingProgress:m,size:fileSizeMap[p]}),React.createElement("div",{className:cnAttachment("Content",[cnMixFlex({flex:"flex",direction:"column",gap:"2xs"})])},i&&React.createElement(Text,{className:cnAttachment("FileName"),size:textSizeMap[p],view:"primary",lineHeight:"xs"},i),n&&!h&&React.createElement(Text,{className:cnAttachment("FileDescription"),size:descriptionSizeMap[p],lineHeight:"xs",view:"ghost"},n),l&&h&&React.createElement(Text,{className:cnAttachment("LoadingText"),size:descriptionSizeMap[p],lineHeight:"xs",view:"ghost"},m?"".concat(l," ").concat(m,"%"):"".concat(l,"...")),j&&React.createElement(Text,{className:cnAttachment("ErrorText"),size:descriptionSizeMap[p],lineHeight:"xs",view:"alert"},j)),y&&React.createElement("div",{className:cnAttachment("Actions",[cnMixFlex({flex:"flex",gap:"xs"})])},x.map(function(a,b){return React.createElement(Button,{key:a.title||b,className:cnAttachment("Button"),tabIndex:-1,onlyIcon:!0,iconLeft:a.icon,onClick:a.onClick,title:a.title,ref:a.ref,size:"xs",view:"clear"})})))});export{Attachment,cnAttachment};
//# sourceMappingURL=Attachment.js.map