import{f as k,r as l,ab as _,j as d,$ as A,ac as c}from"./index.RuhrnD1v.js";import{u as R}from"./useBasicWidgetState.CI9LlGGe.js";import"./FormClearHelper.DFo50Lfo.js";const x=k("div",{target:"e1xqjt520"})(({containerWidth:e})=>({width:e?"100%":"auto",minWidth:"fit-content"})),I=k("div",{target:"e1xqjt521"})(({theme:e})=>({display:"flex",flexWrap:"nowrap",gap:e.spacing.threeXS,minWidth:"fit-content"})),D=k("button",{target:"e1xqjt522"})(({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:"],B=[":material/sentiment_sad:",":material/sentiment_dissatisfied:",":material/sentiment_neutral:",":material/sentiment_satisfied:",":material/sentiment_very_satisfied:"],M=":material/star:",N=":material/star_filled:",F=5;function O(e){switch(e){case c.FeedbackType.FACES:return B.map((t,a)=>({icon:t,selectedIcon:t,value:a}));case c.FeedbackType.STARS:return Array.from({length:F},(t,a)=>({icon:M,selectedIcon:N,value:a}));default:return[{icon:f[0],selectedIcon:f[0],value:1},{icon:f[1],selectedIcon:f[1],value:0}]}}function U(e,t){switch(t){case c.FeedbackType.THUMBS:return e===1?"Thumbs up":"Thumbs down";case c.FeedbackType.FACES:return["Very dissatisfied","Dissatisfied","Neutral","Satisfied","Very satisfied"][e]??`Rating ${e+1}`;case c.FeedbackType.STARS:return`${e+1} out of ${F} stars`;default:return`Rating ${e+1}`}}function W(e,t,a){return t===null?!1:a===c.FeedbackType.STARS?e<=t:e===t}function j(e,t){const a=e.getStringValue(t);if(a!==void 0)return a===""?null:parseInt(a,10)}function E(e){return e.default??null}function L(e){return e.value??null}function $(e,t,a,b){const g=a.value===null?"":String(a.value);t.setStringValue(e,g,{fromUi:a.fromUi},b)}function V(e){const{disabled:t,element:a,fragmentId:b,widgetMgr:g,widthConfig:h}=e,{type:u}=a,[v,p]=R({getStateFromWidgetMgr:j,getDefaultStateFromProto:E,getCurrStateFromProto:L,updateWidgetMgrState:$,element:a,widgetMgr:g,fragmentId:b,formClearBehavior:"resetValueOnly"}),o=a.value??v,w=_(h),i=l.useMemo(()=>O(u),[u]),y=l.useRef([]),m=l.useCallback(n=>{p({value:o===n?null:n,fromUi:!0})},[o,p]),T=l.useCallback((n,r)=>{let s;switch(n.key){case"ArrowLeft":case"ArrowUp":n.preventDefault(),s=r>0?r-1:i.length-1;break;case"ArrowRight":case"ArrowDown":n.preventDefault(),s=r<i.length-1?r+1:0;break;case" ":case"Enter":n.preventDefault(),m(i[r].value);return;default:return}y.current[s]?.focus()},[i,m]);return d(x,{className:"stFeedback","data-testid":"stFeedback",containerWidth:w,children:d(I,{role:"radiogroup","aria-label":"Feedback rating",children:i.map((n,r)=>{const s=W(n.value,o,u),C=s?n.selectedIcon:n.icon;return d(D,{ref:S=>{y.current[r]=S},type:"button",role:"radio","aria-checked":o===n.value,"aria-label":U(n.value,u),tabIndex:o===n.value||o===null&&r===0?0:-1,disabled:t,isSelected:s,onClick:()=>m(n.value),onKeyDown:S=>T(S,r),"data-testid":s?"stFeedbackButtonActive":"stFeedbackButton",children:d(A,{iconValue:C,size:"lg"})},n.value)})})})}const P=l.memo(V);export{P as default};
