import _defineProperty from"@babel/runtime/helpers/defineProperty";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["accept","maxSize","minSize","multiple","onDropFiles","children","locale","disabled","onClick"];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"./DragNDropField.css";import React,{forwardRef,useRef}from"react";import{useDropzone}from"react-dropzone";import{usePropsHandler}from"../EventInterceptor/usePropsHandler";import{Text}from"../Text/Text";import{useForkRef}from"../../hooks/useForkRef/useForkRef";import{useMutableRef}from"../../hooks/useMutableRef/useMutableRef";import{cn}from"../../utils/bem";import{isRenderProp}from"../../utils/isRenderProp";import{DragNDropFieldContent}from"./DragNDropFieldContent/DragNDropFieldContent";import{DragNDropFieldTooltip}from"./DragNDropFieldTooltip/DragNDropFieldTooltip";import{getErrorsList}from"./getErrorsList";import{withdefaultLocale}from"./locale";var cnDragNDropField=cn("DragNDropField");export var COMPONENT_NAME="DragNDropField";export var DragNDropField=forwardRef(function(a,b){var c=useRef(null),d=usePropsHandler(COMPONENT_NAME,a,c),e=d.accept,f=d.maxSize,g=d.minSize,h=d.multiple,i=void 0!==h&&h,j=d.onDropFiles,k=d.children,l=void 0===k?DragNDropFieldContent:k,m=d.locale,n=d.disabled,o=d.onClick,p=_objectWithoutProperties(d,_excluded),q=useMutableRef(o),r=withdefaultLocale(m),s=React.useCallback(function(a){return 0<a.length&&j(a)},[j]),t=useDropzone({accept:null!==e&&void 0!==e&&e.length?e:void 0,maxSize:f||void 0,minSize:g||void 0,onDrop:s,multiple:i,disabled:n}),u=t.fileRejections,v=t.getRootProps,w=t.getInputProps,x=t.isDragActive,y=t.rootRef,z=t.open,A=React.useCallback(function(a){var b;a.target!==y.current&&a.stopPropagation(),null===(b=q.current)||void 0===b?void 0:b.call(q,a)},[]),B=v(_objectSpread(_objectSpread({},p),{},{className:cnDragNDropField({active:x,disabled:n},[p.className]),onClick:A})),C=isRenderProp(l)?l({accept:e,maxSize:f,minSize:g,multiple:i,openFileDialog:z,locale:r,disabled:n}):l,D=React.useMemo(function(){return getErrorsList(u,{maxSize:f,minSize:g},r)},[u]);return React.createElement(React.Fragment,null,React.createElement("div",Object.assign({},B,{ref:useForkRef([b,y,c])}),React.createElement("input",w()),x?React.createElement(Text,{view:"secondary",size:"s",align:"center",lineHeight:"m"},"\u041F\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u044B \u0441\u044E\u0434\u0430"):C),React.createElement(DragNDropFieldTooltip,{anchorRef:y,errors:D}))});export*from"./types";
//# sourceMappingURL=DragNDropField.js.map