import _defineProperty from"@babel/runtime/helpers/defineProperty";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["valueAtom","inputMinWidthAtom"],_excluded2=["children","className","inputMinWidthAtom","size","style"],_excluded3=["className","inputRef","inputMaxLength","value","inputValue","inputDefaultValue","renderValue","onFocus","onBlur","autoFocus","inputTabIndex","inputAriaLabel","disabled","size","placeholder","onKeyDown","onKeyDownCapture","onChange","onKeyUp","onKeyUpCapture","onCopy","onCopyCapture","onCut","onCutCapture","onPaste","onPasteCapture","onWheel","disableInput"];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{useAction,useAtom,useUpdate}from"@reatom/npm-react";import React,{forwardRef,useRef}from"react";import{useComponentSize}from"../../../hooks/useComponentSize";import{useForkRef}from"../../../hooks/useForkRef";import{usePropAtom,useSendToAtom,withCtx}from"../../../utils/state";import{useCreateAtom}from"../../../utils/state/useCreateAtom";import{cnFieldArrayValueInlineControl}from"./cnFieldArrayValueInlineControl";var gapMap={l:"calc(var(--space-3xs) + var(--space-2xs))",m:"var(--space-2xs)",s:"var(--space-3xs)",xs:"var(--space-3xs)"},verticalPaddingMap={l:"var(--space-xs)",m:"calc(var(--space-xs) - var(--space-3xs))",s:"var(--space-2xs)",xs:"var(--space-3xs)"},inputHeightMap={l:"var(--space-2xl)",m:"calc(var(--space-2xl) - var(--space-2xs))",s:"var(--space-xl)",xs:"var(--space-l)"},InputFakeElement=forwardRef(function(a,b){var c=a.valueAtom,d=a.inputMinWidthAtom,e=_objectWithoutProperties(a,_excluded),f=useAtom(c),g=_slicedToArray(f,1),h=g[0],i=useRef(null),j=useComponentSize(i),k=j.width;return useUpdate(function(a,b){d(a,b)},[k]),React.createElement("div",Object.assign({},e,{ref:useForkRef([b,i])}),h)}),Root=forwardRef(function(a,b){var c,d=a.children,e=a.className,f=a.inputMinWidthAtom,g=a.size,h=void 0===g?"m":g,i=a.style,j=_objectWithoutProperties(a,_excluded2),k=useAtom(f),l=_slicedToArray(k,1),m=l[0];return React.createElement("div",Object.assign({},j,{className:cnFieldArrayValueInlineControl(null,[e]),ref:b,style:_objectSpread(_objectSpread({},i),{},(c={},_defineProperty(c,"--field-array-value-inline-control-items-gap",gapMap[h]),_defineProperty(c,"--field-array-value-inline-control-input-min-width","".concat(m,"px")),_defineProperty(c,"--field-array-value-inline-control-vertical-padding","".concat(verticalPaddingMap[h])),_defineProperty(c,"--field-array-value-inline-control-input-height","".concat(inputHeightMap[h])),c))}),d)}),FieldArrayValueInlineControlRender=function(a,b){var c=a.className,d=a.inputRef,e=a.inputMaxLength,f=a.value,g=void 0===f?[]:f,h=a.inputValue,i=a.inputDefaultValue,j=void 0===i?"":i,k=a.renderValue,l=a.onFocus,m=a.onBlur,n=a.autoFocus,o=a.inputTabIndex,p=a.inputAriaLabel,q=a.disabled,r=a.size,s=void 0===r?"m":r,t=a.placeholder,u=a.onKeyDown,v=a.onKeyDownCapture,w=a.onChange,x=a.onKeyUp,y=a.onKeyUpCapture,z=a.onCopy,A=a.onCopyCapture,B=a.onCut,C=a.onCutCapture,D=a.onPaste,E=a.onPasteCapture,F=a.onWheel,G=a.disableInput,H=_objectWithoutProperties(a,_excluded3),I=useSendToAtom(a),J=usePropAtom(I,"inputValue"),K=useCreateAtom(h||j||""),L=useCreateAtom(j),M=useCreateAtom(0),N=useRef(null),O=useRef(null),P=useAction(function(a,b){K(a,b.target.value);var c=a.get(I),d=c.onChange;d&&d(b)},[]);return useAtom(function(a){var b=a.spy(J),c=a.get(L);c?L(a,""):(O.current&&(O.current.value=b||""),K(a,b||""))}),React.createElement(Root,Object.assign({},H,{className:cnFieldArrayValueInlineControl(null,[c]),ref:b,size:s,inputMinWidthAtom:M}),k(g||[]),React.createElement("input",{className:cnFieldArrayValueInlineControl("Input",{disabled:G}),onChange:P,ref:useForkRef([O,d]),maxLength:e,onFocus:l,onBlur:m,autoFocus:n,tabIndex:o,"aria-label":p,onKeyDown:u,onKeyDownCapture:v,onKeyUp:x,onKeyUpCapture:y,disabled:q,type:"text",placeholder:g.length?void 0:t,onCopy:z,onCopyCapture:A,onCut:B,onCutCapture:C,onPaste:D,onPasteCapture:E,onWheel:F,defaultValue:j,readOnly:G}),React.createElement(InputFakeElement,{ref:N,className:cnFieldArrayValueInlineControl("HelperInputFakeElement"),valueAtom:K,inputMinWidthAtom:M}))};export var FieldArrayValueInlineControl=withCtx(forwardRef(FieldArrayValueInlineControlRender));
//# sourceMappingURL=FieldArrayValueInlineControl.js.map