import{r as s,E as W,_ as $,n as d,aj as L,a0 as V,j as a,am as D,b9 as K}from"./index.BSITpAz8.js";import{I as N}from"./InputInstructions.CWlmC2Qh.js";import{i as _}from"./inputUtils.CQWz5UKz.js";import{T as j}from"./textarea.DvzSPS_8.js";import"./base-input.C7heAUz7.js";var w=s.forwardRef(function(t,r){var l={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return s.createElement(W,$({iconAttrs:l,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:r}),s.createElement("rect",{width:24,height:24,fill:"none"}),s.createElement("path",{d:"M3 5.51v3.71c0 .46.31.86.76.97L11 12l-7.24 1.81c-.45.11-.76.51-.76.97v3.71c0 .72.73 1.2 1.39.92l15.42-6.49c.82-.34.82-1.5 0-1.84L4.39 4.58C3.73 4.31 3 4.79 3 5.51z"}))});w.displayName="Send";const q=d("div",{target:"e1qzcwc60"})(({theme:t,width:r})=>({borderRadius:t.radii.xxxl,display:"flex",backgroundColor:t.colors.widgetBackgroundColor??t.colors.secondaryBg,width:`${r}px`})),A=d("div",{target:"e1qzcwc61"})(({theme:t})=>({backgroundColor:t.colors.transparent,position:"relative",flexGrow:1,borderRadius:t.radii.xxxl,display:"flex",alignItems:"center"})),M=d("button",{target:"e1qzcwc62"})(({theme:t,disabled:r,extended:l})=>{const u=L(t),[o,g]=u?[t.colors.gray60,t.colors.gray80]:[t.colors.gray80,t.colors.gray40];return{border:"none",backgroundColor:t.colors.transparent,borderTopRightRadius:l?"0":t.radii.xxxl,borderTopLeftRadius:l?t.radii.default:"0",borderBottomRightRadius:t.radii.xxxl,display:"inline-flex",alignItems:"center",justifyContent:"center",lineHeight:t.lineHeights.none,margin:t.spacing.none,padding:t.spacing.sm,color:r?o:g,pointerEvents:"auto","&:focus":{outline:"none"},":focus":{outline:"none"},"&:focus-visible":{backgroundColor:u?t.colors.gray10:t.colors.gray90},"&:hover":{color:t.colors.primary},"&:disabled, &:disabled:hover, &:disabled:active":{backgroundColor:t.colors.transparent,borderColor:t.colors.transparent,color:t.colors.gray}}}),F=d("div",{target:"e1qzcwc63"})({display:"flex",alignItems:"flex-end",height:"100%",position:"absolute",right:0,pointerEvents:"none"}),G=d("div",{target:"e1qzcwc64"})(({theme:t})=>({position:"absolute",bottom:"0px",right:`calc(${t.iconSizes.xl} + 2 * ${t.spacing.sm} + ${t.spacing.sm})`})),U=6.5,H=1;function Z({width:t,element:r,widgetMgr:l,fragmentId:u}){const o=V(),[g,h]=s.useState(!1),[p,f]=s.useState(r.default),[x,y]=s.useState(0),i=s.useRef(null),b=s.useRef({minHeight:0,maxHeight:0}),R=()=>{let e=0;const{current:n}=i;if(n){const c=n.placeholder;n.placeholder="",n.style.height="auto",e=n.scrollHeight,n.placeholder=c,n.style.height=""}return e},C=()=>{i.current&&i.current.focus(),p&&(l.setStringTriggerValue(r,p,{fromUi:!0},u),h(!1),f(""),y(0))},E=e=>{const{metaKey:n,ctrlKey:c,shiftKey:T}=e;_(e)&&!T&&!c&&!n&&(e.preventDefault(),C())},z=e=>{const{value:n}=e.target,{maxChars:c}=r;c!==0&&n.length>c||(h(n!==""),f(n),y(R()))};s.useEffect(()=>{if(r.setValue){r.setValue=!1;const e=r.value||"";f(e),h(e!=="")}},[r]),s.useEffect(()=>{if(i.current){const{offsetHeight:e}=i.current;b.current.minHeight=e,b.current.maxHeight=e*U}},[i]);const{disabled:m,placeholder:I,maxChars:k}=r,{minHeight:B,maxHeight:S}=b.current,v=x>0&&i.current?Math.abs(x-B)>H:!1;return a(q,{className:"stChatInput","data-testid":"stChatInput",width:t,children:D(A,{children:[a(j,{inputRef:i,value:p,placeholder:I,onChange:z,onKeyDown:E,"aria-label":I,disabled:m,rows:1,overrides:{Root:{style:{minHeight:o.sizes.minElementHeight,outline:"none",backgroundColor:o.colors.transparent,borderRadius:o.radii.xxxl,borderLeftWidth:o.sizes.borderWidth,borderRightWidth:o.sizes.borderWidth,borderTopWidth:o.sizes.borderWidth,borderBottomWidth:o.sizes.borderWidth,width:`${t}px`}},InputContainer:{style:{backgroundColor:o.colors.transparent}},Input:{props:{"data-testid":"stChatInputTextArea"},style:{lineHeight:o.lineHeights.inputWidget,backgroundColor:o.colors.transparent,resize:"none","::placeholder":{opacity:"0.7"},height:v?`${x+H}px`:"auto",maxHeight:S?`${S}px`:"none",paddingLeft:o.spacing.lg,paddingBottom:o.spacing.sm,paddingTop:o.spacing.sm,paddingRight:`calc(${o.iconSizes.xl} + 2 * ${o.spacing.sm} + ${o.spacing.sm})`}}}}),t>o.breakpoints.hideWidgetDetails&&a(G,{children:a(N,{dirty:g,value:p,maxLength:k,type:"chat",inForm:!1})}),a(F,{children:a(M,{onClick:C,disabled:!g||m,extended:v,"data-testid":"stChatInputSubmitButton",children:a(K,{content:w,size:"xl",color:"inherit"})})})]})})}export{Z as default};
