1import{reactExports as t,jsxRuntimeExports as e}from"./react-core-chunk-B2r03cU8.js";import{EVENT_CATEGORIES as oe,PRODUCT_AREAS as le,EVENT_ACTIONS as D,TRACK_ACTION_TYPES as A,ELEMENTS as U,postFormData as B,postJSON as ce}from"./app-bundle-B0YfsjKz.js";import{getRolloutEnabled as ae,withUxRoot as ie,useHistory as se,useLocation as ue,useTrackUx as pe,ptoPoliciesTranscribeRoute as de,flashNotice as _e,ptoPoliciesGeneratePolicyTemplateRoute as Y,PTO_POLICY_ROUTES as k,Box_default as l,Button_default as g,CircularInfinite_default as V,Text_default as _,Alert_default as he,TextInput_default as ye,IconButton_default as fe,Icon_default as H,cxHelpers as me}from"./app-init-chunk-kk_CZVyp.js";import{ENTRY_PATHS as I}from"./types-chunk-Bkn_oBV9.js";import{toI18n as n}from"./tracking-chunk-Cdw_Cfie.js";import{useSelector as Ee}from"./redux-core-chunk-DgWMjMkF.js";import{useVoiceRecorder as be}from"./Waveform-chunk-BHFfX-bb.js";import{VoiceRecorder as xe}from"./index-chunk-D2kyqZ3r.js";try{(function(){var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},a=new r.Error().stack;a&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[a]="537d2946-dcb0-4998-a207-a78e4c0894d2",r._sentryDebugIdIdentifier="sentry-dbid-537d2946-dcb0-4998-a207-a78e4c0894d2")})()}catch{}const Ce="pto_llm_policy_template_creation",ge=r=>!!ae(r,Ce),Ie=()=>Ee(ge),Te=({onEndRecording:r})=>{const a=be(),{handleStopRecording:p}=a;return t.useEffect(()=>()=>p(),[p]),e.jsx(xe,{...a,onEndRecording:r,uxElement:"policy_launcher_voice_button"})},{cxEl:v}=me("PolicyLauncherView"),c={IDLE:"idle",GENERATING:"generating",FAILED:"failed"},K=async r=>{const a=r?.body;if(a?.error)return a.error;try{const p=r?.response;return p?.json?(await p.json())?.error??null:null}catch{return null}},Le="Generate a time off policy based on the uploaded reference document.",Re=5e6,je=["application/pdf","text/plain"],De="application/pdf,text/plain,.pdf,.txt",Ae=()=>{const r=se(),a=ue(),p=Ie(),[f,b]=t.useState(""),[h,T]=t.useState(null),[P,S]=t.useState(""),[E,s]=t.useState(c.IDLE),[W,d]=t.useState(""),[N,w]=t.useState(!1),x=t.useRef(null),u=t.useRef(!1),O=t.useRef(null),F=t.useRef(null),m=pe();t.useEffect(()=>{m(D.PAGE_VIEWED,A.VIEW)},[m]),t.useEffect(()=>(u.current=!1,()=>{u.current=!0}),[]),t.useEffect(()=>{E===c.GENERATING&&O.current?.focus(),E===c.FAILED&&F.current?.focus()},[E]);const z=t.useCallback(()=>{b(n("pto_policy.policy_launcher.prefill_paid_time_off")),s(c.IDLE),d("")},[]),M=t.useCallback(()=>{b(n("pto_policy.policy_launcher.prefill_sick_leave")),s(c.IDLE),d("")},[]),Z=t.useCallback(o=>{b(String(o.target.value)),s(c.IDLE),d("")},[]),L=t.useCallback(()=>{m(D.BUTTON_CLICKED,A.CLICK,{element:U.POLICY_LAUNCHER_UPLOAD_TILE}),x.current?.click()},[m]),X=t.useCallback(o=>{const i=o.target.files?.[0];if(o.target.value="",!!i){if(!je.includes(i.type)||i.size>Re){T(null),S(n("pto_policy.policy_launcher.upload_error")),s(c.IDLE),d("");return}S(""),T(i),s(c.IDLE),d("")}},[]),q=t.useCallback(async o=>{w(!0);try{const i=o.audioBlob.type==="audio/mp4"?"mp4":"webm",y=new File([o.audioBlob],`recording.${i}`,{type:o.audioBlob.type}),C=await B(de(),{file:y});if(u.current)return;C.transcript&&(b(re=>[re.trim(),C.transcript].filter(ne=>ne!=="").join(" ")),s(c.IDLE),d(""))}catch(i){const y=await K(i)??n("pto_policy.policy_launcher.transcribe_error");
1if(u.current)return;_e.error(y)}finally{u.current||w(!1)}},[]),J=t.useCallback(()=>{T(null),s(c.IDLE),d(""),x.current&&(x.current.value="")},[]),R=f.trim()!==""||h!==null,$=t.useCallback(()=>{if(!R)return;s(c.GENERATING);const o=h?B(Y(),{policy_description:f.trim()||Le,reference_document_file:h}):ce(Y(),{policy_description:f}),i=h?I.UPLOADED:I.GENERATED;o.then(y=>{u.current||r.push({pathname:k.POLICY_WIZARD_NEW,state:{policyTemplate:y,entryPath:i}})}).catch(y=>{u.current||K(y).then(C=>{u.current||(d(C??""),s(c.FAILED))})})},[R,f,h,r,a.search]),j=t.useCallback(()=>{m(D.BUTTON_CLICKED,A.CLICK,{element:U.POLICY_LAUNCHER_SCRATCH_TILE,entry_path:I.SCRATCH}),r.push({pathname:k.POLICY_WIZARD_NEW,state:{entryPath:I.SCRATCH}})},[m,r]),Q=t.useCallback(o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),j())},[j]),ee=t.useCallback(o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),L())},[L]),te=t.useCallback(()=>{u.current=!0,r.replace(k.POLICY_INDEX)},[r]),G=e.jsx(l,{row:!0,justifyContentEnd:!0,vcenter:!0,p:"sm",bbw:1,bcolor:"subtle",children:e.jsx(g,{type:"button",variant:"tertiary",onClick:te,uxElement:"policy_launcher_cancel_button",children:n("pto_policy.cancel")})});return E===c.GENERATING?e.jsxs(l,{bgcolor:"mono0",w:"100%",minh:"100vh",children:[G,e.jsxs(l,{h:"60vh",column:!0,hcenter:!0,vcenter:!0,gap:"md",children:[e.jsx(V,{variant:"dark",size:"large",alt:n("pto_policy.policy_launcher.generating_title")}),e.jsxs(l,{ref:O,tabIndex:-1,column:!0,hcenter:!0,gap:"md",className:v("focusTarget"),children:[e.jsx(_,{variant:"heading2",component:"h1",children:n("pto_policy.policy_launcher.generating_title")}),e.jsx(_,{color:"secondary",children:n("pto_policy.policy_launcher.generating_subtitle")})]})]})]}):e.jsxs(l,{bgcolor:"mono0",w:"100%",minh:"100vh",children:[G,e.jsx(l,{pt:"xl",ph:"xl",pb:"2xl",children:e.jsxs(l,{column:!0,gap:"lg",maxw:600,mh:"auto",children:[e.jsx(_,{variant:"heading2",component:"h1",children:n("pto_policy.policy_launcher.title")}),E===c.FAILED&&e.jsx(l,{ref:F,tabIndex:-1,className:v("focusTarget"),children:e.jsx(he,{variant:"error",title:n("pto_policy.policy_launcher.failed_message"),children:W})}),p&&e.jsxs(e.Fragment,{children:[e.jsxs(l,{column:!0,gap:"md",children:[e.jsxs(l,{row:!0,gap:"xs",children:[e.jsx(g,{variant:"secondary",size:"small",onClick:z,uxElement:"policy_launcher_category_paid_time_off",children:n("pto_policy.policy_launcher.category_paid_time_off")}),e.jsx(g,{variant:"secondary",size:"small",onClick:M,uxElement:"policy_launcher_category_sick_leave",children:n("pto_policy.policy_launcher.category_sick_leave")})]}),e.jsxs(l,{relative:!0,column:!0,overflow:"hidden",bradiusm:!0,bw:1,bcolor:"subtle",className:v("composer"),children:[e.jsx(ye,{name:"policyDescription",ariaLabel:n("pto_policy.policy_launcher.title"),placeholder:n("pto_policy.policy_launcher.describe_placeholder"),value:f,onChange:Z,textArea:!0,minRows:4,maxRows:8,fullWidth:!0,uxElement:"policy_launcher_policy_description_field"}),e.jsxs(l,{absolute:!0,bottom:0,right:0,p:"xs",row:!0,gap:"xs",vcenter:!0,children:[N?e.jsx(V,{variant:"dark",size:"small"}):e.jsx(Te,{onEndRecording:q}),e.jsx(fe,{icon:"Send",label:n("pto_policy.policy_launcher.send_button_label"),onClick:$,disabled:!R||N,dataTestId:"policy-launcher-generate-button",uxElement:"policy_launcher_generate_button"})]})]})]}),e.jsx("input",{ref:x,type:"file",accept:De,hidden:!0,"data-testid":"policy-launcher-file-input",onChange:X}),h&&e.jsxs(l,{row:!0,vcenter:!0,gap:"sm",children:[e.jsx(_,{children:h.name}),e.jsx(g,{variant:"tertiary",size:"small",onClick:J,uxElement:"policy_launcher_remove_file_button",children:n("pto_policy.policy_launcher.remove_file_button")})]}),P&&e.jsx(_,{color:"destructive",variant:"bodySm",children:P})]}),e.jsxs(l,{row:!0,gap:"md",children:[e.jsxs(l,{column:!0,gap:"xs",w:292,p:"lg",bw:1,bcolor:"subtle",bradiusm:!0,pointer:!0,role:"button",tabIndex:0,onClick:j,onKeyDown:Q,children:[e.jsx(H,{iconName:"Edit"}),e.jsx(_,{variant:"bodyStrong",children:n("pto_policy.policy_launcher.scratch_tile_title")})]}),p&&e.jsxs(l,{column:!0,gap:"xs",w:292,p:"lg",bw:1,bcolor:"subtle",bradiusm:!0,pointer:!0,role:"button",tabIndex:0,"aria-label":n("pto_policy.policy_launcher.upload_tile_title"),"aria-describedby":"policy-launcher-upload-hint",onClick:L,onKeyDown:ee,children:[e.jsx(H,{iconName:"Upload"}),e.jsx(_,{variant:"bodyStrong",children:n("pto_policy.policy_launcher.upload_tile_title")}),e.jsx(_,{variant:"bodySm",color:"secondary",id:"policy-launcher-upload-hint",children:n("pto_policy.policy_launcher.upload_tile_hint")})]})]})]})})]})},Ge=ie({productArea:le.PTO,eventCategory:oe.TIME_OFF_POLICY_LAUNCHER})(Ae);export{Ge as default}; 2//# sourceMappingURL=PolicyLauncherView-chunk-FguCdQj8.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.