import _defineProperty from"@babel/runtime/helpers/defineProperty";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["className","children","label","size","labelIcon","caption","required","status","side","counter","labelPosition","labelIconRef","as","labelHtmlFor"];import React from"react";import{Text}from"../../Text";import{cnMixFlex}from"../../../mixs/MixFlex";import{isString}from"../../../utils/type-guards";import{forwardRefWithAs}from"../../../utils/types/PropsWithAsAttributes";import{FieldCaption}from"../FieldCaption";import{FieldLabel}from"../FieldLabel";import{cnFieldWrapper}from"./cnFieldWrapper";import{directionMap,spaceMap}from"./helpers";var renderCounter=function(a){return React.createElement(Text,{className:cnFieldWrapper("Counter"),view:"ghost",size:"xs",lineHeight:"m"},Array.isArray(a)?a.join("/"):a)},renderSide=function(a){return isString(a)?React.createElement("span",{className:cnFieldWrapper("SideText")},a):a};export var FieldWrapper=forwardRefWithAs(function(a,b){var c,d=a.className,e=a.children,f=a.label,g=a.size,h=void 0===g?"m":g,i=a.labelIcon,j=a.caption,k=a.required,l=a.status,m=a.side,n=a.counter,o=a.labelPosition,p=void 0===o?"top":o,q=a.labelIconRef,r=a.as,s=void 0===r?"div":r,t=a.labelHtmlFor,u=_objectWithoutProperties(a,_excluded),v=spaceMap[h];return React.createElement(s,Object.assign({},u,{ref:b,className:cnFieldWrapper(null,[cnMixFlex({direction:directionMap[p],gap:"top"===p?v:"s"}),d])}),f&&React.createElement(FieldLabel,Object.assign({size:h,required:k,icon:i,iconRef:q},t?{htmlFor:t,as:"label"}:{}),f),React.createElement("div",{className:cnFieldWrapper("ControlAndCaptionWrapper",[cnMixFlex({gap:v,direction:"column"})])},React.createElement("div",{className:cnFieldWrapper("ControlWrapper",[cnMixFlex({gap:v,direction:"row"})])},React.createElement("div",{className:cnFieldWrapper("Control")},e),m&&React.createElement("div",{className:cnFieldWrapper("Side",[cnMixFlex({align:"center",justify:"center"})]),style:(c={},_defineProperty(c,"--field-wrapper-side-text-size","var(--control-text-size-".concat(h,")")),_defineProperty(c,"--field-wrapper-side-height","var(--control-height-".concat(h,")")),c)},renderSide(m))),(j||n)&&React.createElement("div",{className:cnMixFlex({direction:"row",gap:v,justify:"space-between"})},j&&React.createElement(FieldCaption,{className:cnFieldWrapper("Caption"),status:l},j),n&&renderCounter(n))))});
//# sourceMappingURL=FieldWrapper.js.map