1import{r as c,j as t,B as _,T as f,a3 as B,e as I,ab as R,a7 as W,bo as U}from"./MarketingSiteLoadingFallback-DfYAzeIM.js";import{a as T,h as i,I as F,ai as N,ay as E,a3 as O,J as q,a4 as $,a5 as H,F as J,cD as G,cE as K}from"./renderJungleWebApp-DZgne_TB.js";import{I as Y}from"./IconTrashOutline-ChnnBLYT.js";import{F as y,e as C,I as Q,z as A}from"./landingHandoffUploadClaim-B2LBwAI7.js";import{I as D}from"./icon-button-BKnGN1H6.js";import{T as L}from"./textarea-BxfDy4nw.js";import{trackError as V}from"./track-error-DEre5AXz.js";import{s as w}from"./supportApiHttpClient-C7CH2x07.js";import{u as X}from"./use-toast-BZJ66mJi.js";import"./frontend-release-BHg_hj9G.js";import"./hub-D89kKFfg.js";import"./index-rQLcFmgX.js";import"./legacy-referrer-id-43tytWzp.js";import"./main-YoYAMf6n.js";import"./stripe-price-details-DClgIPIw.js";import"./document-upload-sentry-Dl2_Y04U.js";import"./sentry-init-BRm8Bcin.js";import"./client-environment-BMTHOZAb.js";const z=c.memo(({labels:e,selectedLabelId:o,isLoadingInitialSnapshot:r,errorMessage:a,onSelectLabel:p,onCreateLabel:d,onDeleteLabel:m})=>{const{t:l}=T(),x=c.useCallback(s=>p(s),[p]);return t.jsxs(_,{w:"320px",h:"100%",borderRightWidth:"1px",borderColor:i.surface.border,display:"flex",flexDirection:"column",bg:i.surface.white,children:[t.jsxs(y,{align:"center",justify:"space-between",px:3,py:3,borderBottomWidth:"1px",borderColor:i.surface.border,children:[t.jsx(f,{fontSize:"14px",fontWeight:"800",color:i.text.header,children:l("admin_support.labels_labelssidebar.labels_22289854","Labels")}),t.jsx(D,{"aria-label":l("admin_support.labels_labelssidebar.create_label_16823034","Create label"),icon:t.jsx(F,{width:14,height:14}),size:"xs",variant:"ghost",onClick:d})]}),t.jsx(_,{flex:"1",overflowY:"auto",children:r?t.jsx(_,{textAlign:"center",py:6,children:t.jsx(B,{size:"sm",color:i.primaryAction.default})}):a?t.jsx(_,{px:3,py:3,children:t.jsxs(f,{fontSize:"13px",color:i.accentColors.errorStrong,children:[l("admin_support.labels_labelssidebar.failed_to_load_labels_f299b0ba","Failed to load labels:")," ",a]})}):e.length===0?t.jsxs(_,{px:3,py:6,children:[t.jsx(f,{fontSize:"13px",color:i.text.placeholder,mb:3,children:l("admin_support.labels_labelssidebar.no_labels_yet_labels_help_the_bot_classify_and_route_support_conversatio_1938280a","No labels yet. Labels help the bot classify and route support conversations automatically.")}),t.jsx(I,{size:"sm",onClick:d,variant:"outline",children:l("admin_support.labels_labelssidebar.create_your_first_label_ecc6e892","Create your first label")})]}):t.jsx(N,{spacing:1,align:"stretch",px:2,pb:2,pt:2,children:e.map(s=>{var b;const h=o===s.id;return t.jsxs(y,{align:"center",justify:"space-between",px:2,py:2,borderRadius:"8px",cursor:"pointer",bg:h?i.primaryAction.light:"transparent",_hover:{bg:h?i.primaryAction.light:i.surface.hover},onClick:()=>x(s.id),children:[t.jsxs(_,{minW:0,flex:"1",children:[t.jsx(f,{fontSize:"13px",fontWeight:h?"700":"600",noOfLines:1,children:s.title||l("admin.support.labels.untitled","Untitled label")}),t.jsx(f,{fontSize:"12px",color:i.text.placeholder,noOfLines:1,children:(b=s.ai_description)!=null&&b.trim()?s.ai_description:l("admin.support.labels.no_ai_description","No AI description yet")})]}),t.jsx(D,{"aria-label":l("admin_support.labels_labelssidebar.delete_label_93916558","Delete label"),icon:t.jsx(Y,{width:14,height:14}),size:"xs",variant:"ghost",onClick:n=>{n.stopPropagation(),m(s.id)}})]},s.id)})})})]})});z.displayName="LabelsSidebar";const k=c.memo(({selectedLabel:e,onSave:o})=>{const{t:r}=T(),[a,p]=c.useState(""),[d,m]=c.useState(""),[l,x]=c.useState(""),[s,h]=c.useState(!1);c.useEffect(()=>{p((e==null?void 0:e.title)??""),m((e==null?void 0:e.ai_description)??""),x((e==null?void 0:e.ai_action)??"")},[e==null?void 0:e.id,e==null?void 0:e.title,e==null?void 0:e.ai_description,e==null?void 0:e.ai_action]);const b=c.useCallback(async()=>{if(!(!e||s)&&a.trim()){h(!0);try{await o(e.id,{title:a.trim(),ai_description:d,ai_action:l})}finally{h(!1)}}},[e,s,a,d,l,o]);return e?t.jsxs(_,{h:"100%",w:"100%",display:"flex",flexDirection:"column",children:[t.jsxs(y,{align:"center",justify:"space-between",px:4,py:3,borderBottomWidth:"1px",borderColor:i.surface.border,children:[t.jsxs(_,{children:[t.jsx(f,{fontSize:"14px",fontWeight:"800",color:i.text.header,children:r("admin_support.labels_labeleditorpanel.label_74341e3c","Label")}),t.jsx(f,{fontSize:"12px",color:i.text.placeholder,children:r("admin_support.labels_labeleditorpanel.edit_the_title_and_the_ai_prompts_for_this_label_7cf8bf2c","Edit the title and the AI prompts for this label.")})]}),t.jsx(I,{size:"sm",onClick:b,isLoading:s,isDisabled:!a.trim(),bg:i.primaryAction.default,color:"white",_hover:{bg:i.primaryAction.hover},children:r("admin_support.labels_labeleditorpanel.save_efc007a3","Save")})]}),t.jsxs(_,{flex:"1",minH:0,p:4,overflowY:"auto",children:[t.jsxs(C,{isRequired:!0,mb:5,children:[t.jsx(E,{fontSize:"12px",fontWeight:"700",color:i.text.label,children:r("admin_support.labels_labeleditorpanel.title_768e0c1c","Title")}),t.jsx(Q,{value:a,onChange:n=>p(n.target.value),placeholder:r("admin_support.labels_labeleditorpanel.e_g_bug_report_596a8b6a","e.g., Bug report")}),t.jsx(A,{fontSize:"12px",color:i.text.placeholder,children:r("admin_support.labels_labeleditorpanel.shown_as_a_badge_in_the_admin_threads_page_and_in_conversation_transcrip_393f1385","Shown as a badge in the admin Threads page and in conversation transcripts.")})]}),t.jsxs(C,{mb:5,children:[t.jsx(E,{fontSize:"12px",fontWeight:"700",color:i.text.label,children:r("admin_support.labels_labeleditorpanel.ai_description_35dbf33b","AI Description")}),t.jsx(L,{value:d,onChange:n=>m(n.target.value),placeholder:r("admin_support.labels_labeleditorpanel.describe_when_this_label_should_match_a_supp
1ort_request_70437c21","Describe when this label should match a support request"),minH:"120px",fontSize:"13px"}),t.jsx(A,{fontSize:"12px",color:i.text.placeholder,children:r("admin_support.labels_labeleditorpanel.this_description_is_used_to_teach_ai_when_this_label_should_match_a_supp_d12c16ba","This description is used to teach AI when this label should match a support request. Keep your description short and to the point.")})]}),t.jsxs(C,{mb:3,children:[t.jsx(E,{fontSize:"12px",fontWeight:"700",color:i.text.label,children:r("admin_support.labels_labeleditorpanel.ai_action_63b3885a","AI Action")}),t.jsx(L,{value:l,onChange:n=>x(n.target.value),placeholder:r("admin_support.labels_labeleditorpanel.e_g_finalize_the_conversation_with_a_thank_you_message_74fb4592",'e.g., "Finalize the conversation with a thank-you message"'),minH:"120px",fontSize:"13px"}),t.jsx(A,{fontSize:"12px",color:i.text.placeholder,children:r("admin_support.labels_labeleditorpanel.what_should_the_bot_do_whenever_this_label_is_applied_to_a_conversation_872a76fe","What should the bot DO whenever this label is applied to a conversation? This text is injected into the bot's system prompt as a high-priority instruction.")})]})]})]}):t.jsx(y,{h:"100%",w:"100%",align:"center",justify:"center",px:6,children:t.jsxs(_,{maxW:"420px",textAlign:"center",children:[t.jsx(f,{fontSize:"16px",fontWeight:"700",color:i.text.header,mb:2,children:r("admin_support.labels_labeleditorpanel.select_a_label_to_edit_e867fe56","Select a label to edit")}),t.jsx(f,{fontSize:"13px",color:i.text.placeholder,children:r("admin_support.labels_labeleditorpanel.labels_help_the_bot_route_support_requests_automatically_use_the_sidebar_947c792c","Labels help the bot route support requests automatically. Use the sidebar to pick one, or create a new label with the + button.")})]})})});k.displayName="LabelEditorPanel";const v=`${R}/support/labels`;async function Z(){var o;return((o=(await w.get(v)).data)==null?void 0:o.labels)??[]}async function ee(e){var r;return(r=(await w.post(v,e)).data)==null?void 0:r.label}async function te(e,o){var a;return(a=(await w.patch(`${v}/${encodeURIComponent(e)}`,o)).data)==null?void 0:a.label}async function ae(e){await w.delete(`${v}/${encodeURIComponent(e)}`)}function P(e,o){const r=(e.title??"").toLowerCase(),a=(o.title??"").toLowerCase();return r===a?0:r<a?-1:1}function re(){const[e,o]=c.useState([]),[r,a]=c.useState(!0),[p,d]=c.useState(null);return c.useEffect(()=>{if(a(!0),d(null),W){let s=!1;const h=async()=>{try{const n=await Z();if(s)return;n.sort(P),o(n),d(null)}catch(n){if(s)return;d(n instanceof Error?n.message:String(n))}finally{s||a(!1)}};h();const b=window.setInterval(()=>void h(),3e3);return()=>{s=!0,window.clearInterval(b)}}const m=O(q,U),l=$(m,H("status","==","active")),x=J(l,s=>{const h=s.docs.map(b=>({...b.data(),id:b.id}));h.sort(P),o(h),a(!1)},s=>{console.error("[useSupportThreadsLabelsListener] Firestore listener failed:",s),V(s,{scope:"support-threads-labels-listener",fingerprint:["support-firestore-listener-failed","threads-labels"]}),d(s.message),a(!1)});return()=>{x()}},[]),{labels:e,isLoadingInitialSnapshot:r,errorMessage:p}}const se=K((e,o)=>({selectedLabelId:null,isPersistingDraft:!1,lastPersistErrorMessage:null,selectLabel:r=>e({selectedLabelId:r}),createLabelAndSelect:async r=>{e({isPersistingDraft:!0,lastPersistErrorMessage:null});try{const a=await ee(r);return e({selectedLabelId:a.id,isPersistingDraft:!1}),a}catch(a){throw e({isPersistingDraft:!1,lastPersistErrorMessage:a instanceof Error?a.message:String(a)}),a}},saveLabel:async(r,a)=>{e({isPersistingDraft:!0,lastPersistErrorMessage:null});try{const p=await te(r,a);return e({isPersistingDraft:!1}),p}catch(p){throw e({isPersistingDraft:!1,lastPersistErrorMessage:p instanceof Error?p.message:String(p)}),p}},deleteLabel:async r=>{e({isPersistingDraft:!0,lastPersistErrorMessage:null});try{await ae(r);const a=o().selectedLabelId;e({isPersistingDraft:!1,selectedLabelId:a===r?null:a})}catch(a){throw e({isPersistingDraft:!1,lastPersistErrorMessage:a instanceof Error?a.message:String(a)}),a}}})),ie=()=>se(e=>({selectedLabelId:e.selectedLabelId,selectLabel:e.selectLabel,isPersistingDraft:e.isPersistingDraft,lastPersistErrorMessage:e.lastPersistErrorMessage,createLabelAndSelect:e.createLabelAndSelect,saveLabel:e.s
1aveLabel,deleteLabel:e.deleteLabel}),G);function ve(){const{labels:e,isLoadingInitialSnapshot:o,errorMessage:r}=re(),{selectedLabelId:a,selectLabel:p,createLabelAndSelect:d,saveLabel:m,deleteLabel:l,lastPersistErrorMessage:x}=ie(),s=X(),h=c.useMemo(()=>a?e.find(u=>u.id===a)??null:null,[a,e]),b=c.useCallback(async()=>{try{await d({title:"New label",ai_description:"",ai_action:""})}catch(u){s({title:"Couldn't create label",description:u instanceof Error?u.message:String(u),status:"error"})}},[d,s]),n=c.useCallback(async(u,j)=>{try{await m(u,j),s({title:"Label saved",status:"success",duration:1500})}catch(g){s({title:"Couldn't save label",description:g instanceof Error?g.message:String(g),status:"error"})}},[m,s]),M=c.useCallback(async u=>{const j=e.find(S=>S.id===u),g=j?`Delete label "${j.title}"? Conversations already tagged will keep the label snapshot.`:"Delete this label?";if(window.confirm(g))try{await l(u)}catch(S){s({title:"Couldn't delete label",description:S instanceof Error?S.message:String(S),status:"error"})}},[l,e,s]);return t.jsxs(y,{h:"calc(100vh - 64px)",w:"100%",children:[t.jsx(z,{labels:e,selectedLabelId:a,isLoadingInitialSnapshot:o,errorMessage:r,onSelectLabel:u=>p(u),onCreateLabel:b,onDeleteLabel:M}),t.jsxs(_,{flex:"1",minW:0,bg:i.surface.background,children:[x?t.jsx(_,{px:4,py:2,bg:i.accentColors.errorLight,children:t.jsx(f,{fontSize:"12px",color:i.accentColors.errorStrong,children:x})}):null,t.jsx(k,{selectedLabel:h,onSave:n})]})]})}export{ve as default}; 2//# sourceMappingURL=AdminSupportLabelsPage-BUhUP3yP.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.