1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="9376b37c-1bdd-4cdb-9f49-8ef7fefcccfa",e._sentryDebugIdIdentifier="sentry-dbid-9376b37c-1bdd-4cdb-9f49-8ef7fefcccfa")}catch(e){}}(),(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8531],{7291:(e,t,s)=>{"use strict";s.d(t,{G:()=>l,p:()=>n});var a=s(66352),r=s(40522);s(95132);var i=s(42319);function l(e){let{children:t}=e;return(0,a.jsx)("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-[#f5f8fd] [&_svg]:h-8 [&_svg]:w-8 [&_svg]:text-[#7e51e2]",children:t})}function n(e){let{icon:t,title:s,description:l,buttonText:n,onButtonClick:o,buttonVariant:c="primary"}=e,{t:d}=(0,i.Bd)("common");return(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-center p-8",children:[(0,a.jsx)("div",{className:"mb-4",children:t}),(0,a.jsx)("h2",{className:"mb-2 text-2xl font-semibold text-gray-900 dark:text-gray-100",children:d(s)}),(0,a.jsx)("p",{className:"mt-2 max-w-md text-sm leading-relaxed text-gray-500",children:d(l)}),n&&o&&(0,a.jsx)(r.$,{onClick:o,variant:c,className:"mt-6",children:d(n)})]})}},27221:(e,t,s)=>{"use strict";s.d(t,{S:()=>n});var a=s(66352);s(95132);var r=s(17703),i=s(20414),l=s(18109);function n(e){let{className:t,...s}=e;return(0,a.jsx)(r.bL,{"data-slot":"checkbox",className:(0,l.cn)("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] cursor-pointer disabled:cursor-not-allowed disabled:opacity-50",t),...s,children:(0,a.jsx)(r.C1,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:(0,a.jsx)(i.A,{className:"size-3.5"})})})}},29358:(e,t,s)=>{"use strict";s.d(t,{h:()=>p});var a=s(66352),r=s(95132),i=s(32790),l=s.n(i),n=s(6734),o=s(38740),c=s(94230),d=s(40522),m=s(42152),u=s(87629),x=s(55372);function p(e){var t,s;let{data:r,status:i}=(0,n.useSession)(),l=null==r||null==(t=r.user)?void 0:t.id;return"authenticated"===i&&l?(0,a.jsx)(h,{...e},"".concat(l,":").concat(e.workspaceId,":").concat(e.effectiveUserId,":").concat(null!=(s=e.userId)?s:"self")):null}function h(e){let{t}=(0,u.o)(),s=x.id.useUtils(),i=(0,r.useMemo)(()=>({workspaceId:e.workspaceId,...e.userId?{userId:e.userId}:{}}),[e.workspaceId,e.userId]),n=x.id.sellerCopilot.getMeetingReviewAccess.useQuery(i,{retry:!1,staleTime:0,placeholderData:void 0,refetchOnMount:"always",refetchInterval:6e4});(0,r.useEffect)(()=>()=>{s.sellerCopilot.getMeetingReviewAccess.cancel(i)},[s,i]);let p=t=>e.pageContainer?(0,a.jsx)(m.L,{outerClassName:"min-h-0 pb-0 lg:pb-0",children:t}):t,h=!!n.data&&(n.data.workspaceId!==e.workspaceId||n.data.sellerUserId!==e.effectiveUserId);return n.isError||h?p((0,a.jsxs)("div",{role:"alert",className:"space-y-3 rounded-xl border p-4",children:[(0,a.jsx)("p",{className:"text-base",children:t("sellerMeetingReviews.error")}),(0,a.jsx)(d.$,{variant:"outline",className:"min-h-11 text-base",onClick:()=>void n.refetch(),children:t("sellerMeetingReviews.retry")})]})):n.isFetchedAfterMount&&!n.isFetching&&n.data&&"disabled"!==n.data.status&&"no_line"!==n.data.status?p((0,a.jsxs)("section",{"data-sentry-block":!0,"aria-label":t("sellerMeetingReviews.entryTitle"),className:"sentry-block min-w-0 space-y-4 rounded-2xl border border-violet-200 bg-card p-5 dark:border-violet-900",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(o.A,{"aria-hidden":"true",className:"mt-1 size-5 shrink-0 text-violet-700 dark:text-violet-300"}),(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("h2",{className:"text-base font-semibold",children:t("sellerMeetingReviews.entryTitle")}),(0,a.jsx)("p",{className:"text-base leading-6 text-muted-foreground",children:t("sellerMeetingReviews.entryHint")})]})]}),(0,a.jsx)(d.$,{asChild:!0,variant:"outline",className:"h-auto min-h-11 w-full cursor-pointer whitespace-normal text-base sm:w-auto",children:(0,a.jsxs)(l(),{href:"/pipeline/meeting-reviews",children:[t("sellerMeetingReviews.entryOpen"),(0,a.jsx)(c.A,{"aria-hidden":"true"})]})})]})):null}},41118:(e,t,s)=>{"use strict";s.d(t,{E:()=>l});var a=s(66352);s(95132);var r=s(13353),i=s(7291);function l(e){let{onRetry:t}=e;return(0,a.jsx)("div",{"data-testid":"query-error-state",children:(0,a.jsx)(i.p,{icon:(0,a.jsx)(r.A,{className:"h-12 w-12 text-gray-300"}),title:"common.load_error_title",description:"common.load_error_description",buttonText:"common.load_error_retry",onButtonClick:t,buttonVariant:"outline"})})}},42152:(e,t,s)=>{"use strict";s.d(t,{L:()=>l});var a=s(66352),r=s(60326),i=s(18109);function l(e){let{children:t,header:s,className:l,outerClassName:n,headerClassName:o}=e;return(0,a.jsx)("div",{className:(0,i.cn)(r.dx,"min-h-screen bg-background p-4 lg:p-6",n),children:(0,a.jsxs)("div",{className:(0,i.cn)("w-full max-w-screen-2xl mx-auto",l),children:[s&&(0,a.jsx)("div",{className:o,children:s}),t]})})}},61097:(e,t,s)=>{"use strict";s.d(t,{g:()=>i,l:()=>r});var a=s(95132);function r(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:300;return i(e,t).value}function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:300,s=!1===e?null:e,r=(0,a.useRef)(null!=s?s:null),i=(0,a.useRef)(0),l=(0,a.useRef)(null!=s),[,n]=(0,a.useReducer)(e=>e+1,0);null!=s&&(l.current||(i.current+=1),r.current=s),l.current=null!=s;let o=null==s;return(0,a.useEffect)(()=>
1{if(!o||null==r.current)return;let e=setTimeout(()=>{r.current=null,n()},t);return()=>clearTimeout(e)},[o,t]),{value:null!=s?s:r.current,generation:i.current}}},70015:(e,t,s)=>{"use strict";s.d(t,{A:()=>i});var a=s(66352),r=s(18109);function i(e){let{title:t,description:s,className:i,titleClassName:l,descriptionClassName:n}=e;return(0,a.jsxs)("div",{className:i,children:[(0,a.jsx)("h1",{className:(0,r.cn)("text-2xl sm:text-3xl font-bold",l),children:t}),s&&(0,a.jsx)("p",{className:(0,r.cn)("text-muted-foreground text-sm sm:text-base mt-1",n),children:s})]})}},75318:(e,t,s)=>{"use strict";s.d(t,{A:()=>r});var a=s(66352);function r(e){let{message:t}=e;return(0,a.jsx)("div",{role:"status","aria-live":"polite",className:"sr-only",children:t})}s(95132)},77956:(e,t,s)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/pipeline/commercial",function(){return s(94168)}])},90876:(e,t,s)=>{"use strict";s.d(t,{F:()=>h});var a=s(66352),r=s(95132),i=s(32790),l=s.n(i),n=s(96099),o=s(94230),c=s(40522),d=s(93795),m=s(41118),u=s(42152),x=s(87629),p=s(55372);function h(e){var t;return(0,a.jsx)(g,{...e},"".concat(e.workspaceId,":").concat(e.effectiveUserId,":").concat(null!=(t=e.userId)?t:"self"))}function g(e){let{t}=(0,x.o)(),s=t=>e.pageContainer?(0,a.jsx)(u.L,{outerClassName:"min-h-0 pb-0 lg:pb-0",children:t}):t,i=p.id.useUtils(),h=(0,r.useMemo)(()=>({workspaceId:e.workspaceId,...e.userId?{userId:e.userId}:{}}),[e.workspaceId,e.userId]),g=p.id.sellerCopilot.getCommitmentAccess.useQuery(h,{retry:!1,staleTime:0,placeholderData:void 0,refetchOnMount:"always",refetchInterval:6e4}),f=!!g.data&&(g.data.workspaceId!==e.workspaceId||g.data.sellerUserId!==e.effectiveUserId),b=g.isError||f||!g.isFetchedAfterMount?void 0:g.data,v=null==b?void 0:b.accessToken,j=(null==b?void 0:b.status)==="ready"&&b.consentEnabled&&!!v&&!g.isFetching,N=(0,r.useMemo)(()=>({...h,view:"today",limit:3,...v?{accessToken:v}:{}}),[h,v]),w=p.id.sellerCopilot.getCommitments.useQuery(N,{enabled:j,retry:!1,staleTime:0,placeholderData:void 0,refetchOnMount:"always"});if((0,r.useEffect)(()=>()=>{i.sellerCopilot.getCommitmentAccess.cancel(h)},[h,i]),(0,r.useEffect)(()=>()=>{N.accessToken&&i.sellerCopilot.getCommitments.cancel(N)},[N,i]),g.isError||f)return s((0,a.jsx)(m.E,{onRetry:()=>g.refetch()}));if(!b||("disabled"===b.status||"no_line"===b.status)&&!b.consentEnabled)return null;let y="disabled"===b.status||"no_line"===b.status,k=!!w.data&&(w.data.workspaceId!==e.workspaceId||w.data.sellerUserId!==e.effectiveUserId),I=j&&!w.isPending&&!w.isFetching&&w.isFetchedAfterMount,C=I&&!!w.data&&w.data.accessToken!==v;return s((0,a.jsxs)("section",{className:"min-w-0 space-y-4 rounded-2xl border border-violet-200 bg-card p-5 dark:border-violet-900","aria-label":t("sellerCommitments.title"),children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(n.A,{className:"mt-1 size-5 shrink-0 text-violet-700 dark:text-violet-300","aria-hidden":"true"}),(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("h2",{className:"text-base font-semibold",children:t(y?"sellerCommitments.entryPermission":"sellerCommitments.entryTitle")}),(0,a.jsx)("p",{className:"text-base leading-6 text-muted-foreground",children:t(y?"sellerCommitments.permissionHint":"sellerCommitments.entryHint")})]})]}),"ready"===b.status&&(w.isError||k||C?(0,a.jsx)(m.E,{onRetry:()=>w.refetch()}):I&&w.data?0===w.data.items.length?(0,a.jsx)("p",{className:"text-base text-muted-foreground",children:t("sellerCommitments.entryEmpty")}):(0,a.jsx)("ul",{className:"space-y-3",children:w.data.items.map(e=>(0,a.jsxs)("li",{className:"space-y-1 rounded-xl bg-muted/30 p-3",children:[(0,a.jsx)("p",{className:"break-words text-base font-medium",children:e.title}),(0,a.jsxs)("p",{className:"break-words text-sm text-muted-foreground",children:[e.contactName||t("sellerCommitments.contactUnknown")," \xb7"," ",t("seller"===e.owner?"sellerCommitments.ownerSeller":"sellerCommitments.ownerClient")]})]},e.id))}):(0,a.jsx)("div",{"aria-label":t("sellerCommitments.loading"),children:(0,a.jsx)(d.E,{className:"h-24 rounded-xl"})})),(0,a.jsx)(c.$,{asChild:!0,variant:"outline",className:"min-h-11 w-full cursor-pointer whitespace-normal text-base sm:w-auto",children:(0,a.jsxs)(l(),{href:"/pipeline/commitments",children:[t(y?"sellerCommitments.entryPermission":j?"sellerCommitments.entryOpen":"sellerCommitments.entryEnable"),
1(0,a.jsx)(o.A,{"aria-hidden":"true"})]})})]}))}},94168:(e,t,s)=>{"use strict";s.r(t),s.d(t,{__N_SSP:()=>eN,default:()=>ew});var a=s(66352),r=s(95132),i=s(6734),l=s(32509),n=s(93795),o=s(42152),c=s(70015),d=s(41118),m=s(21442),u=s(1841),x=s(4627),p=s(83041),h=s(97161),g=s(52703),f=s(20414),b=s(32988),v=s(78676),j=s(87629),N=s(40522),w=s(57645),y=s(27221),k=s(55372),I=s(15078);function C(e){let{vertical:t}=e,s="real_estate"===t?u.A:"construction"===t?x.A:"saas"===t?p.A:h.A;return(0,a.jsx)(s,{className:"size-5","aria-hidden":"true"})}function A(e){var t,s;let{workspaceId:i,userId:l}=e,{t:o}=(0,j.o)(),c=k.id.useUtils(),m={workspaceId:i,...l?{userId:l}:{}},u=k.id.sellerCopilot.getCommercialSetup.useQuery(m,{retry:!1}),[x,p]=(0,r.useState)("create"),[h,A]=(0,r.useState)("real_estate"),[S,U]=(0,r.useState)(""),[E,_]=(0,r.useState)(1),[z,D]=(0,r.useState)(!1),L=k.id.sellerCopilot.activateCommercial.useMutation({onSuccess:async()=>{await Promise.all([c.sellerCopilot.invalidate(),c.pipeline.invalidate()])}});if(u.isError)return(0,a.jsx)(d.E,{onRetry:()=>u.refetch()});if(u.isPending)return(0,a.jsx)(n.E,{className:"h-72 rounded-2xl"});if(!u.data.enabled||u.data.activePipeline)return null;let T="create"===x?null==(t=u.data.templates.find(e=>e.vertical===h))?void 0:t.steps:null==(s=u.data.candidates.find(e=>e.id===S))?void 0:s.steps,R=null==T?void 0:T.filter(e=>{var t,s;return!(null==(t=e.flags)?void 0:t.countsAsWon)&&!(null==(s=e.flags)?void 0:s.countsAsLost)}),F=null==T?void 0:T.filter(e=>{var t,s;return(null==(t=e.flags)?void 0:t.countsAsWon)||(null==(s=e.flags)?void 0:s.countsAsLost)});return(0,a.jsxs)("section",{className:"mx-auto max-w-4xl overflow-hidden rounded-2xl border bg-background","aria-labelledby":"commercial-setup-title",children:[(0,a.jsx)("header",{className:"border-b px-5 py-6 sm:px-8 sm:py-8",children:(0,a.jsxs)("div",{className:"flex items-start gap-4",children:[(0,a.jsx)("span",{className:"flex size-10 shrink-0 items-center justify-center rounded-full bg-muted text-foreground",children:(0,a.jsx)(g.A,{className:"size-5","aria-hidden":"true"})}),(0,a.jsxs)("div",{className:"max-w-2xl",children:[(0,a.jsx)("p",{className:"mb-2 text-xs font-semibold uppercase tracking-[0.16em] text-primary-80",children:o("commercial.setupStep",{step:E})}),(0,a.jsx)("h2",{id:"commercial-setup-title",className:"font-poppins text-2xl font-semibold tracking-tight text-foreground",children:o("commercial.setupTitle")}),(0,a.jsx)("p",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:o("commercial.setupDescription")})]})]})}),(0,a.jsxs)("div",{className:"space-y-7 px-5 py-6 sm:px-8 sm:py-8",children:[1===E?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("fieldset",{className:"overflow-hidden rounded-xl border",children:[(0,a.jsx)("legend",{className:"sr-only",children:o("commercial.setupDescription")}),(0,a.jsx)("div",{className:"grid sm:grid-cols-2 sm:divide-x",children:["create","existing"].map(e=>(0,a.jsxs)("label",{className:"flex min-h-16 cursor-pointer items-center justify-between gap-3 border-b p-4 transition-colors last:border-b-0 sm:border-b-0 ".concat(x===e?"bg-primary-80/5 text-foreground":"text-muted-foreground hover:bg-muted/40"),children:[(0,a.jsx)("span",{className:"text-sm font-semibold",children:o("commercial.".concat(e))}),(0,a.jsx)("input",{type:"radio",name:"commercial-mode",value:e,checked:x===e,onChange:()=>{p(e),L.reset()},className:"size-4 shrink-0 accent-violet-600"})]},e))})]}),"create"===x?(0,a.jsxs)("fieldset",{className:"space-y-3",children:[(0,a.jsx)("legend",{className:"text-sm font-semibold text-foreground",children:o("commercial.vertical")}),(0,a.jsx)("div",{className:"grid overflow-hidden rounded-xl border sm:grid-cols-2",children:u.data.templates.map((e,t)=>{let s=e.vertical===h;return(0,a.jsxs)("label",{className:"relative flex min-h-24 cursor-pointer items-start gap-3 p-4 transition-colors focus-within:ring-2 focus-within:ring-primary-80/40 focus-within:ring-inset ".concat(t===u.data.templates.length-1?"border-b-0":"border-b"," ").concat(t<u.data.templates.length-2?"sm:border-b":"sm:border-b-0"," ").concat(t%2==0?"sm:border-r":""," ").concat(s?"bg-primary-80/5":"hover:bg-muted/40"),children:[(0,a.jsx)("input",{type:"radio",name:"commercial-vertical",value:e.vertical,checked:s,onChange:()=>{A(e.vertical),L.reset()},className:"sr-only"}),(0,a.jsx)("span",{className:"mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-full ".concat(s?"bg-primary-80 text-white":"bg-muted text-muted-foreground"),children:(0,a.jsx)(C,{vertical:e.vertical})}),(0,a.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,a.jsx)("span",{className:"block text-sm font-semibold text-foreground",children:o("commercial.verticals.".concat(e.vertical))}),(0,a.jsx)("span",{className:"mt-1 block text-xs leading-5 text-muted-foreground",children:o("commercial.setupDesign.verticals.".concat(e.vertical))})]}),s?(0,a.jsx)(f.A,{className:"mt-1 size-4 shrink-0 text-primary-80","aria-hidden":"true"}):null]},e.vertical)})})]}):(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:o("commercial.existingHint")}),u.data.candidates.length?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(w.J,{htmlFor:"commercial-existing",children:o("commercial.chooseExisting")}),(0,a.jsxs)("select",{id:"commercial-existing",value:S,onChange:e=>U(e.target.value),className:"min-h-11 w-full cursor-pointer rounded-xl border bg-background px-3 text-base",children:[(0,a.jsx)("option",{value:"",children:o("commercial.chooseExisting")}),u.data.candidates.map(e=>(0,a.jsx)("option",{value:e.id,children:e.name},e.id))]})]}):(0,a.jsx)("p",{className:"rounded-xl bg-muted p-4 text-sm",children:o("commercial.none
1Existing")})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"grid gap-6 sm:grid-cols-[minmax(0,1fr)_minmax(16rem,1.2fr)] sm:gap-10",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:o("commercial.setupDesign.journeyEyebrow")}),(0,a.jsx)("h3",{className:"mt-2 font-poppins text-xl font-semibold text-foreground",children:o("commercial.preview")}),(0,a.jsx)("p",{className:"mt-3 text-sm leading-6 text-muted-foreground",children:o("commercial.setupDesign.journeyHint")})]}),(0,a.jsxs)("div",{className:"space-y-5",children:[(0,a.jsx)("ol",{"aria-label":o("commercial.preview"),children:null==R?void 0:R.map((e,t)=>{var s;return(0,a.jsxs)("li",{className:"grid grid-cols-[2rem_minmax(0,1fr)] gap-3",children:[(0,a.jsxs)("div",{className:"flex flex-col items-center",children:[(0,a.jsx)("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-full border bg-background text-xs font-semibold text-foreground",children:t+1}),t<(null!=(s=null==R?void 0:R.length)?s:0)-1?(0,a.jsx)("span",{className:"flex min-h-8 flex-1 items-center justify-center","aria-hidden":"true",children:(0,a.jsx)(b.A,{className:"size-3 text-border"})}):null]}),(0,a.jsx)("div",{className:"min-w-0 pb-6 pt-1.5 text-sm font-medium text-foreground",children:(0,I.jl)(o,e,!1)})]},e.stepId)})}),(null==F?void 0:F.length)?(0,a.jsxs)("div",{className:"space-y-3 border-t pt-4",children:[(0,a.jsx)("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:o("commercial.setupDesign.possibleOutcomes")}),(0,a.jsx)("ul",{"aria-label":o("commercial.setupDesign.possibleOutcomes"),className:"grid gap-2 sm:grid-cols-2",children:F.map(e=>(0,a.jsx)("li",{className:"rounded-lg border bg-muted/20 px-3 py-2.5 text-sm font-medium text-foreground",children:(0,I.jl)(o,e,!1)},e.stepId))})]}):null]})]}),(0,a.jsxs)("div",{className:"flex items-start gap-3 border-y py-4 text-sm",children:[(0,a.jsx)(v.A,{className:"mt-0.5 size-5 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("p",{children:o("commercial.setupRules")}),(0,a.jsx)("p",{className:"text-muted-foreground",children:o("commercial.noHistory")}),(0,a.jsx)("p",{className:"text-muted-foreground",children:o("commercial.privacy")})]})]}),"existing"===x?(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(y.S,{id:"commercial-convert-ack",checked:z,onCheckedChange:e=>D(!0===e),className:"mt-1 cursor-pointer"}),(0,a.jsx)(w.J,{htmlFor:"commercial-convert-ack",className:"cursor-pointer text-sm leading-6",children:o("commercial.existingAck")})]}):null]}),L.isError?(0,a.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:o("commercial.error")}):null,(0,a.jsxs)("div",{className:"flex flex-wrap justify-end gap-3",children:[2===E?(0,a.jsx)(N.$,{variant:"outline",className:"min-h-11 cursor-pointer",disabled:L.isPending,onClick:()=>_(1),children:o("commercial.back")}):null,(0,a.jsx)(N.$,{variant:"primary",className:"min-h-11 cursor-pointer",loading:L.isPending,disabled:!(null==T?void 0:T.length)||2===E&&"existing"===x&&!z,onClick:()=>{1===E?_(2):L.mutate("create"===x?{...m,mode:x,vertical:h}:{...m,mode:x,pipelineId:S,explicitConversionAck:!0})},children:o(1===E?"commercial.next":"commercial.activate")})]})]})]})}var S=s(54888),U=s(8974),E=s(2341),_=s(45572),z=s(37084),D=s(47959),L=s(76580),T=s(92558),R=s(32790),F=s.n(R),M=s(94230),P=s(10890),H=s(21867);function $(e){let{workspaceId:t,userId:s,data:i}=e,{t:l}=(0,j.o)(),n=k.id.useUtils(),[o,c]=(0,r.useState)(!1),[d,m]=(0,r.useState)(!1),u={workspaceId:t,...s?{userId:s}:{}},x=()=>n.sellerCopilot.invalidate(),p=k.id.sellerCopilot.setCommercialConsent.useMutation({onSuccess:async()=>{c(!1),m(!1),await x()},onError:()=>H.oR.error(l("commercial.error"))}),h=k.id.sellerCopilot.refreshCommercialSuggestions.useMutation({onSuccess:async e=>{H.oR.success(l("commercial.analyzed",e)),await x()},onError:()=>H.oR.error(l("commercial.error"))}),g=i.hasPersonalLine&&i.consent.enabled;return(0,a.jsxs)("aside",{className:"min-w-0 space-y-5","aria-label":l("commercial.workspaceUI.assistant"),children:[(0,a.jsxs)("section",{className:"overflow-hidden rounded-2xl border bg-card",children:[(0,a.jsxs)("div",{className:"space-y-4 p-5",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:l("commercial.workspaceUI.manualMode")}),(0,a.jsx)("h2",{className:"text-base font-semibold tracking-[-0.02em]",children:l("commercial.workspaceUI.assistant")})]}),(0,a.jsx)(E.A,{className:"mt-1 size-5 shrink-0 text-violet-700 dark:text-violet-300","aria-hidden":"true"})]}),(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:l(g?"commercial.workspaceUI.assistantHint":i.hasPersonalLine?"commercial.workspaceUI.permissionHint":"commercial.workspaceUI.noLineHint")}),g?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N.$,{className:"min-h-11 w-full whitespace-normal rounded-lg bg-violet-700 px-3 text-white hover:bg-violet-800",loading:h.isPending,disabled:p.isPending,onClick:()=>h.mutate(u),children:l("commercial.workspaceUI.findSuggestions")}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:l("commercial.workspaceUI.analysisScope")})]}):i.hasPersonalLine?(0,a.jsx)(N.$,{variant:"outline",className:"min-h-11 w-full whitespace-normal rounded-lg",onClick:()=>m(!0),"aria-expanded":d,"aria-controls":"commercial-permissions",children:l("commercial.workspaceUI.authorize")}):(0,a.jsx)(N.$,{variant:"outline",className:"min-h-11 w-full whitespace-normal rounded-lg",asChild:!0,children:(0,a.jsxs)(F(),{href:"/settings/connections",children:[l("commercial.workspaceUI.connect"),(0,a.jsx)(M.A,{className:"size-4","aria-hidden":"true"})]})})]}),(0,a.jsxs)("div",{className:"border-t bg-muted/15 px-5 py-1",children:[(0,a.jsxs)("button",{type:"button",className:"flex min-h-11 w-full cursor-pointer items-center justify-between gap-2 text-left text-xs font-medium text-muted-foreground focus-visible:outline-2 focus-visible:outline-violet-600",onClick:()=>m(e=>!e),"aria-expanded":d,"aria-controls":"commercial-permissions",children:[(0,a.jsxs)("span",{className:"flex items-center gap-2",children:[(0,a.jsx)(v.A,{className:"size-3.5","aria-hidden":"true"}),l("commercial.workspaceUI.privacySettings")]}),(0,a.jsx)(P.A,{className:"size-4 transition-transform motion-reduce:transition-none ".concat(d?"rotate-180":""),"aria-hidden":"true"})]}),d?(0,a.jsxs)("div",{id:"commercial-permissions",className:"space-y-4 pb-4 pt-2",children:[(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:l("commercial.privacy")}),i.consent.enabled?(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("p",{className:"text-xs font-semibold text-foreground",children:l("commercial.consentActive")}
1),(0,a.jsx)("p",{className:"text-xs leading-6 text-muted-foreground",children:l("commercial.consentDescription")}),(0,a.jsx)(N.$,{variant:"outline",className:"min-h-11 w-full whitespace-normal rounded-lg",loading:p.isPending,onClick:()=>p.mutate({...u,enabled:!1}),children:l("commercial.consentRevoke")})]}):i.hasPersonalLine?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(y.S,{id:"commercial-consent",checked:o,onCheckedChange:e=>c(!0===e),className:"mt-1 cursor-pointer"}),(0,a.jsx)(w.J,{htmlFor:"commercial-consent",className:"cursor-pointer text-xs leading-6 text-muted-foreground",children:l("commercial.consentDescription")})]}),(0,a.jsx)(N.$,{className:"min-h-11 w-full whitespace-normal rounded-lg bg-violet-700 text-white hover:bg-violet-800",disabled:!o,loading:p.isPending,onClick:()=>p.mutate({...u,enabled:!0}),children:l("commercial.consentEnable")})]}):(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:l("commercial.consentNoLine")})]}):null]})]}),(0,a.jsxs)("div",{className:"hidden gap-3 px-1 xl:flex",children:[(0,a.jsx)(v.A,{className:"mt-0.5 size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("h3",{className:"text-xs font-medium",children:l("commercial.workspaceUI.notAutomatic")}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:l("commercial.workspaceUI.notAutomaticHint")})]})]})]})}var O=s(66170),q=s(19146);function Q(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();return e.suggestions.filter(e=>"pending"===e.status&&(!e.snoozedUntil||new Date(e.snoozedUntil).getTime()<=t))}function W(e){let{opportunity:t,asOf:s}=e,{t:r}=(0,j.o)(),i=Q(t,s)[0];return i?(0,a.jsxs)("div",{className:"space-y-1 text-violet-800 dark:text-violet-300",children:[(0,a.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em]",children:r("commercial.suggestion")}),(0,a.jsxs)("p",{className:"flex items-start gap-1.5 text-sm font-medium leading-5",children:[(0,a.jsx)(_.A,{className:"mt-0.5 size-3.5 shrink-0","aria-hidden":"true"}),(0,a.jsx)("span",{className:"min-w-0 break-words",children:(0,I.jl)(r,i.targetStep,!1)})]})]}):(0,a.jsxs)("p",{className:"flex items-start gap-1.5 text-xs leading-5 text-muted-foreground",children:[(0,a.jsx)(O.A,{className:"mt-1 size-3 shrink-0","aria-hidden":"true"}),(0,a.jsx)("span",{children:r("observed"===t.activity.reply?"commercial.reply":"observed"===t.activity.contactAttempt?"commercial.attempt":"commercial.handoff")})]})}function B(e){let{opportunity:t,onSelect:s,layout:r="card",asOf:i=Date.now()}=e,{t:l,currentLanguage:n}=(0,j.o)(),o=t.contactName||l("commercial.unknownContact"),c=Q(t,i).length>0,d=new Date(t.handoffAt),m=Number.isFinite(d.getTime())?d.toLocaleDateString(n,{day:"numeric",month:"short"}):void 0,u="row"===r;return(0,a.jsxs)("button",{type:"button",onClick:()=>s(t),"aria-label":l("commercial.details",{name:o}),"aria-describedby":"commercial-stage-".concat(t.leadId," commercial-signal-").concat(t.leadId),className:"group w-full min-w-0 cursor-pointer text-left transition-colors focus-visible:relative focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-violet-600 ".concat(u?"grid grid-cols-[minmax(0,1fr)_20px] items-center gap-x-4 gap-y-3 border-b px-4 py-5 last:border-b-0 hover:bg-muted/40 sm:px-5 lg:grid-cols-[minmax(0,1.15fr)_minmax(110px,0.7fr)_minmax(0,1fr)_20px]":"space-y-4 rounded-xl border bg-card p-4 hover:border-violet-400"," ").concat(c&&u?"bg-violet-50/40 dark:bg-violet-950/15":""),children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-xs font-semibold ".concat(c?"bg-violet-100 text-violet-800 dark:bg-violet-900/50 dark:text-violet-200":"bg-muted text-muted-foreground"),children:t.contactName.trim().split(/\s+/).filter(Boolean).slice(0,2).map(e=>Array.from(e)[0]).join("").toLocaleUpperCase()||"?"}),(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("p",{className:"break-words text-sm font-semibold tracking-[-0.01em] text-foreground",children:o}),m?(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:l("commercial.workspaceUI.handoffDate",{date:m})}):null]})]}),(0,a.jsx)("div",{id:"commercial-stage-".concat(t.leadId),className:u?"col-start-1 row-start-2 lg:col-start-auto lg:row-start-auto":"",children:(0,a.jsxs)("span",{className:"inline-flex max-w-full items-center gap-2 rounded-md border border-border/70 bg-background/80 px-2 py-1 text-xs leading-5 text-foreground",children:[(0,a.jsx)("span",{className:"size-1.5 shrink-0 rounded-full bg-muted-foreground
1/50","aria-hidden":"true"}),(0,a.jsx)("span",{className:"min-w-0 break-words",children:t.currentStep?(0,I.jl)(l,t.currentStep,!1):l("commercial.handoff")})]})}),(0,a.jsx)("div",{id:"commercial-signal-".concat(t.leadId),className:u?"col-span-2 row-start-3 min-w-0 lg:col-span-1 lg:row-start-auto":"",children:(0,a.jsx)(W,{opportunity:t,asOf:i})}),u?(0,a.jsx)(q.A,{className:"col-start-2 row-start-1 size-4 text-muted-foreground transition-transform group-hover:translate-x-0.5 motion-reduce:transition-none lg:col-start-auto lg:row-start-auto","aria-hidden":"true"}):null]})}function V(e){var t;let{data:s,mode:r,onSelect:i,asOf:l=Date.now()}=e,{t:n}=(0,j.o)();return s.opportunities.length?"list"===r?(0,a.jsxs)("div",{className:"overflow-hidden rounded-xl border bg-card",children:[(0,a.jsxs)("div",{className:"hidden grid-cols-[minmax(0,1.15fr)_minmax(110px,0.7fr)_minmax(0,1fr)_20px] gap-4 border-b bg-muted/25 px-5 py-3 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground lg:grid","aria-hidden":"true",children:[(0,a.jsx)("span",{children:n("commercial.workspaceUI.contact")}),(0,a.jsx)("span",{children:n("commercial.workspaceUI.confirmed")}),(0,a.jsx)("span",{children:n("commercial.workspaceUI.signal")}),(0,a.jsx)("span",{})]}),s.opportunities.map(e=>(0,a.jsx)(B,{opportunity:e,onSelect:i,layout:"row",asOf:l},e.leadId))]}):(0,a.jsxs)("div",{className:"min-w-0 space-y-3",children:[(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:n("commercial.workspaceUI.boardHint")}),(0,a.jsx)("div",{role:"region","aria-label":n("commercial.board"),tabIndex:0,className:"max-w-full overflow-x-auto rounded-xl pb-3 focus-visible:outline-2 focus-visible:outline-violet-600",children:(0,a.jsx)("div",{className:"grid grid-flow-col auto-cols-[260px] items-start gap-4",children:null==(t=s.pipeline)?void 0:t.steps.map(e=>{let t=s.opportunities.filter(t=>{var s;return(null==(s=t.currentStep)?void 0:s.stepId)===e.stepId});return(0,a.jsxs)("section",{className:"min-w-0 space-y-3 rounded-xl bg-muted/35 p-3","aria-label":(0,I.jl)(n,e,!1),children:[(0,a.jsxs)("div",{className:"flex min-h-10 items-center justify-between gap-2 px-1",children:[(0,a.jsx)("h3",{className:"min-w-0 break-words text-xs font-semibold",children:(0,I.jl)(n,e,!1)}),(0,a.jsx)("span",{className:"text-xs tabular-nums text-muted-foreground",children:t.length})]}),t.length?t.map(e=>(0,a.jsx)(B,{opportunity:e,onSelect:i,asOf:l},e.leadId)):(0,a.jsx)("p",{className:"px-1 pb-4 text-xs leading-5 text-muted-foreground",children:n("commercial.workspaceUI.emptyStage")})]},e.stepId)})})})]}):(0,a.jsx)("div",{className:"rounded-xl border border-dashed px-6 py-12 text-center text-sm leading-6 text-muted-foreground",children:n("commercial.noOpportunities")})}function J(e){let{data:t}=e,{t:s}=(0,j.o)();return(0,a.jsxs)("section",{className:"max-w-4xl space-y-6 rounded-xl border bg-card p-5 sm:p-7","aria-label":s("commercial.teamTitle"),children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[(0,a.jsx)("h2",{className:"text-base font-semibold tracking-tight",children:s("commercial.teamTitle")}),(0,a.jsx)("span",{className:"rounded-lg bg-muted/60 px-3 py-2 text-sm font-medium tabular-nums",children:s("commercial.total",{count:t.total})})]}),(0,a.jsx)("p",{className:"max-w-2xl text-sm leading-6 text-muted-foreground",children:s("commercial.teamHint")}),(0,a.jsx)("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:s("commercial.workspaceUI.currentDistribution")}),(0,a.jsx)("dl",{className:"space-y-5",children:t.steps.map(e=>(0,a.jsxs)("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-2 sm:grid-cols-[minmax(100px,190px)_minmax(0,1fr)_32px]",children:[(0,a.jsx)("dt",{className:"break-words text-sm text-foreground",children:(0,I.jl)(s,e,!1)}),(0,a.jsxs)("dd",{className:"flex items-center gap-4 sm:col-span-2",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"hidden h-2 flex-1 overflow-hidden rounded-full bg-muted sm:block",children:(0,a.jsx)("span",{className:"block h-full rounded-full bg-violet-600 dar
1k:bg-violet-400",style:{width:"".concat(t.total>0?Math.min(100,e.count/t.total*100):0,"%")}})}),(0,a.jsx)("span",{className:"w-8 text-right text-base font-semibold tabular-nums",children:e.count})]})]},e.stepId))}),0===t.total?(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:s("commercial.workspaceUI.teamZero")}):null]})}function Z(e){var t,s,r,i;let{workspaceId:l,userId:o}=e,{t:c}=(0,j.o)(),m=k.id.sellerCopilot.getCommercialTeamOverview.useQuery({workspaceId:l,...o?{userId:o}:{}},{retry:!1,staleTime:3e4,refetchInterval:6e4});return["FORBIDDEN","UNAUTHORIZED"].includes(null!=(i=null==(s=m.error)||null==(t=s.data)?void 0:t.code)?i:"")?null:m.isError&&!m.data?(0,a.jsx)(d.E,{onRetry:()=>m.refetch()}):m.isPending?(0,a.jsx)(n.E,{className:"h-44 rounded-2xl"}):(null==(r=m.data)?void 0:r.enabled)&&m.data.pipelineId?(0,a.jsxs)("div",{className:"space-y-2",children:[m.isError?(0,a.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:c("commercial.refreshError")}):null,(0,a.jsx)(J,{data:m.data})]}):null}function X(e){let{workspaceId:t,userId:s,data:i,canViewTeam:l,canConfigure:n,asOf:o=Date.now(),isRefreshing:c,refreshError:d,onRefresh:m,onEdit:u,onSelect:x}=e,{t:p}=(0,j.o)(),[h,g]=(0,r.useState)("mine"),[f,b]=(0,r.useState)("list"),[v,w]=(0,r.useState)("all"),[y,k]=(0,r.useState)(""),[I,C]=(0,r.useState)(!1),A=(0,r.useMemo)(()=>(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();return[...e].sort((e,s)=>Number(Q(s,t).length>0)-Number(Q(e,t).length>0))})(i.opportunities,o),[i.opportunities,o]),R=A.filter(e=>Q(e,o).length>0),F=A.filter(e=>("all"===v||Q(e,o).length>0)&&function(e,t){let s=e=>e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLocaleLowerCase();return s(e).includes(s(t.trim()))}(e.contactName,y)),M=l&&"team"===h;return(0,a.jsxs)("div",{className:"min-w-0 space-y-5 sm:space-y-7",children:[(0,a.jsxs)("header",{className:"flex flex-wrap items-start justify-between gap-3 border-b pb-4 sm:gap-5 sm:pb-6",children:[(0,a.jsxs)("div",{className:"max-w-2xl space-y-2.5",children:[(0,a.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-violet-800 dark:text-violet-300",children:p("commercial.workspaceUI.eyebrow")}),(0,a.jsx)("h1",{className:"text-2xl font-semibold leading-[1.16] tracking-[-0.045em] text-foreground sm:text-[34px]",children:p(M?"commercial.workspaceUI.teamHeading":"commercial.workspaceUI.heading")}),(0,a.jsx)("p",{className:"max-w-xl text-sm leading-6 text-muted-foreground",children:p(M?"commercial.workspaceUI.teamDescription":"commercial.workspaceUI.description")})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(N.$,{variant:"ghost",className:"min-h-11 rounded-lg text-muted-foreground",loading:c,onClick:m,"aria-label":p("commercial.workspaceUI.reload"),title:p("commercial.workspaceUI.reload"),children:(0,a.jsx)(S.A,{className:"size-4","aria-hidden":"true"})}),n?(0,a.jsxs)(N.$,{variant:"outline",className:"min-h-11 rounded-lg",onClick:u,children:[(0,a.jsx)(U.A,{className:"size-4","aria-hidden":"true"}),p("commercial.manager")]}):null]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 ".concat(l?"":"xl:hidden"),children:[l?(0,a.jsx)("div",{role:"group","aria-label":p("commercial.title"),className:"flex w-fit gap-1 rounded-lg bg-muted/50 p-1",children:["mine","team"].map(e=>(0,a.jsx)("button",{type:"button","aria-pressed":(M?"team":"mine")===e,onClick:()=>g(e),className:"min-h-11 cursor-pointer rounded-md px-3 text-xs font-medium focus-visible:outline-2 focus-visible:outline-violet-600 sm:px-4 sm:text-sm ".concat((M?"team":"mine")===e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:p("mine"===e?"commercial.workspaceUI.personal":"commercial.workspaceUI.team")},e))}):null,M?null:(0,a.jsxs)("button",{type:"button","aria-expanded":I,"aria-controls":"commercial-assistant-panel",onClick:()=>C(e=>!e),className:"flex min-h-11 cursor-pointer items-center gap-1.5 rounded-lg px-2 text-xs font-medium text-violet-800 focus-visible:outline-2 focus-visible:outline-violet-600 dar
1k:text-violet-300 xl:hidden",children:[(0,a.jsx)(E.A,{className:"size-4","aria-hidden":"true"}),p("commercial.workspaceUI.assistantToggle")]})]}),d?(0,a.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:p("commercial.refreshError")}):null,M?(0,a.jsx)(Z,{workspaceId:t,userId:s}):(0,a.jsxs)("div",{className:"grid min-w-0 items-start gap-6 xl:grid-cols-[minmax(0,1fr)_288px] xl:grid-rows-[auto_1fr]",children:[(0,a.jsxs)("section",{className:"flex flex-wrap items-center justify-between gap-2 rounded-xl border-l-[3px] px-4 py-3 sm:gap-5 sm:px-6 sm:py-5 xl:col-start-1 xl:row-start-1 ".concat(R.length?"border-l-violet-600 bg-violet-50/70 dark:bg-violet-950/25":"border-l-border bg-muted/30"),"aria-label":p("commercial.workspaceUI.pending"),children:[(0,a.jsxs)("div",{className:"max-w-lg space-y-2",children:[R.length?(0,a.jsx)("span",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-violet-800 dark:text-violet-300",children:p("commercial.workspaceUI.pendingCount",{count:R.length})}):null,(0,a.jsx)("h2",{className:"hidden text-lg font-semibold leading-7 tracking-[-0.025em] sm:block",children:p(R.length?"commercial.workspaceUI.pendingHeading":"commercial.workspaceUI.clearHeading")}),(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:p(R.length?"commercial.workspaceUI.pendingHint":"commercial.workspaceUI.clearHint")}),i.hasMore?(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:p("commercial.workspaceUI.loadedOnly")}):null]}),R[0]?(0,a.jsxs)(N.$,{variant:"ghost",className:"min-h-11 whitespace-normal rounded-lg px-0 text-left text-violet-800 hover:bg-violet-100 dark:text-violet-300 dark:hover:bg-violet-900/40",onClick:()=>x(R[0]),children:[p("commercial.workspaceUI.reviewNext"),(0,a.jsx)(_.A,{className:"size-4","aria-hidden":"true"})]}):null]}),(0,a.jsx)("div",{id:"commercial-assistant-panel",className:"min-w-0 xl:col-start-2 xl:row-start-1 xl:row-span-2 xl:block ".concat(I?"block":"hidden"),children:(0,a.jsx)($,{workspaceId:t,userId:s,data:i})}),(0,a.jsxs)("div",{className:"min-w-0 space-y-4 xl:col-start-1 xl:row-start-2",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,a.jsxs)("h2",{className:"text-base font-semibold tracking-[-0.02em]",children:[p("commercial.workspaceUI.queue")," ",(0,a.jsx)("span",{className:"ml-2 text-sm font-normal tabular-nums text-muted-foreground",children:i.total})]}),(0,a.jsx)("div",{role:"group","aria-label":p("commercial.workspaceUI.viewMode"),className:"flex gap-1 rounded-lg border p-1",children:[{value:"list",icon:z.A},{value:"board",icon:D.A}].map(e=>{let{value:t,icon:s}=e;return(0,a.jsx)("button",{type:"button",title:p("commercial.".concat(t)),"aria-label":p("commercial.".concat(t)),"aria-pressed":f===t,onClick:()=>b(t),className:"flex min-h-11 min-w-11 cursor-pointer items-center justify-center rounded-md px-2.5 focus-visible:outline-2 focus-visible:outline-violet-600 ".concat(f===t?"bg-muted text-foreground":"text-muted-foreground hover:bg-muted/50"),children:(0,a.jsx)(s,{className:"size-4","aria-hidden":"true"})},t)})})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,a.jsx)("div",{role:"group","aria-label":p("commercial.workspaceUI.queue"),className:"flex gap-1",children:["all","pending"].map(e=>(0,a.jsxs)("button",{type:"button","aria-pressed":v===e,onClick:()=>w(e),className:"min-h-11 cursor-pointer rounded-lg px-3 text-xs font-medium focus-visible:outline-2 focus-visible:outline-violet-600 ".concat(v===e?"bg-foreground text-background":"text-muted-foreground hover:bg-muted"),children:[p("commercial.workspaceUI.".concat(e)),"pending"===e?(0,a.jsx)("span",{className:"ml-2 tabular-nums opacity-70",children:R.length}):null]},e))}),(0,a.jsxs)("div",{className:"flex min-h-11 w-full items-center gap-2 rounded-lg border bg-card px-3 sm:w-60",children:[(0,a.jsx)(L.A,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,a.jsx)("input",{"aria-label":p("commercial.workspaceUI.search"),placeholder:p("commercial.workspaceUI.search"),value:y,onChange:e=>k(e.target.value),className:"min-w-0 flex-1 bg-transparent py-2 text-base outline-none placeholder:text-muted-foreground focus-visible:outline-2 focus-visible:outline-violet-600 sm:text-sm"}),y?(0,a.jsx)("button",{type:"button",className:"flex min-h-11 min-w-8 cursor-pointer items-center justify-center text-muted-foreground focus-visible:outline-2 focus-visible:outline-violet-600",onClick:()=>k(""),"aria-label":p("commercial.workspaceUI.clearSearch"),children:(0,a.jsx)(T.A,{className:"size-3.5","aria-hidden":"true"})}):null]})]}),!F.length&&i.opportunities.length>0?(0,a.jsxs)("div",{className:"rounded-xl border px-5 py-10 text-center",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:p("commercial.workspaceUI.noMatches")}),(0,a.jsx)(N.$,{variant:"ghost",className:"mt-3 min-h-11",onClick:()=>{w("all"),k("")},children:p("commercial.workspaceUI.resetFilters")})]}):(0,a.jsx)(V,{data:{...i,opportunities:F},mode:f,asOf:o,onSelect:x}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:p(i.hasMore?"commercial.resultLimit":"commercial.noHistory")})]})]})]})}var G=s(63643),K=s(35764);function Y(e){var t,s,r;let l=(0,i.useSession)();return"authenticated"===l.status&&(null==(s=l.data)||null==(t=s.user)?void 0:t.id)?(0,a.jsx)(ee,{...e},"".concat(l.data.user.id,":").concat(e.workspaceId,":").concat(e.effectiveUserId,":").concat(null!=(r=e.userId)?r:"self")):null}function ee(e){let{workspaceId:t,effectiveUserId:s,userId:i}=e,[l,o]=(0,r.useState)(0),c=k.id.sellerCopilot.getPersonalPortfolio.useQuery({workspaceId:t,...i?{userId:i}:{},cursor:l},{retry:!1,staleTime:0,placeholderData:void 0,refetchOnMount:"always",refetchInterval:6e4,refetchIntervalInBackgroun
1d:!1}),m=c.data&&(c.data.workspaceId!==t||c.data.sellerUserId!==s);return c.isError||m?(0,a.jsx)(d.E,{onRetry:()=>c.refetch()}):c.isPending||!c.isFetchedAfterMount||c.isFetching||!c.data?(0,a.jsx)(n.E,{className:"mb-8 h-60 rounded-2xl"}):(0,a.jsx)(et,{data:c.data,cursor:l,onCursorChange:o,onRefresh:()=>void c.refetch()})}function et(e){let{data:t,cursor:s,onCursorChange:r,onRefresh:i}=e,{t:l,currentLanguage:n}=(0,j.o)(),o=e=>"commercial.personalPortfolio.".concat(e),c=e=>e&&Number.isFinite(new Date(e).getTime())?new Intl.DateTimeFormat("en"===n?"en":"es",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(e)):l(o("unknownDate"));if("disabled"===t.status||"no_line"===t.status)return null;if("consent_required"===t.status)return(0,a.jsx)("p",{role:"status",className:"mb-8 rounded-xl border p-5 text-sm leading-6 text-muted-foreground",children:l(o("consentRequired"))});let d=[{name:"total",count:t.total},{name:"pending",count:t.counts.reply_pending},{name:"followUp",count:t.counts.follow_up}];return(0,a.jsxs)("section",{"data-sentry-block":!0,className:"sentry-block mb-10 min-w-0 space-y-5","aria-label":l(o("eyebrow")),children:[(0,a.jsxs)("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0 max-w-3xl space-y-2",children:[(0,a.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-violet-700 dark:text-violet-300",children:l(o("eyebrow"))}),(0,a.jsx)("h2",{className:"text-2xl font-semibold tracking-tight sm:text-3xl",children:l(o("heading"))}),(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:l(o("description"))})]}),(0,a.jsxs)(N.$,{variant:"outline",onClick:i,className:"min-h-11 shrink-0 cursor-pointer whitespace-normal",children:[(0,a.jsx)(S.A,{className:"size-4 shrink-0","aria-hidden":"true"}),l(o("refresh"))]})]}),(0,a.jsx)("div",{className:"grid min-w-0 grid-cols-3 gap-2 sm:gap-3",children:d.map(e=>(0,a.jsxs)("div",{className:"min-w-0 rounded-xl border bg-card px-3 py-4 sm:px-5",children:[(0,a.jsx)("p",{className:"text-xs text-muted-foreground [overflow-wrap:anywhere] sm:text-sm",children:l(o(e.name))}),(0,a.jsx)("p",{className:"mt-1 text-2xl font-semibold tabular-nums sm:text-3xl",children:e.count})]},e.name))}),(0,a.jsxs)("div",{className:"flex items-start gap-2 rounded-xl bg-violet-50/60 px-4 py-3 text-sm leading-6 text-violet-950 dark:bg-violet-950/30 dark:text-violet-200",children:[(0,a.jsx)(v.A,{className:"mt-1 size-4 shrink-0","aria-hidden":"true"}),(0,a.jsx)("p",{children:l(o("scope"))})]}),0===t.total?(0,a.jsxs)("div",{className:"space-y-2 rounded-xl border border-dashed p-6",children:[(0,a.jsx)("p",{className:"font-medium",children:l(o("empty"))}),(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:l(o("emptyHint"))})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("ul",{className:"divide-y overflow-hidden rounded-xl border bg-card",children:t.rows.map(e=>{let t,s=e.contactName.trim()||l(o("chat"),{id:e.conversationId});return(0,a.jsxs)("li",{className:"grid min-w-0 gap-4 p-4 sm:p-5 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] lg:items-center",children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-start gap-3",children:[(0,a.jsx)("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full bg-violet-50 text-violet-700 dark:bg-violet-950/40 dark:text-violet-300",children:(0,a.jsx)(G.A,{className:"size-4","aria-hidden":"true"})}),(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("p",{className:"font-semibold [overflow-wrap:anywhere]",children:s}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:l(o("lastActivity"),{date:c(e.lastActivityAt)})})]})]}),(0,a.jsxs)("div",{className:"min-w-0 space-y-2",children:[(0,a.jsx)("span",{className:"inline-flex rounded-md px-2 py-1 text-xs font-medium ".concat("reply_pending"===(t=e.attention)?"bg-violet-50 text-violet-900 dark:bg-violet-950/40 dark:text-violet-200":"follow_up"===t?"bg-amber-50 text-amber-950 dark:bg-amber-950/40 dark:text-amber-200":"bg-muted text-muted-foreground"),children:l(o(e.attention))}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:l(o("".concat(e.attention,"Hint")))})]}),(0,a.jsx)(N.$,{variant:"outline",asChild:!0,className:"min-h-11 cursor-pointer whitespace-normal lg:max-w-48",children:(0,a.jsxs)(F(),{prefetch:!1,href:{pathname:"/conversations/".concat(e.conversationId),query:{leadId:e.id}},"aria-label":l(o("openChatNamed"),{name:s}),children:[l(o("openChat")),(0,a.jsx)(M.A,{className:"size-4 shrink-0","aria-hidden":"true"})]})})]},e.id)})}),(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:l(o("showing"),{from:t.rows.length?s+1:0,to:t.rows.length?s+t.rows.length:0,total:t.total})}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(N.$,{variant:"outline",disabled:0===s,onClick:()=>r(Math.max(0,s-25)),className:"min-h-11 cursor-pointer",children:l(o("previous"))}),(0,a.jsx)(N.$,{variant:"outline",disabled:void 0===t.nextCursor,onClick:()=>{void 0!==t.nextCursor&&r(t.nextCursor)},className:"min-h-11 cursor-pointer",children:l(o("next"))})]})]})]}),(0,a.jsxs)("div",{className:"flex items-start gap-2 text-xs leading-5 text-muted-foreground",children:[(0,a.jsx)(K.A,{className:"mt-0.5 size-3.5 shrink-0","aria-hidden":"true"}),(0,a.jsxs)("p",{children:[l(o("updated"),{date:c(t.checkedAt)})," \xb7 ",l(o("autoRefresh"))]})]}),(0,a.jsxs)("div",{className:"space-y-1 border-t pt-6",children:[(0,a.jsx)("h3",{className:"text-base font-semibold",children:l(o("assignedHeading"))}),(0,a.jsx)("p",{className:"max-w-3xl text-sm leading-6 text-muted-foreground",children:l(o("assignedHint"))})]})]})}var es=s(68435),ea=s(52580),er=s(82864),ei=s(34223);function el(e,t){let s=new Date(e);return Number.isNaN(s.getTime())?"":new Intl.DateTimeFormat("en"===t?"en-US":"es-AR",{dateStyle:"medium",timeStyle:"short"}).format(s)}function en(e){var t,s,i,l;let{open:n,workspaceId:o,userId:c,opportunity:d,pipeline:m,onClose:u}=e,{t:x}=(0,j.o)(),p=k.id.useUtils(),[h,g]=(0,r.useState)(null!=(l=null==(t=d.currentStep)?void 0:t.stepId)?l:""),f=k.id.sellerCopilot.moveCommercialStage.useMutation({onSuccess:async()=>
1{u(),await Promise.all([p.sellerCopilot.invalidate(),p.pipeline.invalidate()])},onError:async()=>{H.oR.error(x("commercial.error")),await p.sellerCopilot.invalidate()}}),b=null==(s=m.steps.find(e=>e.stepId===h))?void 0:s.flags;return(0,a.jsx)(ei.cj,{open:n,onOpenChange:e=>{e||u()},children:(0,a.jsxs)(ei.h,{hideClose:!0,className:"w-full overflow-y-auto bg-background sm:max-w-xl",children:[(0,a.jsx)(ei.kN,{asChild:!0,children:(0,a.jsx)(N.$,{type:"button",variant:"ghost",size:"icon",className:"absolute right-2 top-2 z-10 size-11 rounded-lg text-muted-foreground sm:right-3 sm:top-3","aria-label":x("common.close"),children:(0,a.jsx)(T.A,{className:"size-5","aria-hidden":"true"})})}),(0,a.jsxs)(ei.Fm,{className:"border-b px-5 pt-6 pb-5 pr-12 sm:px-7 sm:pt-7",children:[(0,a.jsx)("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-primary-80",children:x("commercial.review.eyebrow")}),(0,a.jsx)(ei.qp,{className:"mt-1 break-words font-poppins text-xl text-foreground",children:d.contactName}),(0,a.jsxs)(ei.Qs,{className:"mt-2 flex items-start gap-2 leading-5",children:[(0,a.jsx)(v.A,{className:"mt-0.5 size-4 shrink-0","aria-hidden":"true"}),(0,a.jsx)("span",{children:x("commercial.privacy")})]})]}),(0,a.jsxs)("div",{className:"space-y-7 px-5 pb-8 sm:px-7",children:[0===d.suggestions.length?(0,a.jsxs)("section",{className:"border-b py-5","aria-label":x("commercial.current"),children:[(0,a.jsx)("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:x("commercial.review.currentStage")}),(0,a.jsx)("p",{className:"mt-2 text-base font-semibold text-foreground",children:d.currentStep?(0,I.jl)(x,d.currentStep,!1):x("commercial.handoff")})]}):null,d.suggestions.map(e=>(0,a.jsx)(eo,{workspaceId:o,userId:c,suggestion:e,currentStep:d.currentStep,onResolved:u},e.id)),(0,a.jsxs)("details",{className:"group border-t pt-1",children:[(0,a.jsxs)("summary",{className:"flex min-h-11 cursor-pointer list-none items-center justify-between gap-3 rounded-lg py-2 text-sm font-semibold text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary-80/50 [&::-webkit-details-marker]:hidden",children:[(0,a.jsx)("span",{children:x("commercial.review.manualSummary")}),(0,a.jsx)(P.A,{className:"size-4 shrink-0 text-muted-foreground transition-transform group-open:rotate-180","aria-hidden":"true"})]}),(0,a.jsxs)("div",{className:"space-y-3 pt-3 pb-2",children:[(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:x("commercial.review.manualDescription")}),(0,a.jsx)(w.J,{htmlFor:"commercial-target",children:x("commercial.stage")}),(0,a.jsx)("select",{id:"commercial-target",value:h,disabled:f.isPending,onChange:e=>g(e.target.value),className:"min-h-11 w-full cursor-pointer rounded-lg border bg-background px-3 text-base",children:m.steps.map(e=>(0,a.jsx)("option",{value:e.stepId,children:(0,I.jl)(x,e,!1)},e.stepId))}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:x((null==b?void 0:b.countsAsWon)||(null==b?void 0:b.countsAsLost)?"commercial.terminal":"commercial.confirmHint")}),(0,a.jsx)(N.$,{variant:"primary",className:"min-h-11 w-full cursor-pointer",loading:f.isPending,disabled:!h||h===(null==(i=d.currentStep)?void 0:i.stepId)||!d.currentStep,onClick:()=>{d.currentStep&&f.mutate({workspaceId:o,...c?{userId:c}:{},leadId:d.leadId,fromStepId:d.currentStep.stepId,toStepId:h,expectedUpdatedAt:new Date(d.currentStepUpdatedAt),confirmed:!0})},children:x("commercial.saveStage")})]})]}),d.conversationId&&d.conversationLeadId?(0,a.jsx)(N.$,{variant:"ghost",asChild:!0,className:"min-h-11 w-full cursor-pointer justify-between border-t px-0 text-muted-foreground hover:bg-transparent hover:text-foreground",children:(0,a.jsxs)(F(),{href:{pathname:"/conversations/".concat(d.conversationId),query:{leadId:d.conversationLeadId}},children:[(0,a.jsxs)("span",{className:"flex items-center gap-2",children:[(0,a.jsx)(es.A,{className:"size-4","aria-hidden":"true"}),x("dashboard.seller_copilot.open_conversation")]}),(0,a.jsx)(ea.A,{className:"size-4","aria-hidden":"true"})]})}):null]})]})})}function eo(e){let{workspaceId:t,userId:s,suggestion:i,currentStep:l,onResolved:n}=e,{t:o,currentLanguage:c}=(0,j.o)(),d=k.id.useUtils(),[m,u]=(0,r.useState)(!1),x={workspaceId:t,...s?{userId:s}:{},suggestionId:i.id},p=k.id.sellerCopilot.getCommercialEvidence.useQuery(x,{enabled:m&&i.hasEvidence,retry:!1,staleTime:0,gcTime:0}),h=async()=>
1{n(),await Promise.all([d.sellerCopilot.invalidate(),d.pipeline.invalidate()])},g=async()=>{u(!1),H.oR.error(o("commercial.error")),await d.sellerCopilot.invalidate()},f=k.id.sellerCopilot.confirmCommercialSuggestion.useMutation({onSuccess:h,onError:g}),b=k.id.sellerCopilot.dismissCommercialSuggestion.useMutation({onSuccess:h,onError:g}),w=k.id.sellerCopilot.snoozeCommercialSuggestion.useMutation({onSuccess:h,onError:g}),y=f.isPending||b.isPending||w.isPending,C=l?(0,I.jl)(o,l,!1):o("commercial.handoff"),A=(0,I.jl)(o,i.targetStep,!1);return(0,a.jsxs)("section",{className:"space-y-5 border-b pb-7","aria-labelledby":"suggestion-".concat(i.id),children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("p",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-primary-80",children:o("commercial.suggestion")}),(0,a.jsx)("h3",{id:"suggestion-".concat(i.id),className:"text-lg font-semibold text-foreground",children:o("commercial.review.decision")})]}),(0,a.jsxs)("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-3 rounded-xl border bg-muted/20 p-4",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:o("commercial.review.currentStage")}),(0,a.jsx)("p",{className:"mt-1 break-words text-sm font-semibold text-foreground",children:C})]}),(0,a.jsx)(_.A,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-[0.12em] text-primary-80",children:o("commercial.review.suggestedStage")}),(0,a.jsx)("p",{className:"mt-1 break-words text-sm font-semibold text-foreground",children:A})]})]}),i.reasonCode?(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:o("commercial.reasons.".concat(i.reasonCode))}):null,m?p.isError?(0,a.jsx)("p",{role:"alert",className:"text-sm text-destructive",children:o("commercial.noEvidence")}):p.isPending||p.isFetching?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",role:"status",children:o("common.loading")}):p.data?(0,a.jsxs)("div",{className:"space-y-4","aria-label":o("commercial.evidenceTitle"),children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:[(0,a.jsx)(v.A,{className:"size-4","aria-hidden":"true"}),o("commercial.review.workEvidence")]}),p.data.messages.map(e=>(0,a.jsxs)("article",{className:"border-l-2 border-border pl-4",children:[(0,a.jsxs)("header",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1 text-xs",children:[(0,a.jsx)("span",{className:"font-semibold text-foreground",children:o("commercial.review.".concat(e.role))}),(0,a.jsx)("time",{className:"text-muted-foreground",dateTime:String(e.occurredAt),children:el(e.occurredAt,c)})]}),(0,a.jsx)("blockquote",{className:"mt-2 whitespace-pre-wrap break-words text-sm leading-6 text-foreground",children:e.text})]},e.id)),p.data.meeting?(0,a.jsxs)("div",{className:"border-l-2 border-border pl-4 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 font-semibold text-foreground",children:[(0,a.jsx)(er.A,{className:"size-4","aria-hidden":"true"}),o("commercial.review.calendar")]}),(0,a.jsx)("p",{className:"mt-2 leading-6 text-muted-foreground",children:o("commercial.meetingEvidence")}),(0,a.jsx)("time",{className:"mt-2 block font-medium text-foreground",dateTime:String(p.data.meeting.startAt),children:el(p.data.meeting.startAt,c)})]}):null,(0,a.jsxs)("div",{className:"space-y-3 border-t pt-4",children:[(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:o("commercial.confirmHint")}),(0,a.jsx)(N.$,{variant:"primary",className:"min-h-11 w-full cursor-pointer",loading:f.isPending,disabled:y,onClick:()=>f.mutate(x),children:o("commercial.confirm")})]})]}):null:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:o("commercial.review.evidenceIntro")}),(0,a.jsx)(N.$,{variant:"outline",className:"min-h-11 w-full cursor-pointer",disabled:!i.hasEvidence,onClick:()=>u(!0),children:o("commercial.evidence")})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-x-2 gap-y-1 border-t pt-2",children:[(0,a.jsx)(N.$,{variant:"ghost",className:"min-h-11 cursor-pointer px-3 text-muted-foreground",disabled:y,onClick:()=>w.mutate({...x,until:new Date(Date.now()+36e5)}),children:o("commercial.snooze")}),(0,a.jsx)(N.$,{variant:"ghost",className:"min-h-11 cursor-pointer px-3 text-muted-foreground",disabled:y,onClick:()=>b.mutate(x),children:o("commercial.dismiss")})]}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:o("commercial.snoozeHint")})]})}var ec=s(3846),ed=s(61097);let em=e=>e.findings.some(e=>
1"conversation_started"!==e.reasonCode),eu=e=>e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase();function ex(e,t){var s;return"analyzed"===e.analysisStatus&&e.inferredStepId&&null!=(s=t.find(t=>{var s,a;return t.stepId===e.inferredStepId&&!(null==(s=t.flags)?void 0:s.countsAsWon)&&!(null==(a=t.flags)?void 0:a.countsAsLost)&&e.findings.some(e=>e.targetStepId===t.stepId)}))?s:null}function ep(e){let{data:t,impersonatedName:s}=e,{t:i,currentLanguage:l}=(0,j.o)(),[n,o]=(0,r.useState)("list"),[c,d]=(0,r.useState)("all"),[m,u]=(0,r.useState)(""),[x,p]=(0,r.useState)(!1),[h,g]=(0,r.useState)(),f=e=>{let t=e?new Date(e):null;return t&&Number.isFinite(t.getTime())?t.toLocaleDateString(l,{day:"numeric",month:"short",year:"numeric"}):i("commercial.historical.dateUnknown")},b=e=>{let t=e.contactName.trim();return t&&!["sin nombre","no name","unknown","contacto","contact"].includes(eu(t))?t:e.phone||i("commercial.historical.chat",{id:e.conversationId})},w=(0,r.useMemo)(()=>[...t.opportunities].sort((e,t)=>{let s=Number(em(t))-Number(em(e));if(s)return s;let a=e=>Math.max(0,...e.findings.map(e=>new Date(e.observedAt).getTime()));return a(t)-a(e)||e.personalLeadId.localeCompare(t.personalLeadId)}),[t.opportunities]),y=w.filter(em),k=w.filter(e=>("all"===c||em(e))&&eu([e.contactName,e.phone,e.conversationId].filter(Boolean).join(" ")).includes(eu(m.trim()))),C=w.filter(e=>"analyzed"!==e.analysisStatus).length,A={conversation:w.filter(e=>e.findings.some(e=>"conversation_started"===e.reasonCode)).length,meeting:w.filter(e=>e.findings.some(e=>"meeting_agreed"===e.reasonCode)).length,proposal:w.filter(e=>e.findings.some(e=>"proposal_shared"===e.reasonCode)).length},S=w.find(e=>e.personalLeadId===h),U=(0,ed.l)(S),R=[...t.pipeline.steps].sort((e,t)=>e.order-t.order).filter(e=>{var s,a,r;return!(null==(s=e.flags)?void 0:s.countsAsWon)&&!(null==(a=e.flags)?void 0:a.countsAsLost)&&(["human_contacted","meeting_scheduled","proposal_sent"].includes(null!=(r=e.semanticMilestone)?r:"")||w.some(s=>{var a;return(null==(a=ex(s,t.pipeline.steps))?void 0:a.stepId)===e.stepId}))}),M=[{id:"pending",label:i("commercial.historical.pendingStage"),items:k.filter(e=>!ex(e,t.pipeline.steps))},...R.map(e=>({id:e.stepId,label:(0,I.jl)(i,e,!1),items:k.filter(s=>{var a;return(null==(a=ex(s,t.pipeline.steps))?void 0:a.stepId)===e.stepId})}))],P=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=ex(e,t.pipeline.steps),l=em(e),n=[...e.findings].sort((e,t)=>Number("conversation_started"!==t.reasonCode)-Number("conversation_started"!==e.reasonCode)||new Date(t.observedAt).getTime()-new Date(e.observedAt).getTime())[0];return(0,a.jsxs)("button",{type:"button",onClick:()=>g(e.personalLeadId),"aria-label":i("commercial.historical.details",{name:b(e)}),"data-testid":"historical-opportunity-".concat(e.personalLeadId),className:"group w-full min-w-0 cursor-pointer text-left transition-colors focus-visible:relative focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-violet-600 ".concat(s?"grid grid-cols-[minmax(0,1fr)_20px] items-center gap-x-4 gap-y-3 border-b px-4 py-5 last:border-b-0 hover:bg-muted/40 sm:px-5 lg:grid-cols-[minmax(0,1.05fr)_minmax(120px,0.7fr)_minmax(0,1fr)_20px]":"space-y-4 rounded-xl border bg-card p-4 hover:border-violet-400"," ").concat(s&&l?"bg-violet-50/40 dark:bg-violet-950/15":""),children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("span",{className:"flex size-10 shrink-0 items-center justify-center rounded-full ".concat(l?"bg-violet-100 text-violet-800 dark:bg-violet-900/50 dark:text-violet-200":"bg-muted text-muted-foreground"),"aria-hidden":"true",children:(0,a.jsx)(es.A,{className:"size-4"})}),(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("p",{className:"break-words text-sm font-semibold tracking-[-0.01em]",children:b(e)}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:i("commercial.historical.chat",{id:e.conversationId})})]})]}),(0,a.jsxs)("div",{className:s?"col-start-1 row-start-2 lg:col-start-auto lg:row-start-auto":"",children:[(0,a.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:i("commercial.historical.inferred")}),(0,a.jsx)("p",{className:"mt-1 break-words text-sm ".concat(r?"font-medium":"text-muted-foreground"),children:r?(0,I.jl)(i,r,!1):i("commercial.historical.pendingStage")}),r?(0,a.jsx)("p",{className:"mt-1 text-[11px] text-muted-foreground",children:i("commercial.historical.notConfirmed")}):null]}),(0,a.jsxs)("div",{className:s?"col-start-1 row-start-3 lg:col-start-auto lg:row-start-auto":"",children:[(0,a.jsx)("p",{className:"text-xs leading-5 ".concat(l?"font-medium text-violet-800 dark:text-violet-300":"text-muted-foreground"),children:n?i("commercial.historical.signal.".concat(n.reasonCode)):i("commercial.historical.unknownCard")}),"analyzed"!==e.analysisStatus?(0,a.jsx)("p",{className:"mt-1 text-xs leading-5 text-amber-800 dark:text-amber-300",children:i("commercial.historical.partialCard")}):n?(0,a.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:f(n.observedAt)}):null]}),(0,a.jsx)(q.A,{className:"size-4 text-muted-foreground ".concat(s?"col-start-2 row-start-1 lg:col-start-auto lg:row-start-auto":"hidden"),"aria-hidden":"true"})]},e.personalLeadId)};return(0,a.jsxs)("div",{className:"min-w-0 space-y-5 sm:space-y-7","data-testid":"historical-review",children:[s?(0,a.jsx)("p",{role:"status",className:"rounded-lg border border-amber-300/60 bg-amber-50 px-4 py-3 text-sm text-amber-950 dar
1k:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100",children:i("commercial.impersonationActive",{name:s})}):null,(0,a.jsxs)("header",{className:"flex flex-wrap items-start justify-between gap-3 border-b pb-4 sm:pb-6",children:[(0,a.jsxs)("div",{className:"max-w-2xl space-y-2.5",children:[(0,a.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-violet-800 dark:text-violet-300",children:i("commercial.historical.eyebrow")}),(0,a.jsx)("h1",{className:"text-2xl font-semibold leading-[1.16] tracking-[-0.045em] sm:text-[34px]",children:i("commercial.historical.heading")}),(0,a.jsx)("p",{className:"max-w-xl text-sm leading-6 text-muted-foreground",children:i("commercial.historical.description")})]}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-2 rounded-full border bg-muted/30 px-3 py-2 text-xs font-medium text-muted-foreground",children:[(0,a.jsx)(ec.A,{className:"size-3.5","aria-hidden":"true"}),i("commercial.historical.banner")]})]}),(0,a.jsxs)("p",{className:"flex items-start gap-2 rounded-xl border border-violet-200/70 bg-violet-50/50 px-4 py-3 text-sm leading-6 text-violet-950 dark:border-violet-800/60 dark:bg-violet-950/20 dark:text-violet-100",children:[(0,a.jsx)(v.A,{className:"mt-1 size-4 shrink-0","aria-hidden":"true"}),i("commercial.historical.bannerHint")]}),(0,a.jsx)("dl",{className:"grid grid-cols-3 gap-2 sm:gap-4",children:[{key:"portfolio",count:t.total},{key:"priority",count:y.length},{key:"partial",count:C}].map(e=>{let{key:t,count:s}=e;return(0,a.jsxs)("div",{className:"min-w-0 rounded-xl border bg-card px-3 py-4 sm:px-5",children:[(0,a.jsx)("dt",{className:"text-xs leading-5 text-muted-foreground",children:i("commercial.historical.".concat(t))}),(0,a.jsx)("dd",{className:"mt-1 text-2xl font-semibold tabular-nums tracking-tight sm:text-3xl",children:s})]},t)})}),(0,a.jsx)("div",{className:"flex justify-end xl:hidden",children:(0,a.jsxs)("button",{type:"button","aria-expanded":x,"aria-controls":"historical-assistant",onClick:()=>p(e=>!e),className:"flex min-h-11 cursor-pointer items-center gap-2 rounded-lg px-3 text-sm font-medium text-violet-800 focus-visible:outline-2 focus-visible:outline-violet-600 dark:text-violet-300",children:[(0,a.jsx)(E.A,{className:"size-4","aria-hidden":"true"}),i("commercial.workspaceUI.assistantToggle")]})}),(0,a.jsxs)("div",{className:"grid min-w-0 items-start gap-6 xl:grid-cols-[minmax(0,1fr)_288px] xl:grid-rows-[auto_1fr]",children:[(0,a.jsxs)("section",{className:"flex flex-wrap items-center justify-between gap-3 rounded-xl border-l-[3px] border-l-violet-600 bg-violet-50/70 px-4 py-4 dark:bg-violet-950/25 sm:px-6 xl:col-start-1 xl:row-start-1",children:[(0,a.jsxs)("div",{className:"max-w-xl space-y-2",children:[(0,a.jsx)("h2",{className:"text-base font-semibold tracking-[-0.025em]",children:i("commercial.historical.priorityHeading")}),(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:i("commercial.historical.priorityHint",{count:y.length})})]}),y[0]?(0,a.jsxs)(N.$,{variant:"ghost",className:"min-h-11 cursor-pointer whitespace-normal rounded-lg px-0 text-left text-violet-800 hover:bg-violet-100 dark:text-violet-300 dark:hover:bg-violet-900/40",onClick:()=>g(y[0].personalLeadId),children:[i("commercial.historical.reviewNext"),(0,a.jsx)(_.A,{className:"size-4","aria-hidden":"true"})]}):null]}),(0,a.jsxs)("aside",{id:"historical-assistant","aria-label":i("commercial.historical.assistant"),className:"min-w-0 space-y-5 rounded-2xl border bg-card p-5 xl:col-start-2 xl:row-start-1 xl:row-span-2 xl:block ".concat(x?"block":"hidden"),children:[(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("span",{className:"flex size-10 items-center justify-center rounded-xl bg-violet-100 text-violet-800 dark:bg-violet-900/50 dark:text-violet-200",children:(0,a.jsx)(E.A,{className:"size-5","aria-hidden":"true"})}),(0,a.jsx)("h2",{className:"text-base font-semibold tracking-tight",children:i("commercial.historical.assistant")}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:i("commercial.historical.assistantHint")})]}),(0,a.jsx)("ul",{className:"space-y-3 text-sm",children:["conversation","meeting","proposal"].map(e=>(0,a.jsxs)("li",{className:"flex items-start gap-2",children:[(0,a.jsx)("span",{className:"mt-2 size-1.5 shrink-0 rounded-full bg-violet-500","aria-hidden":"true"}),(0,a.jsx)("span",{children:i("commercial.historical.".concat(e,"Count"),{count:A[e]})})]},e))}),(0,a.jsx)("p",{className:"border-t pt-4 text-xs leading-5 text-muted-foreground",children:i("commercial.historical.assistantSafety")}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:i("commercial.historical.generated",{date:f(t.generatedAt)})})]}),(0,a.jsxs)("section",{className:"min-w-0 space-y-4 xl:col-start-1 xl:row-start-2","aria-label":i("commercial.workspaceUI.queue"),children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,a.jsxs)("h2",{className:"text-base font-semibold tracking-[-0.02em]",children:[i("commercial.workspaceUI.queue"),(0,a.jsx)("span",{className:"ml-2 text-sm font-normal tabular-nums text-muted-foreground",children:k.length})]}),(0,a.jsx)("div",{role:"group","aria-label":i("commercial.workspaceUI.viewMode"),className:"flex gap-1 rounded-lg border p-1",children:[{value:"list",icon:z.A},{value:"board",icon:D.A}].map(e=>{let{value:t,icon:s}=e;return(0,a.jsx)("button",{type:"button","aria-label":i("commercial.".concat(t)),"aria-pressed":n===t,onClick:()=>o(t),className:"flex min-h-11 min-w-11 cursor-pointer items-center justify-center rounded-md px-2.5 focus-visible:outline-2 focus-visible:outline-violet-600 ".concat(n===t?"bg-muted text-foreground":"text-muted-foreground hover:bg-muted/50"),children:(0,a.jsx)(s,{className:"size-4","aria-hidden":"true"})},t)})})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,a.jsx)("div",{role:"group","aria-label":i("commercial.workspaceUI.queue"),className:"flex gap-1",children:["all","priority"].map(e=>(0,a.jsxs)("button",{type:"button","aria-pressed":c===e,onClick:()=>d(e),className:"min-h-11 cursor-pointer rounded-lg px-3 text-xs font-medium focus-visible:outline-2 focus-visible:outline-violet-600 ".concat(c===e?"bg-foreground text-background":"text-muted-foreground hover:bg-muted"),children:[i("all"===e?"commercial.historical.all":"commercial.historical.toReview"),"priority"===e?(0,a.jsx)("span",{className:"ml-2 tabular-nums opacity-70",children:y.length}):null]},e))}),(0,a.jsxs)("div",{className:"flex min-h-11 w-full items-center gap-2 rounded-lg border bg-card px-3 sm:w-64",children:[(0,a.jsx)(L.A,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,a.jsx)("input",{"aria-label":i("commercial.historical.search"),placeholder:i("commercial.historical.search"),value:m,onChange:e=>u(e.target.value),className:"min-w-0 flex-1 bg-transparent py-2 text-base outline-none placeholder:text-muted-foreground focus-visible:outline-2 focus-visible:outline-violet-600 sm:text-sm"}),m?(0,a.jsx)("button",{type:"button",onClick:()=>u(""),"aria-label":i("commercial.workspaceUI.clearSearch"),className:"flex min-h-11 min-w-11 cursor-pointer items-center justify-center rounded-md focus-visible:outline-2 focus-visible:outline-violet-600",children:(0,a.jsx)(T.A,{className:"size-4","aria-hidden":"true"})}):null]})]}),k.length?"list"===n?(0,a.jsx)("div",{className:"overflow-hidden rounded-xl border bg-card","data-testid":"historical-list",children:k.map(e=>P(e,!0))}):(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:i("commercial.historical.boardHint")}),(0,a.jsx)("div",{className:"grid min-w-0 grid-flow-col auto-cols-[minmax(240px,1fr)] gap-4 overflow-x-auto pb-3","data-testid":"historical-board",children:M.map(e=>(0,a.jsxs)("section",{"aria-label":e.label,"data-testid":"historical-column-".concat(e.id),className:"min-w-0 rounded-xl border bg-muted/25 p-3",children:[(0,a.jsxs)("div",{className:"mb-3 flex items-start justify-between gap-2",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold leading-5",children:e.label}),(0,a.jsx)("span",{className:"rounded-md bg-background px-2 py-0.5 text-xs tabular-nums text-muted-foreground",children:e.items.length})]}),(0,a.jsx)("div",{className:"max-h-[65vh] space-y-3 overflow-y-auto",children:e.items.length?e.items.map(e=>P(e)):(0,a.jsx)("p",{className:"p-3 text-xs leading-5 text-muted-foreground",children:i("commercial.workspaceUI.emptyStage")})})]},e.id))})]}):(0,a.jsxs)("div",{className:"rounded-xl border px-5 py-10 text-center",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:i(w.length?"commercial.workspaceUI.noMatches":"commercial.historical.empty")}),w.length?(0,a.jsx)(N.$,{variant:"ghost",className:"mt-3 min-h-11 cursor-pointer",onClick:()=>{u(""),d("all")},children:i("commercial.workspaceUI.resetFilters")}):null]}),t.excludedSinceImport>0?(0,a.jsx)("p",{className:"text-xs leading-5 text-amber-800 dark:text-amber-300",children:i("commercial.historical.excluded",{count:t.excludedSinceImport})}):null,(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:i("commercial.historical.limitations")})]})]}),U?(0,a.jsx)(ei.cj,{open:!!S,onOpenChange:e=>{e||g(void 0)},children:(0,a.jsxs)(ei.h,{hideClose:!0,className:"w-full gap-0 overflow-y-auto sm:max-w-lg",children:[(0,a.jsxs)(ei.Fm,{className:"space-y-3 border-b px-5 pb-5 pt-6 pr-16",children:[(0,a.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-violet-800 dark:text-violet-300",children:i("commercial.historical.banner")}),(0,a.jsx)(ei.qp,{className:"break-words text-2xl tracking-tight",children:b(U)}),(0,a.jsx)(ei.Qs,{className:"text-sm leading-6",children:i("commercial.historical.detailHint")})]}),(0,a.jsx)(ei.kN,{className:"absolute right-3 top-3 flex min-h-11 min-w-11 cursor-pointer items-center justify-center rounded-lg text-muted-foreground hover:bg-muted focus-visible:outline-2 focus-visible:outline-violet-600","aria-label":i("commercial.close"),children:(0,a.jsx)(T.A,{className:"size-5","aria-hidden":"true"})}),(0,a.jsxs)("div",{className:"space-y-6 px-5 py-6 pb-[max(24px,env(safe-area-inset-bottom))]",children:[(0,a.jsxs)("div",{className:"space-y-2 rounded-xl bg-violet-50/70 p-4 dark:bg-violet-950/25",children:[(0,a.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-violet-800 dark:text-violet-300",children:i("commercial.historical.inferred")}),(0,a.jsx)("p",{className:"text-base font-semibold",children:ex(U,t.pipeline.steps)?(0,I.jl)(i,ex(U,t.pipeline.steps),!1):i("commercial.historical.pendingStage")}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:i("commercial.historical.notConfirmed")})]}),"analyzed"!==U.analysisStatus?(0,a.jsx)("p",{className:"rounded-xl border border-amber-200 bg-amber-50 p-4 text-sm leading-6 text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-200",children:i(U.rejectedWindows>0?"commercial.historical.partialDetail":"commercial.historical.failedDetail",{c
1ount:U.rejectedWindows})}):null,(0,a.jsxs)("section",{className:"space-y-3",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold",children:i("commercial.historical.evidenceTitle")}),U.findings.length?U.findings.map(e=>(0,a.jsxs)("article",{className:"space-y-2 rounded-xl border p-4",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:i("commercial.historical.signal.".concat(e.reasonCode))}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:i("commercial.historical.observed",{date:f(e.observedAt)})}),(0,a.jsx)("p",{className:"break-words text-xs leading-5 text-muted-foreground",children:i("commercial.historical.evidenceIds",{ids:e.evidenceMessageIds.join(", ")})})]},"".concat(e.reasonCode,":").concat(e.observedAt))):(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:i("commercial.historical.unknownCard")})]}),(0,a.jsxs)("dl",{className:"space-y-4 text-sm",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("dt",{className:"font-medium",children:i("commercial.historical.sourceRange")}),(0,a.jsx)("dd",{className:"text-muted-foreground",children:i("commercial.historical.range",{from:f(U.sourceOldestAt),to:f(U.sourceNewestAt)})})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("dt",{className:"font-medium",children:i("commercial.historical.mappingTitle")}),(0,a.jsx)("dd",{className:"leading-6 text-muted-foreground",children:i("commercial.historical.mapping.".concat(U.mappingStatus))})]})]}),(0,a.jsxs)("div",{className:"space-y-3 border-t pt-5",children:[(0,a.jsx)(N.$,{asChild:!0,variant:"outline",className:"min-h-11 w-full cursor-pointer rounded-lg",children:(0,a.jsxs)(F(),{prefetch:!1,href:{pathname:"/conversations/".concat(U.conversationId),query:{leadId:U.personalLeadId}},children:[(0,a.jsx)(es.A,{className:"size-4","aria-hidden":"true"}),i("commercial.historical.openChat")]})}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:i("commercial.historical.openChatHint")})]})]})]})}):null]})}function eh(e){let{workspaceId:t,userId:s,data:i,isError:l,onRetry:o,onBeforeChange:c,onAfterChange:m}=e,{t:u}=(0,j.o)(),x=(0,r.useId)(),p=(0,r.useId)(),[h,g]=(0,r.useState)(!1),[f,b]=(0,r.useState)(!1),[I,C]=(0,r.useState)(!1),A=k.id.sellerCopilot.setCommercialConsent.useMutation(),S=async e=>{if(!I&&!l&&(null==i?void 0:i.enabled)&&(!e||i.hasPersonalLine&&f)){C(!0),b(!1);try{await c(),await A.mutateAsync({workspaceId:t,...s?{userId:s}:{},enabled:e}),H.oR.success(u("commercial.accessSaved"))}catch(e){H.oR.error(u("commercial.error"))}finally{try{await m()}catch(e){H.oR.error(u("commercial.error"))}C(!1),g(!1)}}};return l?(0,a.jsx)(d.E,{onRetry:o}):i?i.enabled?(0,a.jsxs)("section",{className:"mb-5 overflow-hidden rounded-2xl border bg-card","aria-label":u("commercial.consentTitle"),children:[(0,a.jsxs)("div",{className:"flex flex-col gap-4 p-5 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0 space-y-1.5",children:[(0,a.jsxs)("h2",{className:"flex items-center gap-2 text-base font-semibold",children:[(0,a.jsx)(v.A,{className:"size-4 shrink-0 text-violet-700 dark:text-violet-300","aria-hidden":"true"}),u("commercial.consentTitle")]}),(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:u("commercial.accessSettingsHint")}),i.consent.enabled?(0,a.jsx)("p",{className:"text-xs font-medium text-emerald-700 dark:text-emerald-300",children:u("commercial.consentActive")}):null]}),(0,a.jsxs)(N.$,{variant:"outline",className:"min-h-11 shrink-0 cursor-pointer whitespace-normal",disabled:I,"aria-expanded":h,"aria-controls":x,onClick:()=>{g(e=>!e),b(!1)},children:[u("commercial.workspaceUI.privacySettings"),(0,a.jsx)(P.A,{className:"size-4 shrink-0 transition-transform motion-reduce:transition-none ".concat(h?"rotate-180":""),"aria-hidden":"true"})]})]}),h?(0,a.jsxs)("div",{id:x,className:"space-y-4 border-t bg-muted/15 p-5",children:[(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:u("commercial.privacy")}),i.consent.enabled?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"max-w-3xl text-sm leading-6",children:u("commercial.consentDescription")}),(0,a.jsx)(N.$,{variant:"outline",className:"min-h-11 cursor-pointer whitespace-normal",loading:I,onClick:()=>void S(!1),children:u("commercial.consentRevoke")})]}):i.hasPersonalLine?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex max-w-3xl items-start gap-3",children:[(0,a.jsx)(y.S,{id:p,checked:f,disabled:I,onCheckedChange:e=>b(!0===e),className:"mt-1 cursor-pointer"}),(0,a.jsx)(w.J,{htmlFor:p,className:"cursor-pointer text-sm leading-6",children:u("commercial.consentDescription")})]}),(0,a.jsx)(N.$,{className:"min-h-11 cursor-pointer whitespace-normal bg-violet-700 text-white hover:bg-violet-800",disabled:!f,loading:I,onClick:()=>void S(!0),children:u("commercial.consentEnable")})]}):(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:u("commercial.consentNoLine")}),(0,a.jsx)("p",{className:"text-xs leading-5 text-muted-foreground",children:u("commercial.historicalAccessHint")})]}):null]}):(0,a.jsx)("p",{className:"mb-5 rounded-2xl border p-5 text-sm text-muted-foreground",children:u("commercial.unavailable")}):(0,a.jsx)(n.E,{className:"mb-5 h-28 rounded-2xl"})}var eg=s(90876),ef=s(29358),eb=s(48160),ev=s(15726),ej=s(77863),eN=!0;function ew(){var e,t;let{t:s}=(0,j.o)(),r=(0,i.useSession)(),{currentWorkspace:c,can:d,isLoading:m}=(0,ev.hA)(),{isImpersonating:u,impersonationUiVisible:x,isInitialized:p,effectiveUserId:h,selectedUser:g}=(0,ej.Wu)();return"authenticated"===r.status&&(null==(t=r.data)||null==(e=t.user)?void 0:e.id)&&!m&&p&&h?c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(eg.F,{workspaceId:c._id,effectiveUserId:h,userId:u?h:void 0,pageContainer:!0},"commitments:".concat(c._id,":").concat(h)),(0,a.jsx)(ef.h,{workspaceId:c._id,effectiveUserId:h,userId:u?h:void 0,pageContainer:!0},"meeting-reviews:".concat(c._id,":").concat(h)),(0,a.jsx)(ey,{workspaceId:c._id,effectiveUserId:h,userId:u?h:void 0,impersonatedName:x?(null==g?void 0:g.name)||(null==g?void 0:g.email):void 0,canViewTeam:d(l.bpW.LeadsViewAll),canConfigure:d(l.bpW.PipelineConfigure)},"".concat(r.data.user.id,":").concat(c._id,":").concat(h,":").concat(u))]}):(0,a.jsx)(o.L,{children:(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:s("commercial.unavailable")})}):(0,a.jsx)(o.L,{children:(0,a.jsx)(n.E,{className:"h-72 rounded-2xl"})})}function ey(e){var t,s,i,l,c;let{effectiveUserId:m,...u}=e,{t:x}=(0,j.o)(),p=k.id.useUtils(),[h,g]=(0,r.useState)(!1),[f,b]=(0,r.useState)("current"),[v,N]=(0,r.useState)(!1),[w,y]=(0,r.useState)(!1),[I,C]=(0,r.useState)(!1),A={workspaceId:u.workspaceId,...u.userId?{userId:u.userId}:{}},S=k.id.sellerCopilot.getCommercialHistoricalReview.useQuery(A,{retry:!1,staleTime:0,placeholderData:void 0,refetchOnMount:"always",refetchInterval:6e4}),U=k.id.sellerCopilot.getCommercialAccess.useQuery(A,{retry:!1,staleTime:0,placeholderData:void 0,refetchOnMount:"always",refetchInterval:6e4}),E=!!(U.data&&(U.data.workspaceId!==u.workspaceId||U.data.sellerUserId!==m)),_=!!(U.data&&!U.isError&&!E&&U.isFetchedAfterMount&&!U.isFetching&&!U.isPending),z=async()=>{b("current"),N(!0),y(!1),C(!1);try{var e;let t=await U.refetch(),s=!t.isError&&(null==(e=t.data)?void 0:e.enabled)&&t.data.workspaceId===u.workspaceId&&t.data.sellerUserId===m;y(!!s),C(!s)}catch(e){C(!0)}finally{N(!1)}},D=(0,a.jsxs)("div",{className:"mb-6 space-y-3",children:[(0,a.jsx)("div",{role:"group","aria-label":x("commercial.n
1avigation.label"),className:"flex flex-wrap gap-2 border-b",children:["current","historical"].map(e=>(0,a.jsx)("button",{type:"button","aria-pressed":f===e,disabled:"current"===e&&v,onClick:()=>"current"===e?void z():b("historical"),className:"min-h-11 cursor-pointer rounded-t-lg border-b-2 px-4 py-3 text-base font-medium transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600 disabled:cursor-wait disabled:opacity-60 ".concat(f===e?"border-violet-600 bg-violet-50 text-violet-900 dark:bg-violet-950/40 dark:text-violet-200":"border-transparent text-muted-foreground hover:bg-muted"),children:x("commercial.navigation.".concat(e))},e))}),(0,a.jsx)("p",{className:"text-sm leading-6 text-muted-foreground",children:x("commercial.navigation.".concat(f,"Hint"))})]}),L=(0,a.jsx)(eh,{workspaceId:u.workspaceId,userId:u.userId,data:_?U.data:void 0,isError:U.isError||E,onRetry:()=>void U.refetch(),onBeforeChange:async()=>{g(!0),y(!1),await p.sellerCopilot.getCommercialHistoricalReview.cancel(A)},onAfterChange:async()=>{await Promise.all([U.refetch(),S.refetch()]),g(!1)}}),T=S.data&&(S.data.workspaceId!==u.workspaceId||S.data.sellerUserId!==m),R=S.isFetchedAfterMount&&!S.isFetching&&void 0!==S.data&&!S.isError&&!T;if("current"===f&&!h){if(v||!_&&!U.isError&&!E)return(0,a.jsx)(o.L,{header:D,children:(0,a.jsx)(n.E,{className:"h-72 rounded-2xl"})});if(U.isError||E||I)return(0,a.jsxs)(o.L,{header:D,children:[L,(0,a.jsx)(d.E,{onRetry:()=>void z()})]});if(_&&!(null==(l=U.data)?void 0:l.enabled))return(0,a.jsxs)(o.L,{header:D,children:[L,(0,a.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:x("commercial.unavailable")})]});if(_&&(null==(c=U.data)?void 0:c.enabled)&&(w||R))return(0,r.createElement)(ek,{...u,effectiveUserId:m,navigation:D,key:"".concat(U.data.hasPersonalLine,":").concat(U.data.consent.enabled,":").concat(U.data.consent.version,":").concat(U.data.consent.grantedAt)});if(!S.isError&&!T)return(0,a.jsxs)(o.L,{header:D,children:[L,(0,a.jsx)(n.E,{className:"h-72 rounded-2xl"})]})}if(S.isError||T)return(0,a.jsxs)(o.L,{header:D,children:[L,(0,a.jsx)("p",{className:"mb-4 text-sm leading-6 text-muted-foreground",children:x("commercial.navigation.historyUnavailable")}),(null==(s=S.error)||null==(t=s.data)?void 0:t.code)==="FORBIDDEN"?(0,a.jsx)("p",{role:"status",className:"rounded-xl border p-5 text-sm leading-6 text-muted-foreground",children:x("commercial.historicalRestricted")}):(0,a.jsx)(d.E,{onRetry:()=>S.refetch()})]});let F=null===S.data&&(!S.isFetchedAfterMount||S.isFetching);return h||S.isPending||void 0===S.data||F||v?(0,a.jsxs)(o.L,{header:D,children:[L,(0,a.jsx)(n.E,{className:"h-72 rounded-2xl"})]}):S.data?(0,a.jsxs)(o.L,{className:"min-w-0",header:D,children:[L,(null==(i=U.data)?void 0:i.enabled)&&U.data.hasPersonalLine&&U.data.consent.enabled&&_&&R&&!E?(0,a.jsx)(ep,{data:S.data,impersonatedName:u.impersonatedName},S.data.id):(0,a.jsx)("p",{role:"status",className:"rounded-xl border p-5 text-sm leading-6 text-muted-foreground",children:x("commercial.historicalRestricted")})]}):(0,a.jsxs)(o.L,{header:D,children:[L,(0,a.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:x("commercial.navigation.historyEmpty")})]})}function ek(e){var t,s,i,u,x,p;let{workspaceId:h,userId:g,impersonatedName:f,canViewTeam:b,canConfigure:v,navigation:N,effectiveUserId:w}=e,{t:y}=(0,j.o)(),I=k.id.useUtils(),[C,S]=(0,r.useState)(),[U,E]=(0,r.useState)(!1),_={workspaceId:h,...g?{userId:g}:{}},z=k.id.workspace.getPermissions.useQuery(_,{enabled:!!g,retry:!1,staleTime:0,refetchInterval:6e4}),D=e=>{var t,s;return!z.isError&&null!=(s=null==(t=z.data)?void 0:t.permissions.includes(e))&&s},L=g?D(l.bpW.LeadsViewAll):b,T=g?D(l.bpW.PipelineConfigure):v,R=k.id.sellerCopilot.getCommercialMine.useQuery(_,{retry:!1,staleTime:0,placeholderData:void 0,refetchOnMount:"always",refetchInterval:e=>{var t;return null!=(t=e.state.data)&&!!t.enabled&&6e4}}),F=k.id.pipeline.listPipelines.useQuery(_,{enabled:T&&U,staleTime:0}),M=null==(t=R.data)?void 0:t.opportunities.find(e=>e.leadId===C),P=(0,ed.l)(M);if(["FORBIDDEN","UNAUTHORIZED"].includes(null!=(x=null==(i=R.error)||null==(s=i.data)?void 0:s.code)?x:"")||(null==(u=R.data)?void 0:u.enabled)===!1)return(0,a.jsx)(o.L,{header:N,children:(0,a.jsx)("p",{className:"rounded-xl border p-6 text-sm text-muted-foreground",children:y("commercial.unavailable")})});if(R.isError)return(0,a.jsx)(o.L,{header:N,children:(0,a.jsx)(d.E,{onRetry:()=>R.refetch()})});if(R.isPending||!R.isFetchedAfterMount||R.isFetching)return(0,a.jsx)(o.L,{header:N,children:(0,a.jsx)(n.E,{className:"h-72 rounded-2xl"})});let H=R.data;return H?(0,a.jsxs)(o.L,{className:"min-w-0",header:N,children:[(0,a.jsx)(m.D,{workspaceId:h,userId:g,active:"commercial"}),f?(0,a.jsx)("p",{role:"status",className:"mb-5 rounded-lg border border-amber-300/60 bg-amber-50 px-4 py-3 text-sm text-amber-950 dar
1k:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100",children:y("commercial.impersonationActive",{name:f})}):null,(0,a.jsx)(Y,{workspaceId:h,effectiveUserId:w,userId:g}),H.pipeline?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(X,{workspaceId:h,userId:g,data:H,canViewTeam:L,canConfigure:T,asOf:R.dataUpdatedAt,isRefreshing:R.isFetching,refreshError:R.isError,onRefresh:()=>void I.sellerCopilot.invalidate(),onEdit:()=>E(!0),onSelect:e=>S(e.leadId)}),P?(0,a.jsx)(en,{open:!!M,workspaceId:h,userId:g,opportunity:P,pipeline:H.pipeline,onClose:()=>S(void 0)},"".concat(P.leadId,":").concat(P.currentStepUpdatedAt)):null,T&&U&&F.isError?(0,a.jsx)(d.E,{onRetry:()=>F.refetch()}):null,T?(0,a.jsx)(eb.A,{open:U,onOpenChange:E,workspaceId:h,userId:g,onPipelinesChanged:()=>void I.sellerCopilot.invalidate(),pipelines:(null!=(p=F.data)?p:[]).filter(e=>{var t;return e._id===(null==(t=H.pipeline)?void 0:t.id)})}):null]}):(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsx)(c.A,{title:y("commercial.title"),description:y("commercial.subtitle")}),T?(0,a.jsx)(A,{workspaceId:h,userId:g}):(0,a.jsx)("div",{className:"rounded-2xl border p-6 text-sm text-muted-foreground",children:y("commercial.waitingAdmin")})]})]}):null}},94728:(e,t,s)=>{"use strict";s.d(t,{I:()=>n});var a=s(66352);s(95132);var r=s(47541),i=s(78134),l=s(18109);function n(e){let{text:t,side:s="top",className:n,label:o}=e;return(0,a.jsxs)(i.m_,{children:[(0,a.jsx)(i.k$,{asChild:!0,children:(0,a.jsx)("span",{tabIndex:0,"aria-label":null!=o?o:t,className:(0,l.cn)("inline-flex cursor-help ml-0.5",n),children:(0,a.jsx)(r.A,{className:"h-3 w-3 text-muted-foreground"})})}),(0,a.jsx)(i.ZI,{side:s,className:"max-w-[260px]",children:t})]})}}},e=>{e.O(0,[9854,2655,636,6593,8792],()=>e(e.s=77956)),_N_E=e.O()}]);
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.