import{o as e}from"./chunk.DuxOD-Sk.js";import{r as t}from"./emotion-is-prop-valid.esm.DV_OErv-.js";import{c as n,t as r}from"./emotion-styled.browser.esm.BPUx6WuE.js";import{h as i}from"./protobuf.DyZGXwGk.js";import{a}from"./utils.CuRWPZ_O.js";import{t as o}from"./DynamicIcon.BDXbm0Of.js";import{n as s}from"./useBasicWidgetState.DAZ7WsXN.js";var c=e(t()),l=r(`div`,{target:`e1fiu7py0`})(({containerWidth:e})=>({width:e?`100%`:`auto`,minWidth:`fit-content`})),u=r(`div`,{target:`e1fiu7py1`})(({theme:e})=>({display:`flex`,flexWrap:`nowrap`,gap:e.spacing.threeXS,minWidth:`fit-content`})),d=r(`button`,{target:`e1fiu7py2`})(({theme:e,isSelected:t})=>({display:`inline-flex`,alignItems:`center`,justifyContent:`center`,padding:e.spacing.threeXS,margin:e.spacing.none,backgroundColor:e.colors.transparent,color:t?e.colors.bodyText:e.colors.fadedText60,border:`none`,borderRadius:e.radii.button,cursor:`pointer`,userSelect:`none`,minHeight:`unset`,flex:`0 0 fit-content`,"&:focus":{boxShadow:`none`,outline:`none`},"&:focus-visible":{boxShadow:e.shadows.focusRing},"&:hover:not(:disabled)":{color:e.colors.bodyText},"&:disabled":{color:t?e.colors.fadedText40:e.colors.fadedText10,cursor:`not-allowed`,img:{opacity:.4}}})),f=[`:material/thumb_up:`,`:material/thumb_down:`],p=[`:material/sentiment_sad:`,`:material/sentiment_dissatisfied:`,`:material/sentiment_neutral:`,`:material/sentiment_satisfied:`,`:material/sentiment_very_satisfied:`],m=`:material/star:`,h=`:material/star_filled:`,g=5;function _(e){switch(e){case i.FeedbackType.FACES:return p.map((e,t)=>({icon:e,selectedIcon:e,value:t}));case i.FeedbackType.STARS:return Array.from({length:g},(e,t)=>({icon:m,selectedIcon:h,value:t}));default:return[{icon:f[0],selectedIcon:f[0],value:1},{icon:f[1],selectedIcon:f[1],value:0}]}}function v(e,t){switch(t){case i.FeedbackType.THUMBS:return e===1?`Thumbs up`:`Thumbs down`;case i.FeedbackType.FACES:return[`Very dissatisfied`,`Dissatisfied`,`Neutral`,`Satisfied`,`Very satisfied`][e]??`Rating ${e+1}`;case i.FeedbackType.STARS:return`${e+1} out of ${g} stars`;default:return`Rating ${e+1}`}}function y(e,t,n){return t===null?!1:n===i.FeedbackType.STARS?e<=t:e===t}function b(e,t){let n=e.getStringValue(t);if(n!==void 0)return n===``?null:parseInt(n,10)}function x(e){return e.default??null}function S(e){return e.value??null}function C(e,t,n,r){let i=n.value===null?``:String(n.value);t.setStringValue(e,i,{fromUi:n.fromUi},r)}function w(e){let{disabled:t,element:r,fragmentId:i,widgetMgr:f,widthConfig:p}=e,{type:m}=r,[h,g]=s({getStateFromWidgetMgr:b,getDefaultStateFromProto:x,getCurrStateFromProto:S,updateWidgetMgrState:C,element:r,widgetMgr:f,fragmentId:i,formClearBehavior:`resetValueOnly`}),w=r.value??h,T=a(p),E=(0,c.useMemo)(()=>_(m),[m]),D=(0,c.useRef)([]),O=(0,c.useCallback)(e=>{g({value:w===e?null:e,fromUi:!0})},[w,g]),k=(0,c.useCallback)((e,t)=>{let n;switch(e.key){case`ArrowLeft`:case`ArrowUp`:e.preventDefault(),n=t>0?t-1:E.length-1;break;case`ArrowRight`:case`ArrowDown`:e.preventDefault(),n=t<E.length-1?t+1:0;break;case` `:case`Enter`:e.preventDefault(),O(E[t].value);return;default:return}D.current[n]?.focus()},[E,O]);return n(l,{className:`stFeedback`,"data-testid":`stFeedback`,containerWidth:T,children:n(u,{role:`radiogroup`,"aria-label":`Feedback rating`,children:E.map((e,r)=>{let i=y(e.value,w,m),a=i?e.selectedIcon:e.icon;return n(d,{ref:e=>{D.current[r]=e},type:`button`,role:`radio`,"aria-checked":w===e.value,"aria-label":v(e.value,m),tabIndex:w===e.value||w===null&&r===0?0:-1,disabled:t,isSelected:i,onClick:()=>O(e.value),onKeyDown:e=>k(e,r),"data-testid":i?`stFeedbackButtonActive`:`stFeedbackButton`,children:n(o,{iconValue:a,size:`lg`})},e.value)})})})}var T=(0,c.memo)(w);export{T as default};