PageSourceSearch

https://app.storika.ai/_next/static/chunks/4003-9481ad91e18ef359.js?dpl=dpl_Eq3u4Z7V3psEbxcNjBbvsR1vVwdK

js storika.ai collected 2026-09-24 12:07:28 UTC 111,591 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4003],{14613:(e,n,t)=>{function a(e){var n,t;return null!=(t=null==e||null==(n=e.connectEmail)?void 0:n.enabled)&&t}function r(e){var n,t;return null!=(t=null==e||null==(n=e.customDomainSending)?void 0:n.enabled)&&t}t.d(n,{D:()=>r,Q:()=>a})},17700:(e,n,t)=>{t.d(n,{A:()=>s});var a=t(45855);class r extends a.Ay{async getOrganizationGmailSenderAccounts(){return this.httpRequired.get("/gmail-accounts")}async getConnectUrl(e){let n=e?"?return_url=".concat(encodeURIComponent(e)):"";return this.httpRequired.get("/gmail-accounts/connect".concat(n))}async disconnectGmailSenderAccount(e){return this.httpRequired.delete("/gmail-accounts/".concat(e))}async undoGmailSenderAccount(e){return this.httpRequired.post("/gmail-accounts/".concat(e,"/undo"))}async getPendingDisconnect(){return this.httpRequired.get("/gmail-accounts/pending-disconnect")}async getCampaignsUsingSenderAccount(e){return this.httpRequired.get("/gmail-accounts/".concat(e,"/campaigns"))}async sendTestEmail(e,n){return this.httpRequired.post("/gmail-accounts/".concat(e,"/test"),{toEmail:n})}}let s=new r},25347:(e,n,t)=>{t.d(n,{A:()=>o,D:()=>l});var a=t(17700),r=t(45855);class s extends r.Ay{static getInstance(){return s.instance||(s.instance=new s),s.instance}getSettings(e){return this.http.get("/campaigns/".concat(e,"/gmail-settings")).then(e=>null!=e?e:null)}
1createSettings(e,n){return this.httpRequired.post("/campaigns/".concat(e,"/gmail-settings"),n)}patchSettings(e,n,t){return this.httpRequired.patch("/campaigns/".concat(e,"/gmail-settings/").concat(n),t)}async deleteSettings(e,n){await this.http.delete("/campaigns/".concat(e,"/gmail-settings/").concat(n))}sendEmail(e,n){return this.httpRequired.post("/campaigns/".concat(e,"/gmail/send"),n)}async getConversations(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=new URLSearchParams;n.page&&t.set("page",n.page.toString()),n.limit&&t.set("limit",n.limit.toString());let a=t.toString();return this.httpRequired.get("/campaigns/".concat(e,"/gmail-conversations").concat(a?"?".concat(a):""))}getMessages(e,n){return this.httpRequired.get("/campaigns/".concat(e,"/gmail-messages?campaignResultId=").concat(n))}createManualDraft(e,n){return this.httpRequired.post("/campaigns/".concat(e,"/gmail-messages/compose"),n)}ensureDraft(e,n){return this.httpRequired.post("/campaigns/".concat(e,"/results/").concat(n,"/agent-job/ensure-email-draft"))}sendDraftMessage(e,n,t){return this.httpRequired.post("/campaigns/".concat(e,"/gmail-messages/").concat(n,"/send"),void 0!==t?{conceptApproved:t}:void 0)}updateMessage(e,n,t){return this.httpRequired.patch("/campaigns/".concat(e,"/gmail-messages/").concat(n),t)}async deleteDraftMessage(e,n){await this.http.delete("/campaigns/".concat(e,"/gmail-messages/").concat(n))}downloadAttachment(e,n,t){return this.requestBlob("GET","/campaigns/".concat(e,"/gmail-messages/").concat(encodeURIComponent(n),"/attachments/").concat(encodeURIComponent(t)))}constructor(){super()}}let i=s.getInstance(),l={senderAccounts:["gmail-sender-accounts"],pendingDisconnect:["gmail-pending-disconnect"],campaignSettings:e=>["campaign-gmail-sender-settings",e],conversations:(e,n)=>["gmail-conversations",e,n],messages:(e,n)=>["gmail-messages",e,n]},o={getOrganizationGmailSenderAccounts:()=>({queryKey:l.senderAccounts,queryFn:()=>a.A.getOrganizationGmailSenderAccounts()}),getPendingDisconnect:()=>({queryKey:l.pendingDisconnect,queryFn:()=>a.A.getPendingDisconnect()}),getCampaignGmailSettings:e=>({queryKey:l.campaignSettings(e),queryFn:()=>i.getSettings(e)}),getGmailMessages:(e,n)=>({queryKey:l.messages(e,n),queryFn:()=>i.getMessages(e,n)})}},25812:(e,n,t)=>{t.d(n,{ZD:()=>o});var a=t(27736),r=t(45855);class s extends r.Ay{async fetchConfig(){return this.httpRequired.get("/organizations/me/email-sender")}async upsert(e){return this.httpRequired.put("/organizations/me/email-sender",e)}async remove(){return this.httpRequired.delete("/organizations/me/email-sender")}async sendTestEmail(e){return this.httpRequired.post("/organizations/me/email-sender/test",{to:e})}}let i=new s,l=["organizations","me","email-sender"];function o(){return(0,a.I)({queryKey:l,queryFn:()=>i.fetchConfig(),staleTime:3e4,retry:!1})}},35664:(e,n,t)=>{t.d(n,{M4:()=>i,Mi:()=>a,sQ:()=>s});let a="connect",r={instagram:"Instagram",tiktok:"TikTok"};function s(e){return"/chat?".concat(a,"=").concat(e)}function i(e){return e&&Object.hasOwn(r,e)?"Connect my ".concat(r[e]," account"):null}},38205:(e,n,t)=>{t.d(n,{O2:()=>u,Sc:()=>c,cD:()=>m,of:()=>d,sK:()=>o});var a=t(27736),r=t(81562),s=t(4869),i=t(25347),l=t(17700);function o(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{enabled:!0};return(0,a.I)({...i.A.getOrganizationGmailSenderAccounts(),...e})}function c(){return(0,r.n)({mutationFn:e=>l.A.getConnectUrl(e)})}function d(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{enabled:!0};return(0,a.I)({...i.A.getPendingDisconnect(),...e})}function u(){let e=(0,s.jE)();return(0,r.n)({mutationFn:e=>l.A.disconnectGmailSenderAccount(e),onSuccess:()=>{e.invalidateQueries({queryKey:i.D.senderAccounts}),e.invalidateQueries({queryKey:i.D.pendingDisconnect})}})}function m(){let e=(0,s.jE)();return(0,r.n)({mutationFn:e=>l.A.undoGmailSenderAccount(e),onSuccess:()=>{e.invalidateQueries({queryKey:i.D.senderAccounts}),e.invalidateQueries({queryKey:i.D.pendingDisconnect})}})}},40973:(e,n,t)=>{t.d(n,{A:()=>i});var a=t(45855),r=t(65152);class s extends a.Ay{prepare(e,n){return this.httpRequired.post("/campaigns/".concat(e.campaignId,"/human-gates"),{...n,threadId:e.threadId})}async list(e,n){let{campaignId:t,threadId:a}=e,s=await this.httpRequired.get("/campaigns/".concat(t,"/human-gates").concat((0,r.Z)({threadId:a,before:n})));if(!Array.isArray(s))throw Error("Approval details are unavailable. Try again.");return s}read(e,n){let{campaignId:t,threadId:a}=e;return this.httpRequired.get("/campaigns/".concat(t,"/human-gates/").concat(n).concat((0,r.Z)({threadId:a})))}reviewLaterOutreach(e,n){return this.httpRequired.post("/campaigns/".concat(e.campaignId,"/human-gates/review-later-outreach"),{...n,threadId:e.threadId})}sendLaterOutreach(e,n,t){return this.httpRequired.post("/campaigns/".concat(e.campaignId,"/human-gates/send-later-outreach"),{...n,threadId:e.threadId,reviewedPayloadHash:t})}decide(e,n,t){return this.httpRequired.post("/campaigns/".concat(e.campaignId,"/human-gates/").concat(n.requestId,"/decision"),{threadId:e.threadId,reviewedPayloadHash:n.payloadHash,decision:"approved"===t?"approve":"decline"})}regenerate(e,n,t){return this.httpRequired.post("/campaigns/".concat(e.campaignId,"/human-gates/").concat(n.requestId,"/regenerate"),{...t,threadId:e.threadId,reviewedPayloadHash:n.payloadHash})}resendContract(e,n){return this.httpRequired.post("/campaigns/".concat(e.campaignId,"/human-gates/").concat(n.requestId,"/resend-contract"),{threadId:e.threadId,reviewedPayloadHash:n.payloadHash})}}let i=new s},49086:(e,n,t)=>{t.d(n,{DY:()=>l,eg:()=>s,gP:()=>r,oB:()=>o});var a=t(59081);function r(e){if((null==e?void 0:e.amountMinor)==null||!Number.isFinite(e.amountMinor)||!e.currency)return"Amount unavailable";let n=(0,a.Au)({amount:String((0,a.Di)(e.amountMinor,e.currency)),currency:e.currency},2);return(0,a.H0)(n,e.currency)}let s="max-md:min-h-11 max-md:min-w-11",i={rail:256,railCollapsed:56,gap:24,transcriptMin:640,details:340},l={expanded:i.rail+i.gap+i.transcriptMin+i.gap+i.details,collapsed:i.railCollapsed+i.gap+i.transcriptMin+i.gap+i.details};function o(e){let{fitsExpanded:n,fitsCollapsed:t,detailsOpen:a}=e,r=t?"docked":"drawer";return{rail:a&&"docked"===r&&!n?"collapsed":"expanded",details:r}}},55811:(e,n,t)=>{t.d(n,{FG:()=>r,J8:()=>a,Ls:()=>c,TD:()=>d,Zb:()=>s,eq:()=>i,iz:()=>o,uv:()=>u,wn:()=>l});let a="storika:tiktok-shop-connect",r="storika-tiktok-shop-connect",s="/tiktok-shop-connected",i="storika-tiktok-shop-oauth";function l(e){return"".concat(i,"-").concat(e)}let o="tiktok_shop_connected",c="tiktok_shop_error",d="tiktok_shop_error_code",u="tiktok_shop_move_nonce"},60875:(e,n,t)=>{t.d(n,{MD:()=>s,mw:()=>r});var a=t(10141);function r(e){let n=Object.values(a.TiktokShopConnectErrorCode).find(n=>n===e);return n?function(e){switch(e){case a.TiktokShopConnectErrorCode.SESSION_EXPIRED:return"That connection attempt expired. Please try connecting again.";case a.TiktokShopConnectErrorCode.ACCESS_DENIED:return"TikTok Shop authorization was declined. You can try connecting again.";case a.TiktokShopConnectErrorCode.TEMPORARILY_UNAVAILABLE:return"TikTok Shop is temporarily unavailable. Please try again in a few minutes.";case a.TiktokShopConnectErrorCode.ALREADY_LINKED:return"That shop is already linked to another organization. Disconnect it there first.";case a.TiktokShopConnectErrorCode.MOVE_CONFIRMATION_REQUIRED:return"This shop is connected to another brand in your organization. Try connecting again.";case a.TiktokShopConnectErrorCode.MULTIPLE_SHOPS:return"That TikTok account manages more than one shop. Storika can link only one - contact support to pick the shop.";case a.TiktokShopConnectErrorCode.NO_SHOPS:return"No shop was found on that TikTok account. Open TikTok Seller Center, then try again.";case a.TiktokShopConnectErrorCode.UNEXPECTED:return"TikTok Shop could not complete the connection. Please try again.";default:return e}}(n):"Could not connect TikTok Shop. Please try again."}function s(e){let n=Object.values(a.TiktokShopConnectErrorCode).find(n=>n===e),t=null!=n?n:a.TiktokShopConnectErrorCode.UNEXPECTED;return"/tiktok-shop-connected?tiktok_shop_error=1&tiktok_shop_error_code=".concat(t)}},61899:(e,n,t)=>{t.d(n,{dx:()=>nR,BS:()=>nS,T_:()=>nI});var a=t(54568),r=t(7620),s=t(52182),i=t(379),l=t(24560),o=t(73673),c=t(62178);let d=[{id:"system",label:"System"},{id:"light",label:"Light"},{id:"dark",label:"Dark"}];function u(){let{theme:e,setTheme:n}=(0,l.D)(),[t,s]=(0,r.useState)(null),i="light"===e||"dark"===e?e:"system";return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(o.Y4,{"aria-label":"Appearance",size:"sm",selectedKey:i,onSelectionChange:e=>{if(("system"===e||"light"===e||"dark"===e)&&e!==i){try{window.localStorage.setItem(c.V,e)}catch(e){s("Couldn't save your appearance choice on this device. The previous choice is kept.");return}s(null),n(e)}},children:d.map(e=>(0,a.jsx)(o.Y4.Item,{id:e.id,children:e.label},e.id))}),t?(0,a.jsx)("p",{role:"alert",className:"text-xs text-danger",children:t}):null]})}var m=t(19512),h=t(43298),p=t(10141),g=t(91618),f=t(54028);function x(e){var n;let{me:t}=e,s=(0,i.nN)(),[l,o]=(0,r.useState)(null),c=s.isPending,d=null!=(n=t.numberDis
1playFormat)?n:p.NumberDisplayFormat.FULL,u=async e=>{if(null!==e&&e!==d)try{o(null),await s.mutateAsync(e),(0,f.u4)(p.AnalyticsEventName.SETTINGS_PROFILE_SAVED)}catch(e){var n;o(null!=(n=(0,g.VR)(e))?n:"Couldn't update number display. Try again.")}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(m.l6,{"aria-label":"Large numbers",value:d,onChange:u,isDisabled:c,variant:"secondary",className:"w-full sm:w-64",children:[(0,a.jsxs)(m.l6.Trigger,{children:[(0,a.jsx)(m.l6.Value,{}),(0,a.jsx)(m.l6.Indicator,{})]}),(0,a.jsx)(m.l6.Popover,{children:(0,a.jsxs)(h.qF,{children:[(0,a.jsxs)(h.qF.Item,{id:p.NumberDisplayFormat.FULL,textValue:"Full numbers (4,231)",children:["Full numbers (4,231)",(0,a.jsx)(h.qF.ItemIndicator,{})]}),(0,a.jsxs)(h.qF.Item,{id:p.NumberDisplayFormat.COMPACT,textValue:"Compact (4.2K)",children:["Compact (4.2K)",(0,a.jsx)(h.qF.ItemIndicator,{})]})]})})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground sm:text-right",children:"How large counts (followers, views, likes, reach) are shown for you across the app. Currency and token amounts are not affected."}),l?(0,a.jsx)("p",{role:"alert",className:"text-xs text-danger",children:l}):null]})}var v=t(93639),y=t(86630),b=t(75539);let j=p.USER_AVATAR_ALLOWED_MIME_TYPES.join(","),w=p.USER_AVATAR_MAX_BYTES/1048576;function N(e){let{me:n,onPendingChange:t}=e,s=(0,i.Sn)("avatar"),l=(0,r.useRef)(null),o=(0,r.useRef)(null),[c,d]=(0,r.useState)(null),[u,m]=(0,r.useState)(null);(0,r.useEffect)(()=>()=>{c&&URL.revokeObjectURL(c)},[c]);let h=(0,r.useCallback)(()=>{var e;return null==(e=o.current)?void 0:e.abort()},[]),x=s.isPending;(0,r.useEffect)(()=>{t(x,h)},[x,t,h]);let N=()=>{var e;return null==(e=l.current)?void 0:e.click()},k=()=>{l.current&&(l.current.value="")},C=null!=c?c:n.profilePicUrl||void 0,E=(0,b.N)(n).charAt(0).toUpperCase();return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsxs)(v.eu,{size:"lg",children:[(0,a.jsx)(v.eu.Image,{src:C,alt:""}),(0,a.jsx)(v.eu.Fallback,{children:E})]}),(0,a.jsx)("input",{ref:l,type:"file",accept:j,className:"sr-only","aria-label":"Choose a profile photo",tabIndex:-1,onChange:e=>{var n;let t=null==(n=e.target.files)?void 0:n[0];if(!t)return;if(!p.USER_AVATAR_ALLOWED_MIME_TYPES.includes(t.type)){m("Choose a PNG, JPEG or WebP image."),k();return}if(t.size>p.USER_AVATAR_MAX_BYTES){m("Choose an image under ".concat(w," MB.")),k();return}m(null),d(URL.createObjectURL(t));let a=new AbortController;o.current=a,s.mutate({file:t,signal:a.signal},{onSettled:()=>{o.current===a&&(o.current=null)},onSuccess:()=>{d(null),k(),(0,f.u4)(p.AnalyticsEventName.SETTINGS_PROFILE_SAVED)},onError:e=>{var n;d(null),k(),a.signal.aborted||m((0,g.PF)(e)?"Your profile changed in another tab. Choose the photo again.":null!=(n=(0,g.VR)(e))?n:"Couldn't save that photo. Choose another.")}})}}),(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",onPress:N,isPending:x,children:x?"Uploading":"Change photo"})]}),u?(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("p",{role:"alert",className:"text-xs text-danger",children:u}),(0,a.jsx)(y.$n,{variant:"ghost",size:"sm",onPress:N,children:"Retry"})]}):null]})}var k=t(78876),C=t(51961),E=t(65101),S=t(27605),R=t(77074);let I="Enter a name.";function A(e){var n;let{me:t,onDirtyChange:s}=e,l=(0,i.Sn)("name"),o=(0,r.useRef)(!1),c=null!=(n=t.name)?n:"",[d,u]=(0,r.useState)(c),[m,h]=(0,r.useState)(c),[x,v]=(0,r.useState)(null),[b,j]=(0,r.useState)(!1);c!==d&&(u(c),m===d&&h(c));let w=(0,r.useCallback)(()=>{h(c),v(null),j(!1)},[c]),N=m.trim()!==c;(0,r.useEffect)(()=>{s(N,w)},[N,s,w]);let A=()=>{if(l.isPending||o.current)return;let e=m.trim();if(!e)return void v(I);if(e===c){h(e),v(null),j(!1);return}o.current=!0,l.mutate({name:e},{onSettled:()=>{o.current=!1},onSuccess:()=>{h(e),v(null),j(!1),(0,f.u4)(p.AnalyticsEventName.SETTINGS_PROFILE_SAVED)},onError:e=>{var n;let t=(0,g.PF)(e);j(t),v(t?"Your profile changed in another tab. Retry to save this name.":null!=(n=(0,g.VR)(e))?n:"Couldn't save your name. Retry.")}})};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(k.A_,{value:m,onChange:e=>{h(e),x&&(v(null),j(!1))},isInvalid:null!==x,isDisabled:l.isPending,className:"w-full sm:w-64",children:[(0,a.jsx)(C.JU,{className:"sr-only",children:"Name"}),(0,a.jsx)(E.pd,{maxLength:100,onKeyDown:e=>{e.nativeEvent.isComposing||("Enter"===e.key?(e.preventDefault(),A()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),w()))},onBlur:e=>{if(!N)return;if(!m.trim())return void v(I);let n=e.relatedTarget,t=e.currentTarget.closest('[role="dialog"]');!(n instanceof Element)||t&&!t.contains(n)||n.closest("[".concat(R.iv,"]"))||A()}}),(0,a.jsx)(S.bg,{children:x})]}),x&&b?(0,a.jsx)(y.$n,{variant:"ghost",size:"sm",onPress:A,children:"Retry"}):null]})}function T(e){let{heading:n,message:t,onRetry:s,retryAfterSeconds:i,requestId:l,isRetrying:o=!1,headingId:c}=e,[d,u]=(0,r.useState)(null!=i?i:0),[m,h]=(0,r.useState)(!1);(0,r.useEffect)(()=>
1{if(u(null!=i?i:0),!i)return;let e=setInterval(()=>{u(n=>(n<=1&&clearInterval(e),Math.max(0,n-1)))},1e3);return()=>clearInterval(e)},[i]);let p=async()=>{if(l)try{await navigator.clipboard.writeText(l),h(!0)}catch(e){h(!1)}};return(0,a.jsxs)("section",{"aria-labelledby":c,className:"flex flex-col gap-4 rounded-lg border border-border bg-surface p-4",children:[(0,a.jsx)("h2",{id:c,tabIndex:-1,className:"text-base font-medium text-foreground outline-none",children:n}),(0,a.jsx)("p",{role:"alert",className:"text-sm text-muted-foreground",children:t}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",onPress:s,isDisabled:d>0||o,isPending:o,children:"Retry"}),d>0?(0,a.jsxs)("span",{role:"status",className:"text-xs text-muted-foreground",children:["Retry in ",d,"s"]}):null,l?(0,a.jsx)(y.$n,{variant:"ghost",size:"sm",onPress:p,children:m?"Copied":"Copy request id"}):null]})]})}function P(e){let{headingId:n,children:t}=e;return(0,a.jsx)("h2",{id:n,tabIndex:-1,
1className:"text-base font-medium text-foreground outline-none",children:t})}function D(e){let{label:n,children:t}=e;return(0,a.jsxs)("div",{className:"flex flex-col gap-2 border-b border-border py-4 sm:flex-row sm:items-start sm:justify-between sm:gap-6",children:[(0,a.jsx)("span",{className:"text-sm text-muted-foreground sm:w-40 sm:shrink-0 sm:pt-2",children:n}),(0,a.jsx)("div",{className:"flex min-w-0 flex-1 flex-col items-start gap-2 sm:items-end",children:t})]})}function L(e){let{me:n,heading:t,headingId:s,onDirtyChange:i}=e,[l,o]=(0,r.useState)(!1),[c,d]=(0,r.useState)(!1),m=(0,r.useRef)({name:()=>{},avatar:()=>{}}),h=(0,r.useCallback)((e,n)=>{m.current.name=n,o(e)},[]),p=(0,r.useCallback)((e,n)=>{m.current.avatar=n,d(e)},[]),g=l||c;return(0,r.useEffect)(()=>{null==i||i(g,()=>{m.current.name(),m.current.avatar()})},[g,i]),(0,r.useEffect)(()=>()=>null==i?void 0:i(!1),[i]),(0,a.jsxs)("section",{"aria-labelledby":s,className:"flex flex-col gap-2",children:[(0,a.jsx)(P,{headingId:s,children:t}),(0,a.jsx)(D,{label:"Photo",children:(0,a.jsx)(N,{me:n,onPendingChange:p})}),(0,a.jsx)(D,{label:"Name",children:(0,a.jsx)(A,{me:n,onDirtyChange:h})}),(0,a.jsx)(D,{label:"Email",children:(0,a.jsx)("span",{className:"text-sm text-foreground sm:pt-2",children:n.email})}),(0,a.jsx)(D,{label:"Appearance",children:(0,a.jsx)(u,{})}),(0,a.jsx)(D,{label:"Large numbers",children:(0,a.jsx)(x,{me:n})})]})}var q=t(44603),_=t(4869),F=t(27736),U=t(45855),O=t(92228);let M=O.ai().int().nonnegative(),z=O.Yj().datetime(),K=O.Ik({account:M,memberships:M,organizations:M,brands:M,campaigns:M,creators:M,agreements:M,receipts:M,outreach_messages:M,proposal_messages:M}),B=O.Ik({counts:K,generatedAt:z}),G=O.Ik({actionKey:O.eu("account_export"),organizationId:O.Yj().min(1),units:O.eu(1),tokenAmount:M,displayUsd:O.ai().finite().nonnegative(),chargeRequired:O.zM(),quotedAt:z}),Y=O.Ik({downloadUrl:O.Yj().regex(/^\/users\/me\/export-jobs\/\d+\/bytes\?grant=[a-f0-9-]{36}$/),expiresAt:z,filename:O.k5(["storika-export.json","storika-export.csv","storika-export.md"])}),$=O.Ik({id:O.ai().int().positive(),attemptId:O.Yj().uuid(),organizationId:O.Yj().min(1),format:O.k5(["json","csv","md"]),status:O.k5(["pending","processing","ready","failed","expired"]),stage:O.k5(["queued","reading","serializing","uploading","verifying","ready"]),recordsProcessed:M,counts:K.nullable(),createdAt:z,completedAt:z.nullable(),archiveExpiresAt:z.nullable(),nextExportAt:z.nullable(),reissuesRemaining:M.max(3),downloadIssued:O.zM(),linkExpiredOrFailed:O.zM(),archiveAvailable:O.zM(),platformFailureCredited:O.zM(),currentGrant:Y.nullable(),error:O.Ik({code:O.Yj(),message:O.Yj(),retryable:O.zM()}).nullable()});function V(e,n){let t=e.safeParse(n);if(!t.success)throw Error("The export response is invalid. Try again.");return t.data}class H extends U.Ay{async metadata(){return V(B,await this.httpRequired.get("/users/me/export-jobs/metadata"))}async quote(){return V(G,await this.httpRequired.get("/users/me/export-jobs/quote"))}async latest(){return V(O.Ik({job:$.nullable(),lastSettledJob:$.nullable()}),await this.httpRequired.get("/users/me/export-jobs/latest"))}async job(e){return V($,await this.httpRequired.get("/users/me/export-jobs/".concat(e)))}async start(e){return V($,await this.httpRequired.post("/users/me/export-jobs",e))}async issue(e,n){return V(Y,await this.httpRequired.get("/users/me/export-jobs/".concat(e,"/download"),{headers:{"Idempotency-Key":n}}))}download(e){if(!/^\/users\/me\/export-jobs\/\d+\/bytes\?grant=[a-f0-9-]{36}$/.test(e.downloadUrl))throw Error("The download link is invalid.");return this.requestBlob("GET",e.downloadUrl)}async saveArchive(e){let n=await this.download(e),t=URL.createObjectURL(n);try{let n=document.createElement("a");n.href=t,n.download=e.filename,n.click()}finally{URL.revokeObjectURL(t)}}}let Q=new H;var W=t(8972),X=t(96006),J=t(97817),Z=t(59081);let ee="DELETE";function en(e,n,t){return void 0===e?"We could not count ".concat(t):"".concat((0,Z.qq)(e)," ").concat(1===e?n:t)}function et(e){let{isLoading:n,isError:t,impact:r}=e;if(n)return(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Checking what deleti
1on affects."});if(t)return(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"We could not load the full impact."});if(!r)return null;let{workspacesClosing:s,workspacesPreserved:i,ownershipTransferRequired:l,campaignsInClosingWorkspaces:o,contactsInClosingWorkspaces:c}=r,d=(null!=s?s:0)>0,u=(null!=i?i:0)>0,m=(null!=l?l:0)>0,h=0===s&&0===i&&0===l;return(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[d?(0,a.jsxs)("p",{className:"text-sm text-foreground",children:["Permanently closes"," ",en(s,"workspace","workspaces")," ","where you are the only member, including"," ",en(o,"campaign","campaigns")," ","and"," ",en(c,"contact","contacts"),"."]}):null,u?(0,a.jsxs)("p",{className:"text-sm text-muted-foreground",children:[en(i,"shared workspace","shared workspaces")," ",1===i?"stays":"stay"," open and their other members are unaffected."]}):null,m?(0,a.jsxs)("p",{className:"text-sm text-danger",children:["Transfer ownership of"," ",en(l,"workspace","workspaces")," ","before deleting."]}):null,d||u||m||!h?null:(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"No workspaces are affected."})]})}function ea(e){let{onConfirmationChange:n}=e,[t,s]=(0,r.useState)(!1),[l,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),[u,m]=(0,r.useState)(null),h=(0,r.useRef)(!1),g=(0,r.useRef)(!1),x=(0,i.ZB)({enabled:t}),v=e=>{s(e),null==n||n(e)},b=()=>{h.current||v(!1)},j=async()=>{if(!h.current&&!g.current&&l===ee){h.current=!0,d(!0),m(null);try{await i.Dv.deleteMyAccount()}catch(e){m(e instanceof Error&&e.message&&"Bad Request"!==e.message?e.message:"Failed to delete account."),h.current=!1,d(!1);return}g.current=!0,(0,f.u4)(p.AnalyticsEventName.SETTINGS_ACCOUNT_DELETED),(0,f.oV)(),await (0,X.signOut)({callbackUrl:"/login"})}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(y.$n,{variant:"danger",isDisabled:c,onPress:()=>{o(""),m(null),v(!0)},children:"Delete account"}),t?(0,a.jsx)(J.Lt,{children:(0,a.jsx)(J.Lt.Backdrop,{isOpen:t,isDismissable:!1,isKeyboardDismissDisabled:c,onOpenChange:e=>{e||b()},children:(0,a.jsx)(J.Lt.Container,{children:(0,a.jsxs)(J.Lt.Dialog,{children:[(0,a.jsx)(J.Lt.Header,{children:(0,a.jsx)(J.Lt.Heading,{children:"Delete account"})}),(0,a.jsxs)(J.Lt.Body,{className:"flex flex-col gap-4",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Deleting your account is permanent. We keep only what the law requires - signed agreements, invoices and payout records. Anything still owed on a live campaign settles first."}),(0,a.jsx)(et,{isLoading:x.isLoading,isError:x.isError,impact:x.data}
1),(0,a.jsxs)(k.A_,{value:l,onChange:o,isDisabled:c,className:"w-full",children:[(0,a.jsx)(C.JU,{children:"Type DELETE to confirm"}),(0,a.jsx)(E.pd,{autoComplete:"off",spellCheck:!1})]}),u?(0,a.jsx)("p",{role:"alert",className:"text-sm text-danger",children:u}):null]}),(0,a.jsxs)(J.Lt.Footer,{children:[(0,a.jsx)(y.$n,{autoFocus:!0,variant:"secondary",isDisabled:c,onPress:b,children:"Keep account"}),(0,a.jsx)(y.$n,{variant:"danger",isDisabled:l!==ee||c,isPending:c,onPress:()=>void j(),children:"Delete account"})]})]})})})}):null]})}let er={json:"JSON",csv:"CSV",md:"Markdown"},es={queued:"Queued",reading:"Reading records",serializing:"Preparing archive",uploading:"Saving archive",verifying:"Verifying archive",ready:"Ready"};function ei(){return(0,a.jsxs)("div",{role:"status","aria-label":"Loading data",className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{"data-testid":"data-skeleton-row",className:"flex flex-col gap-3 py-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,a.jsx)(s.EA,{animationType:"none",className:"h-5 w-24 rounded-md"}),(0,a.jsx)(s.EA,{animationType:"none",className:"h-5 w-3/4 rounded-md"}),(0,a.jsx)(s.EA,{animationType:"none",className:"h-4 w-1/2 roun
1ded-md"})]}),(0,a.jsx)(s.EA,{animationType:"none",className:"h-10 w-20 rounded-full"})]}),(0,a.jsxs)("div",{"data-testid":"data-skeleton-row",className:"flex flex-col gap-3 border-t border-border py-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,a.jsx)(s.EA,{animationType:"none",className:"h-5 w-28 rounded-md"}),(0,a.jsx)(s.EA,{animationType:"none",className:"h-5 w-full rounded-md"}),(0,a.jsx)(s.EA,{animationType:"none",className:"h-5 w-2/3 rounded-md"})]}),(0,a.jsx)(s.EA,{animationType:"none",className:"h-10 w-32 rounded-full"})]})]})}var el=t(27541),eo=t(74567),ec=t(80400),ed=t(3785),eu=t(83020),em=t(25472),eh=t(62346);function ep(e){let{canManage:n,online:t,onClose:s}=e,i=(0,eh.jY)({enabled:n}),[l,o]=(0,r.useState)(!1),[c,d]=(0,r.useState)(null),u=(0,r.useRef)(!0),m=(0,r.useRef)(!1),h=(0,r.useRef)(n&&t);h.current=n&&t,(0,r.useEffect)(()=>(u.current=!0,()=>{u.current=!1}),[]);let x=async()=>{if(!m.current&&h.current){m.current=!0,o(!0),d(null);try{let e,n=!1;try{let e=await new Promise((e,n)=>{i.removePaymentMethod(void 0,{onSuccess:e,onError:n})});n=!0===e.removed}catch(n){e=n}if(!u.current||!h.current)return;if(403===(0,g.Y3)(e))throw e;let t=await i.refetch();if(!u.current||!h.current)return;if(!t.isSuccess||null!==t.data)throw null!=e?e:Error("Card removal is not confirmed");n&&(0,f.u4)(p.AnalyticsEventName.BILLING_CARD_REMOVED,void 0),s()}catch(e){u.current&&d("Card removal could not be confirmed. Check the current card and try again.")}finally{m.current=!1,u.current&&o(!1)}}};return(0,a.jsx)(J.Lt,{children:(0,a.jsx)(J.Lt.Backdrop,{isOpen:!0,isDismissable:!1,isKeyboardDismissDisabled:l,onOpenChange:e=>{e||l||s()},children:(0,a.jsx)(J.Lt.Container,{children:(0,a.jsxs)(J.Lt.Dialog,{children:[(0,a.jsx)(J.Lt.Header,{children:(0,a.jsx)(J.Lt.Heading,{children:"Remove card?"})}),(0,a.jsxs)(J.Lt.Body,{children:[(0,a.jsx)("p",{children:"This removes your current saved card."}),c?(0,a.jsx)("p",{role:"alert",children:c}):null]}),(0,a.jsxs)(J.Lt.Footer,{children:[(0,a.jsx)(y.$n,{autoFocus:!0,variant:"secondary",isDisabled:l,onPress:s,children:"Keep card"}),(0,a.jsx)(y.$n,{variant:"danger",isDisabled:l||!n||!t,isPending:l,onPress:()=>void x(),children:c?"Retry":"Remove card"})]})]})})})})}function eg(e){let{canManage:n,online:t,pending:s,error:i,onUpdate:l,onClose:o}=e,c=(0,eh.jY)({enabled:n}),d=!c.card&&!c.isLoading&&!c.isFetching&&!c.isError,[u,m]=(0,r.useState)(!1),h=(0,r.useRef)(null),p=(0,r.useRef)(null);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(em.aF,{isOpen:!u,onOpenChange:e=>{e||s||u||o()},children:(0,a.jsx)(em.aF.Backdrop,{isExiting:u,hidden:u,inert:u,isDismissable:!s,isKeyboardDismissDisabled:s,children:(0,a.jsx)(em.aF.Container,{size:"sm",children:(0,a.jsxs)(em.aF.Dialog,{children:[(0,a.jsx)(em.aF.Header,{children:(0,a.jsx)(em.aF.Heading,{ref:p,tabIndex:-1,children:d?"Add card":"Update card"})}),(0,a.jsxs)(em.aF.Body,{className:"flex flex-col gap-4",children:[c.isLoading?(0,a.jsx)("p",{role:"status",children:"Loading card"}):c.card?(0,a.jsxs)("p",{className:"text-sm",children:[c.card.brand," •••• ",c.card.last4,(0,a.jsx)("br",{}),"Expires ",String(c.card.expMonth).padStart(2,"0"),"/",c.card.expYear]}):c.isError?null:(0,a.jsx)("p",{children:"No card"}),c.isError||i?(0,a.jsx)("p",{role:"alert",children:null!=i?i:"Current card unavailable. Try again."}):null,(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:d?"Add a payment method in the billing portal. Return here to check the card on file.":"Update your payment method in the billing portal. Return here to check the current card."}),(0,a.jsx)(y.$n,{variant:"ghost",isDisabled:c.isFetching||!t||s,onPress:()=>void c.refetch(),children:"Check current card"}),c.card&&n?(0,a.jsx)(y.$n,{ref:h,variant:"ghost",isDisabled:!t||s||c.isFetching||c.isError,onPress:()=>m(!0),children:"Remove card"}):null]}),(0,a.jsxs)(em.aF.Footer,{children:[(0,a.jsx)(y.$n,{variant:"secondary",isDisabled:s,onPress:o,children:"Done"}),(0,a.jsx)(y.$n,{variant:"primary",isDisabled:!n||!t||s,isPending:s,onPress:l,children:"Open billing portal"})]})]})})})}),u?(0,a.jsx)(ep,{canManage:n,online:t,onClose:()=>{m(!1),requestAnimationFrame(()=>{var e,n;return null==(e=null!=(n=h.current)?n:p.current)?void 0:e.focus()})}}):null]})}var ef=t(89746),ex=t(84622),ev=t(12677),ey=t(49086);function eb(e){let{isOpen:n,kind:t,pending:r,offline:s,error:i,planEndDate:l,onConfirm:o,onDismiss:c,onRefresh:d}=e,u=null!=l&&Number.isFinite(Date.parse(l))?l:null,m=u?"Your plan ends on ".concat((0,Z.sL)(u)," with no further charge."):"Your plan ends at the end of the current period with no further charge.";return(0,a.jsx)(J.Lt,{children:(0,a.jsx)(J.Lt.Backdrop,{isOpen:n,isDismissable:!1,isKeyboardDismissDisabled:r,onOpenChange:e=>{e||r||c()},children:(0,a.jsx)(J.Lt.Container,{children:(0,a.jsxs)(J.Lt.Dialog,{children:[(0,a.jsx)(J.Lt.Header,{children:(0,a.jsx)(J.Lt.Heading,{children:"cancel"===t?"Cancel plan?":"Remove card?"})}),i?(0,a.jsx)(J.Lt.Body,{children:(0,a.jsx)("p",{role:"alert",children:i})}):"cancel"===t?(0,a.jsxs)(J.Lt.Body,{children:[(0,a.jsx)("p",{children:m}),(0,a.jsx)("p",{children:"90 days to change your mind, then hidden, except records we must keep"})]}):null,(0,a.jsxs)(J.Lt.Footer,{children:[(0,a.jsx)(y.$n,{autoFocus:!0,variant:"secondary",isDisabled:r,onPress:c,children:"cancel"===t?"Keep plan":"Keep card"}),(0,a.jsx)(y.$n,{variant:d?"secondary":"danger",isDisabled:r||s,isPending:r,onPress:null!=d?d:o,children:d?"Refresh status":i?"Retry":"cancel"===t?"Confirm cancellation":"Remove card"})]})]})})})})}function ej(e){let{isOpen:n,amountLabel:t,pending:r,offline:s,error:i,onConfirm:l,onCancel:o}=e;return(0,a.jsx)(J.Lt,{children:(0,a.jsx)(J.Lt.Backdrop,{isOpen:n,isDismissable:!1,isKeyboardDismissDisabled:r,onOpenChange:e=>{e||r||o()},children:(0,a.jsx)(J.Lt.Container,{children:(0,a.jsxs)(J.Lt.Dialog,{children:[(0,a.jsx)(J.Lt.Header,{children:(0,a.jsxs)(J.Lt.Heading,{children:["Pay ",t,"?"]})}),(0,a.jsxs)(J.Lt.Body,{children:[(0,a.jsx)("p",{children:"This charges your card on file for the selected past-due invoice."}),i?(0,a.jsx)("p",{role:"alert",className:"mt-2",children:i}):null]}),(0,a.jsxs)(J.Lt.Footer,{children:[(0,a.jsx)(y.$n,{autoFocus:!0,variant:"secondary",isDisabled:r,onPress:o,children:"Cancel"}),(0,a.jsx)(y.$n,{variant:"primary",isDisabled:r||s,isPending:r,onPress:l,children:i?"Retry":"Pay ".concat(t)})]})]})})})})}var ew=t(56952),eN=t(4931),ek=t(64605),eC=t(87627);function eE(e){return e&&Number.isFinite(Date.parse(e))?"Your plan ends on ".concat((0,Z.sL)(e),"."):"Cancellation scheduled. Plan end date unavailable."}function eS(e){var n,t,i,l,o,c,d,u,m,h,x;let{headingId:v}=e,[b,j]=(0,r.useState)(!1),w=(0,r.useRef)(null),N=()=>{var n;w.current=document.activeElement instanceof HTMLElement?document.activeElement:null,j(!0),null==(n=e.onConfirmationChange)||n.call(e,!0)},k=null!=(o=e.onAddCard)?o:N,C=function(e){let{onOperationReceipt:n,onAddCard:t}=e,a=(0,_.jE)(),s=(0,ew.NL)({retry:!1}),i=(0,ed.C)(),l=i.isSuccess&&!0===i.data.canManage,o=(0,eh.jY)({enabled:l}),c=(0,eC.n)(),d=(0,W.NK)(e=>e.activeOrgId),u=(0,r.useRef)({org:d,mounted:!0,sequence:0,action:0});u.current.org=d;let m=(0,r.useRef)(!1),[h,x]=(0,r.useState)(null),[v,y]=(0,r.useState)(null),[b,j]=(0,r.useState)(null),[w,N]=(0,r.useState)(null),[k,C]=(0,r.useState)("idle"),[E,S]=(0,r.useState)(!1),[R,I]=(0,r.useState)(!1),[A,T]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=u.current;return e.mounted=!0,()=>{e.mounted=!1,e.sequence++}},[]);let P=s.data,D=!s.isError&&!s.isPending&&("idle"===k||"matched"===k),L=l&&c&&!h&&D,q=async(e,n)=>{let t=u.current.action;C("checking");let a=await s.refetch({cancelRefetch:!0});if(!u.current.mounted||u.current.org!==d||u.current.sequence!==n)return;let r=a.data,i=null===r||r&&"string"==typeof r.id&&/^[1-9]\d*$/.test(r.id)&&"string"==typeof r.status&&"boolean"==typeof r.cancelAtPeriodEnd&&"boolean"==typeof r.canCancel&&"boolean"==typeof r.canResume,l=r&&!1===r.canCancel&&!1===r.canResume,o=!e||null===r||(null==r?void 0:r.id)===e.id&&(l||r.cancelAtPeriodEnd===e.cancelAtPeriodEnd&&r.cancelsAt===e.cancelsAt);C(a.isSuccess&&i&&o?"matched":"unavailable"),a.isSuccess&&i&&o&&(I(!1),T(!1),u.current.action===t&&y(null))},F=async function(e){var r,s;let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null==P?void 0:P.id;if(m.current||!l||!c)return!1;let h="cancel"===e||"resume"===e||"reinstate"===e,v=eN.l.subscriptionStatus(),b=()=>{var e;return"string"==typeof i&&/^[1-9]\d*$/.test(i)&&(null==(e=a.getQueryData(v))?void 0:e.id)===i};if("portal"!==e&&!b()||"cancel"===e&&(!L||(null==P?void 0:P.canCancel)!==!0)||"resume"===e&&(!L||(null==P?void 0:P.canResume)!==!0||E||!o.c
1ard||o.isError||o.isFetching)||"reinstate"===e&&(!L||(null==P||null==(r=P.lifecycle)?void 0:r.restoreEligible)!==!0||E||!o.card||o.isError||o.isFetching)||"remove_card"===e&&(o.isLoading||o.isError||o.isFetching))return!1;m.current=!0,T(!1),u.current.action++;let w=h?++u.current.sequence:u.current.sequence,k=()=>u.current.mounted&&u.current.org===d&&u.current.sequence===w;x(e);let R="portal"===e?"open_portal":"remove_card"===e?null:e;R&&(0,f.u4)(p.AnalyticsEventName.BILLING_SUBSCRIPTION_ACTION_REQUESTED,{action:R});try{if("portal"===e){let e=await ek.A.createPortalSession();if(!k())return!1;if(!(null==(s=e.url)?void 0:s.trim()))throw Error("Billing portal unavailable.");window.location.assign(e.url)}else if("remove_card"===e){let e=await new Promise((e,n)=>o.removePaymentMethod(void 0,{onSuccess:t=>"boolean"==typeof t.removed?e(t.removed):n(Error("Card removal was not confirmed.")),onError:n}));if(!k())return!1;S(!0),e&&(0,f.u4)(p.AnalyticsEventName.BILLING_CARD_REMOVED,void 0),o.refetch({cancelRefetch:!1}).then(e=>{k()&&e.isSuccess&&S(!1)})}else if("reinstate"===e){if(await a.cancelQueries({queryKey:v}),!k()||!b())return!1;let e=await ek.A.reinstateSubscription();if(!k())return!1;if("add_card_required"===e.status)return null==t||t(),!1;if("expired"===e.status)return y("This plan can no longer be restored."),!1;if("needs_reconciliation"===e.status)return T(!0),y(null),!1;q(null,w)}else{if(await a.cancelQueries({queryKey:v}),!k()||!b())return!1;let t=await ("cancel"===e?ek.A.cancelSubscription(i):ek.A.resumeSubscription(i));if(!k())return!1;let r=a.getQueryData(eN.l.subscriptionStatus());if((null==r?void 0:r.id)!==i)return!1;if(t.id!==i||"string"!=typeof t.status||t.cancelAtPeriodEnd!==("cancel"===e)||!(null===t.cancelsAt||"cancel"===e&&"string"==typeof t.cancelsAt&&Number.isFinite(Date.parse(t.cancelsAt))))throw Error("The subscription change was not confirmed. Refresh and try again.");if(await a.cancelQueries({queryKey:v}),!k())return!1;a.setQueryData(v,e=>(null==e?void 0:e.id)===i?{...e,status:t.status,cancelAtPeriodEnd:t.cancelAtPeriodEnd,cancelsAt:t.cancelsAt}:e);let s="cancel"===e?eE(t.cancelsAt):"Cancellation removed.";j(s),N(t),"cancel"===e&&(null==n||n((0,p.buildOperationReceipt)({status:"ok",verdict:s,read_trigger:"/subscriptions",next_action:"Open Plan and billing"}))),q(t,w)}return y(null),R&&(0,f.u4)(p.AnalyticsEventName.BILLING_SUBSCRIPTION_ACTION_SUCCEEDED,{action:R}),!0}catch(n){if(!k())return!1;let e=(0,g.Y3)(n);return 409===e&&(I(!0),N(null),C("unavailable")),y(403===e?"Managing billing requires an Owner, Admin or Staff.":409===e?"This subscription cannot be changed right now. Refresh its status.":"The change could not be confirmed. Please try again."),R&&(0,f.u4)(p.AnalyticsEventName.BILLING_SUBSCRIPTION_ACTION_FAILED,{action:R,failure_reason:(0,g.Pv)(e)}),!1}finally{k()&&(m.current=!1,x(null))}};return{subscription:s,current:P,canManage:l,card:o,online:c,pending:h,error:v,restoreBlocked:A,needsRefresh:R,history:b,expected:w,reconciliation:k,detached:E,available:L,run:F,clearError:()=>{y(null),T(!1)},refresh:()=>{!m.current&&c&&q(w,++u.current.sequence)}}}({...e,onAddCard:k}),E=(0,eh.WI)(),[S,I]=(0,r.useState)(null);(0,r.useEffect)(()=>{E.isError?I(E.error):E.isSuccess&&I(null)},[E.isError,E.isSuccess,E.error]);let A=null!=(c=E.error)?c:S,[P,D]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(!E.isPending||S)return void D(!1);let e=setTimeout(()=>D(!0),R.hD);return()=>clearTimeout(e)},[E.isPending,S]);let L=(0,eo.A)({enabled:C.canManage&&null===C.current}),q=(0,ed.O4)(),[F,U]=(0,r.useState)(""),[O,M]=(0,r.useState)(!1),[z,K]=(0,r.useState)(null),B=(0,r.useRef)(!0),G=(0,r.useRef)(!1),Y=(0,r.useRef)(!1);Y.current=C.canManage&&C.online&&C.subscription.isSuccess&&null===C.current;let $=(0,R.Yn)((0,el.useSearchParams)().get("return"));(0,r.useEffect)(()=>(B.current=!0,()=>{B.current=!1}),[]);let V=Array.isArray(L.data)?L.data.filter(e=>{var n;return e.purchasable&&e.monthlyPriceUsdCents>0&&(null==(n=e.currency)?void 0:n.toLowerCase())==="usd"}):[],H=async()=>{if(!G.current&&Y.current&&V.some(e=>e.planKey===F)){G.current=!0,M(!0),K(null);try{let e=await ec.A.createPlanCheckout(F,null!=$?$:void 0);if(!B.current||!Y.current)return;if(!e.url)throw Error("Checkout unavailable");window.location.assign(e.url)}catch(e){B.current&&K("Could not start checkout. Choose a plan and try again.")}finally{G.current=!1,B.current&&M(!1)}}},Q=(0,_.jE)(),X=(0,ef.l)({returnTo:"/settings?section=billing"}),[J,ee]=(0,r.useState)(!1),en=()=>{var n;ee(!1),null==(n=e.onConfirmationChange)||n.call(e,!1)},et=X.invoice?(0,ey.gP)({amountMinor:X.invoice.amountMinor,currency:X.invoice.currency}):"Amount unavailable",ea=async()=>{"paid"===await X.pay()&&(en(),C.refresh(),Q.invalidateQueries({queryKey:["invoice-payment-preparation"]}))},{current:er,subscription:es,canManage:ei,pending:em,error:ep,restoreBlocked:eS,history:eR,reconciliation:eI,expected:eA,available:eT,card:eP,detached:eD,online:eL}=C,{confirmation:eq,dismiss:e_,open:eF,confirm:eU}=function(e,n){var t;let{headingId:a,onConfirmationChange:s}=n,[i,l]=(0,r.useState)(null),o=(0,r.useRef)(null),c=(0,r.useRef)(void 0),d=null==(t=e.current)?void 0:t.id;(0,r.useEffect)(()=>()=>null==s?void 0:s(!1),[s]),(0,r.useEffect)(()=>{i&&d!==c.current&&(l(null),null==s||s(!1),requestAnimationFrame(()=>{var e;
1return null==(e=document.getElementById(a))?void 0:e.focus()}))},[d,i,s,a]);let u=()=>{e.pending||(l(null),null==s||s(!1),requestAnimationFrame(()=>{var e;let n=o.current;(null==n?void 0:n.isConnected)&&!n.hasAttribute("disabled")?n.focus():null==(e=document.getElementById(a))||e.focus()}))};return{confirmation:i,dismiss:u,open:n=>{o.current=document.activeElement,c.current=d,e.clearError(),l(n),null==s||s(!0),"cancel"===n&&(0,f.u4)(p.AnalyticsEventName.BILLING_CANCELLATION_FLOW_STARTED,{})},confirm:async()=>{await e.run("cancel"===i?"cancel":"remove_card",c.current)&&u()}}}(C,e),[eO,eM]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(!es.isPending)return void eM(!1);let e=setTimeout(()=>eM(!0),R.hD);return()=>clearTimeout(e)},[es.isPending]);let ez="checking"===eI||"unavailable"===eI||es.isError,eK=(null==er?void 0:er.plan)&&"object"==typeof er.plan?er.plan:null,eB=(null==eK||null==(n=eK.currency)?void 0:n.toUpperCase())==="USD"&&Number.isFinite(eK.monthlyPriceUsdCents)?"".concat((0,Z.Au)({amount:String(eK.monthlyPriceUsdCents/100),currency:"USD"})," / month (estimate)"):"Amount unavailable",eG=(null==er?void 0:er.status)==="trialing"?er.trialEnd:E.isError?null:null==(t=E.data)?void 0:t.currentPeriodEnd,eY=!ez&&(null==er?void 0:er.cancelAtPeriodEnd)===!0,e$="checking"===eI?eA:null,eV=e$?!e$.cancelAtPeriodEnd:(null==er?void 0:er.canCancel)===!0,eH=e$?e$.cancelAtPeriodEnd:(null==er?void 0:er.canResume)===!0,eQ=(null==er?void 0:er.cancelAtPeriodEnd)===!0||ez&&(null==eA?void 0:eA.cancelAtPeriodEnd)===!0,eW=eD||!eP.isLoading&&!eP.isError&&!eP.isFetching&&!eP.card,eX=ez?null:null!=(d=null==er?void 0:er.lifecycle)?d:null,eJ=(null==eX?void 0:eX.closedViaCancellation)===!0,eZ=(null==eX?void 0:eX.restoreEligible)===!0,e0=null!=(u=null==eX?void 0:eX.deadline)?u:null,e1=null===er&&es.isSuccess,e2=eH?"resume":eZ?"reinstate":null,e4=e2?"restore":eW||!er?"card":"manage";return(0,a.jsxs)("section",{className:"flex flex-col gap-4","aria-labelledby":v,"aria-busy":es.isPending,children:[(0,a.jsx)("h2",{id:v,tabIndex:-1,className:"text-base font-medium text-foreground outline-none",children:"Plan and billing"}),X.pastDue&&X.invoice?(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border py-4 text-sm",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-col gap-1",children:[(0,a.jsx)("p",{className:"font-medium text-foreground",children:"Past due"}),(0,a.jsx)("p",{className:"text-muted-foreground",children:"Your balance is past due. Review the amount before paying."})]}),(0,a.jsxs)(y.$n,{variant:"primary",isDisabled:!eL||X.isPaying,onPress:()=>{var n;ee(!0),null==(n=e.onConfirmationChange)||n.call(e,!0)},children:["Pay ",et," now"]})]}):null,eO?(0,a.jsx)(s.EA,{className:"h-12 w-full","aria-label":"Loading plan"}):null,eJ?(0,a.jsxs)("div",{className:"flex flex-col gap-2 border-b border-border py-4 text-sm",children:[(0,a.jsx)("p",{className:"font-medium text-foreground",children:"This workspace is closed"}),(0,a.jsxs)("p",{children:["Restore is no longer available for this workspace."," ",(0,a.jsx)("a",{className:"underline",href:"mailto:".concat(ev.ei),children:"Contact support"})]})]}):null,eJ?null:(0,a.jsxs)("dl",{className:"text-sm",children:[(0,a.jsxs)("div",{className:"flex flex-wrap justify-between gap-2 border-b border-border py-4",children:[(0,a.jsx)("dt",{children:"Current plan"}),(0,a.jsx)("dd",{children:es.isPending?"Loading plan":null!==er||es.isError?null!=(m=null==eK?void 0:eK.displayName)?m:"Plan unavailable":"No plan on this account yet"})]}),er?(0,a.jsxs)("div",{className:"flex flex-wrap justify-between gap-2 border-b border-border py-4",children:[(0,a.jsx)("dt",{children:"Status"}),(0,a.jsx)("dd",{children:null!=(h=({active:"Active",trialing:"Trial",past_due:"Past due",canceled:"Canceled",paused:"Paused",unpaid:"Unpaid"})[er.status])?h:"Status unavailable"})]}):null,er?(0,a.jsxs)("div",{className:"flex flex-wrap justify-between gap-2 border-b border-border py-4",children:[(0,a.jsx)("dt",{children:"Catalog price"}),(0,a.jsx)("dd",{className:"tabular-nums",children:eB})]}):null,e1?null:(0,a.jsxs)("div",{className:"flex flex-wrap justify-between gap-2 border-b border-border py-4",children:[(0,a.jsx)("dt",{children:eY||eZ?"Plan end":"Next charge"}),(0,a.jsx)("dd",{children:ez?"Unavailable":eY?eE(null!=(x=null==er?void 0:er.cancelsAt)?x:null):eZ?e0&&Number.isFinite(Date.parse(e0))?(0,a.jsx)("time",{dateTime:e0,children:(0,Z.sL)(e0)}):"Unavailable":(null==er?void 0:er.canCancel)&&eG&&Number.isFinite(Date.parse(eG))?(0,a.jsx)("time",{dateTime:eG,children:(0,Z.sL)(eG)}):"Unavailable"})]}),er&&"trialing"!==er.status&&"canceled"!==er.status&&q.data&&Array.isArray(q.data.ineligibleReasons)&&0===q.data.ineligibleReasons.length&&null!==q.data.monthlyBudgetUsdCents?(0,a.jsxs)("div",{className:"flex flex-wrap justify-between gap-2 border-b border-border py-4",children:[(0,a.jsx)("dt",{children:"Usage credits"}),(0,a.jsxs)("dd",{className:"text-right text-sm tabular-nums",children:[(0,eu.HG)(q.data.mtdTopUpUsdCents)," of"," ",(0,eu.HG)(q.data.monthlyBudgetUsdCents)," used",(0,a.jsx)("br",{}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:Number.isFinite(Date.parse(q.data.resetsAt))?(0,a.jsxs)(a.Fragment,{children:["Resets"," ",(0,a.jsx)("time",{dateTime:q.data.resetsAt,children:(0,Z.GB)(q.data.resetsAt)})]}):"Reset date unavailable"}),q.isError?(0,a.jsx)("p",{role:"alert",children:"Usage credits unavailable. Last available amount shown."}):null]})]}):null,ei&&!e1?(0,a.jsxs)("div",{className:"flex flex-wrap justify-between gap-2 border-b border-border py-4",children:[(0,a.jsx)("dt",{children:eQ?"Payment card":"Card on file"}),(0,a.jsx)("dd",{children:eW?"No card":eP.isLoading||eP.isFetching||eP.isError?"Card status unavailable":eP.card?"".concat(eP.card.brand," ").concat(eP.card.last4):"Card status unavailable"})]}):null]}),null===er&&es.isSuccess&&ei?(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsx)("div",{role:"group","aria-label":"Choose a plan",className:"flex flex-wrap gap-2",children:V.map(e=>(0,a.jsxs)(y.$n,{variant:"secondary","aria-pressed":F===e.planKey,isDisabled:O,onPress:()=>
1U(e.planKey),children:[e.displayName," \xb7"," ",(0,Z.Au)({amount:String(e.monthlyPriceUsdCents/100),currency:e.currency},e.monthlyPriceUsdCents%100?2:0)," ","/ month"]},e.planKey))}),L.isError?(0,a.jsx)(T,{heading:"Plans unavailable",message:"Couldn't load available plans. Try again.",onRetry:()=>void L.refetch(),isRetrying:L.isFetching}):L.isSuccess&&0===V.length?(0,a.jsx)("p",{className:"text-sm",children:"No plans are available to purchase right now."}):null,z?(0,a.jsx)("p",{role:"alert",children:z}):null,(0,a.jsx)(y.$n,{variant:"secondary",isDisabled:!eL||O||!F||L.isError,isPending:O,onPress:()=>void H(),children:"Start a plan"})]}):null,eR?(0,a.jsxs)("p",{role:"status",className:"text-sm",children:["Previous confirmation: ",eR]}):null,ez?(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("p",{role:"status",className:"text-sm",children:"checking"===eI?"Checking current subscription status":"Current subscription status unavailable"}),(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",isDisabled:!eL||!!em||"checking"===eI,onPress:C.refresh,children:es.isError?"Retry":"Refresh"})]}):null,!ep||eq||eS?null:(0,a.jsx)("p",{role:"alert",className:"text-sm",children:ep}),eS&&!eq?(0,a.jsxs)("p",{role:"alert",className:"text-sm",children:["Restore could not finish because a previous attempt left an unresolved subscription on this workspace."," ",(0,a.jsx)("a",{className:"underline",href:"mailto:".concat(ev.ei),children:"Contact support"})," ","to resolve it."]}):null,ei&&!eJ?(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[er?(0,a.jsx)(y.$n,{variant:"manage"===e4?"primary":"secondary",isDisabled:!eL||!!em,isPending:"portal"===em,onPress:()=>void C.run("portal"),children:"Manage plan"}):null,e1?null:(0,a.jsx)(y.$n,{variant:"card"===e4?"primary":"secondary",isDisabled:!eL||!!em,onPress:N,children:eP.card?"Update card":"Add card"}),eV?(0,a.jsx)(y.$n,{variant:"ghost",isDisabled:!eT,onPress:()=>eF("cancel"),children:"Cancel plan"}):null,e2?eW&&!ez?k?(0,a.jsx)(y.$n,{variant:"primary",onPress:k,children:"Add card to Restore"}):(0,a.jsx)("p",{className:"text-sm",children:"Add a card before restoring your plan. Card setup is unavailable."}):(0,a.jsx)(y.$n,{variant:"primary",isDisabled:!eT||eP.isError||eP.isFetching||!eP.card||eD,isPending:em===e2,onPress:()=>void C.run(e2),children:"Restore plan"}):null,eQ&&!eW?(0,a.jsx)(y.$n,{variant:"ghost",isDisabled:!eL||!!em||eP.isLoading||eP.isError||eP.isFetching,onPress:()=>eF("detach"),children:"Remove card"}):null]}):null,e1?null:(0,a.jsxs)("section",{"aria-label":"Invoices",className:"flex flex-col gap-3 border-t border-border pt-4",children:[(0,a.jsx)("h3",{className:"text-sm font-medium",children:"Invoices"}),!P||E.data||A?null:(0,a.jsx)(s.EA,{className:"h-16 w-full","aria-label":"Loading invoices"}),ei&&403!==(0,g.Y3)(A)?(0,a.jsxs)(a.Fragment,{children:[A?(0,a.jsx)(T,{heading:"Invoices unavailable",message:"Couldn't load invoices. Your last available invoices stay here. Try again.",onRetry:()=>void E.refetch(),isRetrying:E.isFetching}):null,(null==(i=E.data)?void 0:i.invoices.length)!==0||A?null:(0,a.jsxs)(ex.pp,{className:"items-start py-2",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:"No invoices yet"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Invoices appear here after billing."}),ei?(0,a.jsx)(y.$n,{variant:"ghost",size:"sm",className:"px-0",onPress:N,children:"Check your payment method"}):(0,a.jsx)("p",{className:"text-xs",children:"Ask an Owner or Admin about billing."})]}),null==(l=E.data)?void 0:l.invoices.map(e=>{var n,t,r,s;let i=null;try{i=null!=(n=new Intl.NumberFormat("en-US",{style:"currency",currency:e.currency}).resolvedOptions().maximumFractionDigits)?n:2}catch(e){i=null}return(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border py-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{children:null!=(t=e.number)?t:"Invoice"}),(0,a.jsx)("time",{dateTime:e.created,className:"text-xs text-muted-foreground",children:(0,Z.sL)(e.created)})]}),(0,a.jsx)("span",{className:"tabular-nums",children:null===i?"Amount unavailable":(0,Z.Au)({amount:String(e.total/10**i),currency:e.currency},i)}),(0,a.jsx)("span",{children:null!=(r=e.status)?r:"Status unavailable"}),e.hostedInvoiceUrl?(0,a.jsx)("a",{className:"underline",href:e.hostedInvoiceUrl,target:"_blank",rel:"noopener noreferrer","aria-label":"View invoice ".concat(null!=(s=e.number)?s:e.id),children:"View"}):(0,a.jsx)("span",{className:"text-muted-foreground",children:"Receipt unavailable"})]},e.id)})]}):(0,a.jsx)("p",{className:"text-sm",children:"Invoices are available to Owners and Admins."})]}),b?(0,a.jsx)(eg,{canManage:ei,online:eL,pending:!!em,error:ep,onUpdate:()=>void C.run("portal"),onClose:()=>{var n;j(!1),null==(n=e.onConfirmationChange)||n.call(e,!1),requestAnimationFrame(()=>{var e,n;(null==(e=w.current)?void 0:e.isConnected)?w.current.focus():null==(n=document.getElementById(v))||n.focus()})}}):null,(0,a.jsx)(eb,{onRefresh:"cancel"===eq&&C.needsRefresh?()=>{e_(),C.refresh()}:void 0,isOpen:null!==eq,kind:null!=eq?eq:"cancel",pending:!!em,offline:!eL||!ei,error:ep,planEndDate:eG,onConfirm:()=>void eU(),onDismiss:e_}),(0,a.jsx)(ej,{isOpen:J,amountLabel:et,pending:X.isPaying,offline:!eL,error:X.error,onConfirm:()=>void ea(),onCancel:en})]})}var eR=t(61606),eI=t(28689),eA=t(45702),eT=t(28875),eP=t(90546),eD=t(32697);function eL(e){let{used:n,total:t}=e,r=t>
10?Math.min(100,n/t*100):0,s="".concat(r.toLocaleString("en-US",{maximumFractionDigits:+(r<10)}),"% used");return(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-4",children:[(0,a.jsx)(eR.kI,{value:r,"aria-label":"Monthly tokens: ".concat(n.toLocaleString("en-US")," of ").concat(t.toLocaleString("en-US")," tokens used"),valueLabel:s,color:"default",className:"min-w-0 flex-1",children:(0,a.jsx)(eR.kI.Track,{children:(0,a.jsx)(eR.kI.Fill,{})})}),(0,a.jsx)("span",{className:"shrink-0 text-sm tabular-nums",children:s})]}),(0,a.jsxs)("span",{className:"text-xs tabular-nums text-muted-foreground","aria-label":"".concat(n.toLocaleString("en-US")," of ").concat(t.toLocaleString("en-US")," tokens used"),children:[(0,Z.qq)(n)," of ",(0,Z.qq)(t)," tokens"]})]})}function eq(e){var n,t,i;let{headingId:l}=e,o=(0,W.NK)(e=>e.activeOrgId),c=(0,_.jE)(),d=(0,eP.U)(R.fg),u=(0,F.I)({...eD.Ay.all(o),retry:!1,retryOnMount:!1,refetchOnMount:!1,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),m=(0,eh.WI)(),[h,p]=(0,r.useState)(null),[f,x]=(0,r.useState)(!1);(0,r.useEffect)(()=>{u.isError?p(u.error):u.isSuccess&&p(null)},[u.isError,u.isSuccess,u.error]),(0,r.useEffect)(()=>{if(!u.isPending||h)return void x(!1);let e=setTimeout(()=>x(!0),R.hD);return()=>clearTimeout(e)},[u.isPending,h]);let v=u.data,y=null!=(t=null==v?void 0:v.creditsBySource.subscription)?t:null==v?void 0:v.creditsBySource.giveaway,b=y&&Number.isFinite(y.initial)&&Number.isFinite(y.current)&&y.initial>=0?Math.max(0,y.initial-y.current):null,j=[403===(0,g.Y3)(m.error)?null:null==(n=m.data)?void 0:n.currentPeriodEnd,null==v?void 0:v.nextRefillAt].find(e=>e&&Number.isFinite(Date.parse(e))),w=null!=(i=u.error)?i:h,N=(0,eD.ge)(c,o),k=Math.max(0,Math.ceil((N-Date.now())/1e3));return(0,a.jsxs)("section",{className:"flex flex-col gap-4","aria-labelledby":l,"aria-busy":u.isFetching,children:[(0,a.jsx)("h2",{id:l,tabIndex:-1,className:"text-base font-medium text-foreground outline-none",children:"Usage"}),w?(0,a.jsx)(T,{heading:"Usage unavailable",message:"Couldn't load token usage. Your last available usage stays here. Try again.",onRetry:()=>{Date.now()>=N&&u.refetch()},isRetrying:u.isFetching,retryAfterSeconds:k||void 0},N):null,!f||v||w?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.EA,{className:"h-24 w-full","aria-label":"Loading usage tiles"}),(0,a.jsx)(s.EA,{className:"h-16 w-full","aria-label":"Loading monthly tokens"})]}),v&&null!==b&&y?(0,a.jsxs)(eA.uW,{orientation:d?"vertical":"horizontal",children:[(0,a.jsxs)(eT.p,{children:[(0,a.jsx)(eT.p.Header,{children:(0,a.jsx)(eT.p.Title,{children:"Tokens used"})}),(0,a.jsx)(eT.p.Content,{children:(0,a.jsx)(eT.p.Value,{maximumFractionDigits:0,value:b})}),(0,a.jsx)(eT.p.Footer,{children:"this billing period"})]}),(0,a.jsx)(eA.uW.Separator,{}),(0,a.jsxs)(eT.p,{children:[(0,a.jsx)(eT.p.Header,{children:(0,a.jsx)(eT.p.Title,{children:"Tokens remaining"})}),(0,a.jsx)(eT.p.Content,{children:(0,a.jsx)(eT.p.Value,{maximumFractionDigits:0,value:Math.max(0,y.current)})}),(0,a.jsx)(eT.p.Footer,{children:"resets on the period boundary"})]})]}):null,v?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-4 border-b border-border py-4 sm:flex-row sm:items-center",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1 sm:w-44",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:"Monthly tokens"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:j?(0,a.jsxs)(a.Fragment,{children:["Resets ",(0,a.jsx)("time",{dateTime:j,children:(0,Z.fA)(j)})]}):"Monthly allowance. Reset date unavailable."})]}),null!==b&&y?(0,a.jsx)(eL,{used:b,total:y.initial}):(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Monthly allowance unavailable"})]}),0===b?(0,a.jsxs)(ex.pp,{className:"items-start py-2",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:"No tokens used this period"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Your monthly allowance is ready."}),(0,a.jsx)(eI.N_,{href:"/chat",children:"Open chat"})]}):null,v.heldTokens>0?(0,a.jsxs)("p",{className:"text-sm text-muted-foreground","aria-label":"".concat(v.heldTokens.toLocaleStr
1ing("en-US")," tokens reserved, not counted as used"),children:[(0,eu.Rk)(v.heldTokens)," tokens reserved, not counted as used"]}):null]}):null]})}let e_={gmail:"Gmail",instagram:"Instagram",tiktok:"TikTok Shop",mcp:"MCP"},eF={gmail:(0,a.jsx)("path",{d:"M1.5 3.5h2.2L8 6.9l4.3-3.4h2.2V13h-2.6V7.3L8 10.2 4.1 7.3V13H1.5z",fill:"currentColor"}),mcp:(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M6.3 2.1a1.4 1.4 0 0 1 2 0l1 1a1.4 1.4 0 0 1 0 2l-.4.4 1.6 1.6.4-.4a1.4 1.4 0 0 1 2 0l1 1a1.4 1.4 0 0 1 0 2l-1.6 1.6a1.4 1.4 0 0 1-2 0l-1-1a1.4 1.4 0 0 1 0-2l.4-.4-1.6-1.6-.4.4a1.4 1.4 0 0 1-2 0l-1-1a1.4 1.4 0 0 1 0-2z",fill:"currentColor"}),instagram:(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.4 1.5h5.2a3.9 3.9 0 0 1 3.9 3.9v5.2a3.9 3.9 0 0 1-3.9 3.9H5.4a3.9 3.9 0 0 1-3.9-3.9V5.4a3.9 3.9 0 0 1 3.9-3.9zm0 1.4A2.5 2.5 0 0 0 2.9 5.4v5.2a2.5 2.5 0 0 0 2.5 2.5h5.2a2.5 2.5 0 0 0 2.5-2.5V5.4a2.5 2.5 0 0 0-2.5-2.5zM8 4.6A3.4 3.4 0 1 1 8 11.4 3.4 3.4 0 0 1 8 4.6zm0 1.4A2 2 0 1 0 8 10 2 2 0 0 0 8 6zm3.6-2.1a.8.8 0 1 1 0 1.6.8.8 0 0 1 0-1.6z",fill:"currentColor"}),tiktok:(0,a.jsx)("path",{d:"M9.6 1.5v8.3a2.3 2.3 0 1 1-1.9-2.27V5.55a4.3 4.3 0 1 0 3.9 4.25V5.4c.9.62 1.95.96 3.05.96V4.4A3.05 3.05 0 0 1 11.6 1.5z",fill:"currentColor"})};function eU(e){let{provider:n,...t}=e;return(0,a.jsx)("svg",{viewBox:"0 0 16 16",width:"16",height:"16","aria-hidden":"true",focusable:"false",className:"size-4",...t,children:eF[n]})}let eO={gmail:"Continue with Google",instagram:"Continue in chat",tiktok:"Continue with TikTok",mcp:"Connect"},eM={gmail:"Storika sends outreach from your Gmail and reads the replies; disconnect any time.",instagram:"Connect Instagram from chat.",tiktok:"Storika reads your shop's orders and creator posts; disconnect any time.",mcp:"Add the MCP endpoint to your client."};function ez(e){let{provider:n,pending:t=!1,error:s=null,onClose:i,onConfirm:l,onConfirmationChange:o}=e,c=null!==n,d=null!=n?n:"gmail";return(0,r.useEffect)(()=>{null==o||o(c)},[c,o]),(0,a.jsx)(J.Lt,{children:(0,a.jsx)(J.Lt.Backdrop,{isOpen:c,isDismissable:!1,isKeyboardDismissDisabled:t,onOpenChange:e=>{e||t||i()},children:(0,a.jsx)(J.Lt.Container,{placement:"center",size:"sm",children:(0,a.jsxs)(J.Lt.Dialog,{children:[(0,a.jsx)(J.Lt.Header,{children:(0,a.jsx)(J.Lt.Heading,{children:(0,a.jsxs)("span",{className:"flex items-center gap-2",children:[(0,a.jsx)(eU,{provider:d}),"Connect ",e_[d]]})})}),(0,a.jsxs)(J.Lt.Body,{children:[s?(0,a.jsx)("p",{role:"alert",className:"mb-3 text-sm text-danger",children:s}):null,(0,a.jsx)("p",{className:"text-left text-sm text-muted-foreground",children:eM[d]})]}),(0,a.jsxs)(J.Lt.Footer,{children:[(0,a.jsx)(y.$n,{autoFocus:!0,variant:"secondary",isDisabled:t,onPress:i,children:"Cancel"}),(0,a.jsx)(y.$n,{variant:"primary",isPending:t,onPress:l,children:t?"Connecting...":eO[d]})]})]})})})})}var eK=t(6204);function eB(e){let{provider:n,label:t,description:r,connected:s,planCanceled:i,onConnect:l,onDisconnect:o,connectLabel:c="Connect",connectDisabled:d=!1,chipLabel:u,selector:m}=e;return(0,a.jsxs)("div",{className:"flex flex-col gap-2 border-b border-border py-4 sm:flex-row sm:items-start sm:justify-between sm:gap-6",children:[(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsxs)("p",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[(0,a.jsx)(eU,{provider:n}),t,(0,a.jsx)(eK.vu,{variant:"secondary",children:(0,a.jsx)(eK.vu.Label,{children:null!=u?u:s?"Connected":"Not connected"})})]}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:r}),m]}),s?o?(0,a.jsx)(y.$n,{variant:"ghost",size:"sm",onPress:o,children:"Disconnect"}):null:(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",isDisabled:i||d,onPress:l,children:c})]})}var eG=t(12307);function eY(e){let{planCanceled:n}=e,t=(0,eG.Dn)(),[i,l]=(0,r.useState)(!1);if(t.isPending)return(0,a.jsx)("div",{className:"flex flex-col gap-2 border-b border-border py-4",children:(0,a.jsx)(s.EA,{className:"h-6 w-32","aria-label":"Loading MCP"})});if(t.isError&&void 0===t.data)return(0,a.jsxs)("div",{className:"flex flex-col gap-2 border-b border-border py-4",children:[(0,a.jsxs)("p",{className:"flex items-center gap-2 text-sm font-medium",children:[(0,a.jsx)(eU,{provider:"mcp"}),"MCP"]}),(0,a.jsx)("p",{role:"alert",className:"text-sm text-muted-foreground",children:"Status unavailable."}
1),(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",isPending:t.isFetching,onPress:()=>void t.refetch(),children:"Retry"})]});let o=t.data,c=!!((null==o?void 0:o.available)&&o.connections.length>0),d=(null==o?void 0:o.available)===!1,u=d?"Not available":c?"Connected to your MCP server":i&&(null==o?void 0:o.available)&&o.endpointUrl?"Add this endpoint to your MCP client: ".concat(o.endpointUrl):"Not connected";return(0,a.jsx)(eB,{provider:"mcp",label:"MCP",description:u,connected:c,planCanceled:n,connectDisabled:d,chipLabel:d?"Not available":void 0,connectLabel:i?"Hide details":"Connect",onConnect:()=>l(e=>!e)})}var e$=t(65152);let eV=O.Ik({connected:O.zM(),reauthenticationRequired:O.zM().optional().default(!1)}).refine(e=>!(e.connected&&e.reauthenticationRequired),{message:"Connected and reauthentication-required are mutually exclusive"});class eH extends U.Ay{async getStatus(e){let n=await this.httpRequired.get("/tiktok-shop/status".concat((0,e$.Z)({brandId:e}))),t=eV.safeParse(n);if(!t.success)throw Error("Contract-broken TikTok Shop status response");return t.data}}let eQ=new eH,eW={all:(e,n)=>["tiktok-shop-status",e,n],status:(e,n)=>[...eW.all(e,n),"status"]};var eX=t(81562);class eJ extends U.Ay{async getConnectUrl(e,n){return this.httpRequired.get("/auth/tiktok-shop/connect".concat((0,e$.Z)({brandId:e,return_url:n})))}async disconnect(e){return this.httpRequired.delete("/tiktok-shop/connection".concat((0,e$.Z)({brandId:e})))}}let eZ=new eJ;var e0=t(93558),e1=t(85406),e2=t(82138),e4=t(55811),e6=t(60875);let e5=O.KC([O.Yj().trim().min(1),O.ai().finite()]).transform(String),e3=O.Ik({name:O.Yj(),region:O.Yj()}),e8=e5.nullable().optional().transform(e=>null!=e?e:null),e9=O.Yj().nullable().optional().transform(e=>null!=e?e:null),e7=O.Ik({shop:e3,targetBrandId:e5,targetBrandName:O.Yj(),currentBrandId:e8,currentBrandName:e9}),ne=O.Ik({brandId:e5,shop:e3});function nn(e,n,t){let a=e.safeParse(n);if(!a.success)throw Error("Contract-broken ".concat(t," response"));return a.data}class nt extends U.Ay{async preview(e){return nn(e7,await this.httpRequired.post("/tiktok-shop/bind/move-preview",{moveNonce:e}),"move-preview")}async confirm(e,n,t){return nn(ne,await this.httpRequired.post("/tiktok-shop/bind/move-confirm",{moveNonce:e,confirmMove:n,expectedCurrentBrandId:t}),"move-confirm")}}let na=new nt,nr=[e4.iz,e4.Ls,e4.TD,e4.uv];function ns(e){let{brands:n,orgId:t,planCanceled:r,onConnect:s,idle:i}=e;return i?(0,a.jsx)(ni,{idle:i,planCanceled:r}):(0,a.jsx)(no,{brands:n,orgId:null!=t?t:"",planCanceled:r,onConnect:s})}function ni(e){let{idle:n,planCanceled:t}=e,r="unresolved"===n;return(0,a.jsx)(eB,{provider:"tiktok",label:"TikTok Shop",description:r?"Choose a workspace in the header to see its shop.":"Add a brand to this workspace to connect its shop.",connected:!0,chipLabel:r?"Choose a workspace":"Not connected",planCanceled:t,onConnect:()=>void 0})}function nl(e){let{brands:n,brandId:t,onPick:r}=e;return(0,a.jsxs)(m.l6,{"aria-label":"TikTok Shop brand",value:t,onChange:e=>{"string"==typeof e&&r(e)},variant:"secondary",className:"w-full sm:w-64",children:[(0,a.jsxs)(m.l6.Trigger,{children:[(0,a.jsx)(m.l6.Value,{}),(0,a.jsx)(m.l6.Indicator,{})]}),(0,a.jsx)(m.l6.Popover,{children:(0,a.jsx)(h.qF,{children:n.map(e=>(0,a.jsxs)(h.qF.Item,{id:e.id,textValue:e.name,children:[e.name,(0,a.jsx)(h.qF.ItemIndicator,{})]},e.id))})})]})}function no(e){var n,t,s;let{brands:i,orgId:l,planCanceled:o,onConnect:c}=e,[d,u]=(0,r.useState)(null),m=null!=(s=i.find(e=>e.id===d))?s:i[0],h=function(e){let n=!(arguments.length>1)||void 0===arguments[1]||arguments[1],t=(0,W.NK)(e=>e.activeOrgId),a=(0,F.I)({queryKey:eW.status(t,e),queryFn:()=>eQ.getStatus(e),enabled:n&&!!e,staleTime:6e4,gcTime:3e5});return e?a:{...a,data:{connected:!1,reauthenticationRequired:!1}}}(m.id),g=function(e,n){let t=(0,_.jE)(),a=(0,W.NK)(e=>e.activeOrgId),r=(0,f.CW)(e),s=(0,f.Wl)(n);return(0,eX.n)({mutationFn:()=>eZ.disconnect(e),onSuccess:()=>{(0,f.u4)(p.AnalyticsEventName.BRAND_INTEGRATION_DISCONNECTED,{provider:"tiktok_shop",...null!==r?{brand_id:r}:{},...null!==s?{org_id:s}:{}}),t.invalidateQueries({queryKey:eW.all(a,e)})}})}(m.id,l),x=i.length>1,v=x?(0,a.jsx)(nl,{brands:i,brandId:m.id,onPick:u}):null;if(h.isError&&void 0===h.data)return(0,a.jsxs)("div",{className:"flex flex-col gap-2 border-b border-border py-4",children:[(0,a.jsxs)("p",{className:"flex items-center gap-2 text-sm font-medium",children:[(0,a.jsx)(eU,{provider:"tiktok"}),"TikTok Shop"]}),(0,a.jsxs)("p",{role:"alert",className:"text-sm text-muted-foreground",children:["Couldn't load TikTok Shop for ",m.name,"."]}),v,(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",onPress:()=>void h.refetch(),children:"Retry"})]});let b=(null==(n=h.data)?void 0:n.connected)===!0,j=(null==(t=h.data)?void 0:t.reauthenticationRequired)===!0;return(0,a.jsx)(eB,{provider:"tiktok",label:x?"TikTok Shop":"TikTok Shop (".concat(m.name,")"),description:j?"Reconnect required":b?"Connected to your TikTok Shop":"Not connected",connected:b&&!j,planCanceled:o,connectLabel:"Connect",onConnect:()=>c(m.id),onDisconnect:()=>void g.mutateAsync(),selector:v})}function nc(e){let{brandId:n,startRef:t}=e;return t.current=function(e){let{brandId:n}=e,t=(0,_.jE)(),a=(0,W.NK)(e=>e.activeOrgId),s=(0,eX.n)({mutationFn:e=>eZ.getConnectUrl(n,e)}),i=(0,r.useRef)(null),l=(0,r.useRef)(null),o=(0,r.useRef)(null),[c,d]=(0,r.useState)(!1),u=(0,r.useRef)(!0),m=(0,r.useCallback)(()=>{null!=o.current&&(o.current(),o.current=null)},[]);(0,r.useEffect)(()=>(u.current=!0,()=>{u.current=!1,m()}),[m]);let h=(0,r.useCallback)(()=>{i.current=null,l.current=null,d(!1)},[]),x=(0,r.useCallback)(()=>{t.invalidateQueries({queryKey:eW.all(a,n)})},[t,a,n]),v=(0,r.useCallback)(()=>{x(),e0.default.success("TikTok Shop connected."),(0,f.u4)(p.AnalyticsEventName.BRAND_INTEGRATION_CONNECTED,{provider:"tiktok_shop"})},[x]),[y,b]=(0,r.useState)(null),j=(0,eX.n)({mutationFn:e=>na.preview(e)}),w=(0,eX.n)({mutationFn:e=>{let{moveNonce:n,expectedCurrentBrandId:t}=e;return na.confirm(n,!0,t)}}),N=(0,r.useCallback)(e=>{j.mutate(e,{onSuccess:n=>{if(!u.current)return;let{currentBrandId:t,...a}=n;if(null==t)return void e0.default.error((0,e6.mw)(p.TiktokShopConnectErrorCode.MOVE_CONFIRMATION_REQUIRED));b({...a,currentBrandId:t,moveNonce:e})},onError:e=>{u.current&&e0.default.error((0,g.KI)(e,{verb:"load",object:"TikTok Shop move details"}))}})},[j]),k=(0,r.useCallback)(()=>{b(null)},[]),C=(0,r.useCallback)(()=>
1{if(!y)return;let{moveNonce:e,currentBrandId:n}=y;w.mutate({moveNonce:e,expectedCurrentBrandId:n},{onSuccess:()=>{u.current&&(b(null),v())},onError:n=>{if(u.current){if(b(null),(0,g.Pl)(n)===p.TiktokShopConnectErrorCode.MOVE_CONFIRMATION_REQUIRED)return void N(e);e0.default.error((0,g.KI)(n,{verb:"move",object:"TikTok Shop connection"}))}}})},[y,w,v,N]),E=(0,r.useCallback)(e=>{m();let n=i.current;return(h(),null==n||n.close(),"connected"===e.status)?void v():e.code===p.TiktokShopConnectErrorCode.MOVE_CONFIRMATION_REQUIRED&&e.moveNonce?void N(e.moveNonce):void e0.default.error((0,e6.mw)(e.code))},[v,m,h,N]),S=(0,r.useCallback)(e=>{u.current&&i.current===e&&(o.current=null,h(),x(),(0,e0.default)("Connection window closed - refreshing TikTok Shop status."))},[x,h]);(0,r.useEffect)(()=>{let e=e=>{i.current&&e&&e.type===e4.J8&&e.flow===l.current&&E({status:e.status,code:e.code,moveNonce:e.moveNonce})},n=n=>{n.origin===window.location.origin&&e(n.data)};window.addEventListener("message",n);let t=null;try{(t=new BroadcastChannel(e4.FG)).onmessage=n=>{e(n.data)}}catch(e){}return()=>{window.removeEventListener("message",n),null==t||t.close()}},[E]);let R=(0,r.useRef)(!1);return(0,r.useEffect)(()=>{if(R.current)return;R.current=!0;let e=new URLSearchParams(window.location.search),n=e.get(e4.iz),t=e.get(e4.Ls);if(!n&&!t)return;if(t){var a,r;let n=null!=(a=e.get(e4.TD))?a:void 0,t=null!=(r=e.get(e4.uv))?r:void 0;n===p.TiktokShopConnectErrorCode.MOVE_CONFIRMATION_REQUIRED&&t?N(t):e0.default.error((0,e6.mw)(n))}else v();let s=new URL(window.location.href);for(let e of nr)s.searchParams.delete(e);(0,e2.w)(s.pathname+s.search)},[v,N]),{startConnect:(0,r.useCallback)(()=>{var e;if("undefined"!=typeof navigator&&!1===navigator.onLine)return void e0.default.error("You appear to be offline. Check your connection and try again.");null==(e=i.current)||e.close(),i.current=null,m(),l.current=null;let n=(0,e1.P)();l.current=n;let t=window.open("",(0,e4.wn)(n),"popup=yes,width=520,height=640");if(d(!0),!t)return void s.mutate(window.location.href,{onSuccess:e=>{window.location.assign(e.url)},onError:e=>{u.current&&(l.current=null,d(!1),e0.default.error((0,g.KI)(e,{verb:"start",object:"TikTok Shop connection"})))}});i.current=t;let a="".concat(window.location.origin).concat(e4.Zb,"/").concat(n);s.mutate(a,{onSuccess:e=>u.current?t.closed?void S(t):void(t.location.replace(e.url),o.current=(0,e1.f)(t,()=>S(t))):void t.close(),onError:e=>{t.close(),u.current&&(h(),e0.default.error((0,g.KI)(e,{verb:"start",object:"TikTok Shop connection"})))}})},[s,m,S,h]),isConnecting:c,moveState:y,confirmMove:C,cancelMove:k,isMoving:w.isPending}}({brandId:n}).startConnect,null}var nd=t(5583),nu=t(14613);class nm extends U.Ay{async listDomains(e){let n=e?"/email/domains?status=".concat(encodeURIComponent(e)):"/email/domains";return this.httpRequired.get(n)}async getDomain(e){return this.httpRequired.get("/email/domains/".concat(e))}async registerDomain(e){return this.httpRequired.post("/email/domains",{domainName:e})}async verifyDomain(e){return this.httpRequired.post("/email/domains/".concat(e,"/verify"))}async deleteDomain(e){await this.http.delete("/email/domains/".concat(e))}}let nh=new nm;function np(e,n){let t=null!=e?e:[];return(t.some(e=>e.id===n.id)?t.map(e=>e.id===n.id?n:e):[n,...t]).sort((e,n)=>new Date(n.createdAt).getTime()-new Date(e.createdAt).getTime())}var ng=t(25812);let nf=/^[\d.]+$/,nx=/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;var nv=t(38205);function ny(e){let[n,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{if(!e)return void t(!1);let n=setTimeout(()=>t(!0),R.hD);return()=>clearTimeout(n)},[e]),e&&n}function nb(e){return Math.max(0,new Date(e).getTime()-Date.now())}function nj(e){let{value:n,label:t}=e,[s,i]=(0,r.useState)(!1);return(0,a.jsx)(y.$n,{variant:"ghost",size:"sm","aria-label":t,onPress:()=>{navigator.clipboard.writeText(n).then(()=>{i(!0),window.setTimeout(()=>i(!1),2e3)},()=>{nd.oR.danger("Failed to copy DNS value.")})},children:s?"Copied":"Copy"})}function nw(e){var n;let{domain:t}=e,r=null!=(n=t.dnsRecords)?n:[];return 0===r.length?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"No DNS records available yet."}):(0,a.jsx)("ul",{className:"divide-y divide-border rounded-lg border border-border",children:r.map((e,n)=>{var r;return(0,a.jsxs)("li",{className:"flex flex-col gap-1 px-3 py-2 sm:flex-row sm:items-center sm:gap-3",children:[(0,a.jsx)("span",{className:"w-14 shrink-0 font-mono text-xs uppercase text-muted-foreground",children:e.type}),(0,a.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-xs",title:e.name,children:e.name}),(0,a.jsx)(nj,{value:e.name,label:"Copy ".concat(e.type," record host")}),(0,a.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-xs",title:e.value,children:e.value}),(0,a.jsx)(nj,{value:e.value,label:"Copy ".concat(e.type," record value")}),(0,a.jsx)("span",{className:"shrink-0 text-xs text-muted-foreground",children:"verified"===(r=e.status?e.status:"verified"===t.status?"verified":"failed"===t.status?"failed":"pending")?"Verified":"failed"===r?"Failed":"not_started"===r?"Not started":"temporary_failure"===r?"Temporary failure":"Pending"})]},"".concat(e.type,"-").concat(e.name,"-").concat(n))})})}function nN(e){var n,t,i;let{planCanceled:l}=e,o=(0,ng.ZD)(),c=(0,nu.D)(o.data),d=(t={enabled:c},(0,F.I)({queryKey:["email-domains"],queryFn:()=>nh.listDomains(),staleTime:3e4,enabled:null==(i=null==t?void 0:t.enabled)||i})),u=function(){let e=(0,_.jE)();return(0,eX.n)({mutationFn:e=>nh.registerDomain(e),onSuccess:n=>{e.setQueryData(["email-domains"],e=>np(e,n)),"verified"===n.status&&e.setQueryData(["email-domains","verified"],e=>
1np(e,n)),e.invalidateQueries({queryKey:["email-domains"],refetchType:"none"})}})}(),m=function(){let e=(0,_.jE)();return(0,eX.n)({mutationFn:e=>nh.verifyDomain(e),onSuccess:n=>{var t;let a=null==(t=e.getQueryData(["email-domains"]))?void 0:t.some(e=>e.id===n.id&&"verified"===e.status);"verified"!==n.status||a||(0,f.u4)(p.AnalyticsEventName.SETTINGS_EMAIL_DOMAIN_VERIFIED),e.setQueryData(["email-domains"],e=>np(e,n)),e.setQueryData(["email-domains",n.id],n),"verified"===n.status&&e.setQueryData(["email-domains","verified"],e=>np(e,n)),e.invalidateQueries({queryKey:["email-domains"]})}})}(),[h,x]=(0,r.useState)(""),[v,b]=(0,r.useState)(null),[j,w]=(0,r.useState)(null),[N,R]=(0,r.useState)(null),I=o.isPending&&void 0===o.data,A=c&&d.isPending&&void 0===d.data,T=ny(I||A),P=async()=>{if(l||u.isPending)return;let e=function(e){let n=(null!=e?e:"").trim().toLowerCase();return n?n.includes("@")?{ok:!1,reason:"contains_at_sign"}:nf.test(n)?{ok:!1,reason:"ip_literal"}:nx.test(n)?n.split(".").length<3?{ok:!1,reason:"too_few_parts"}:{ok:!0,normalized:n}:{ok:!1,reason:"invalid_format"}:{ok:!1,reason:"empty"}}(h);if(!e.ok)return void b(function(e){switch(e){case"empty":return"Enter a domain.";case"contains_at_sign":return"Enter the domain only (no email address).";case"invalid_format":return"Use only letters, numbers, hyphens, and dots.";case"ip_literal":return"IP addresses are not allowed as sending domains.";case"too_few_parts":return"Use a subdomain with at least 3 parts (e.g. mail.example.com)."}}(e.reason));b(null),w(null);try{let n=await u.mutateAsync(e.normalized);x(""),(0,nd.oR)(n.dnsRecords&&n.dnsRecords.length>0?"Domain added. Add the DNS records below to verify it.":"Domain added.")}catch(n){let e=(0,g.KI)(n,{verb:"add",object:"domain",fix:"Try again."});w(e),nd.oR.danger(e)}},D=async e=>{if(!l&&!m.isPending){w(null),R(null);try{let n=await m.mutateAsync(e);(0,nd.oR)("verified"===n.status?"".concat(n.domainName," is verified."):"Checked - records are still propagating.")}catch(t){let n=(0,g.KI)(t,{verb:"verify",object:"domain",fix:"Try again."});R(e),w(n),nd.oR.danger(n)}}};if(I||A)return T?(0,a.jsx)(s.EA,{className:"h-16 w-full"}):null;if(o.isError&&void 0===o.data)return(0,a.jsxs)("div",{className:"flex flex-col gap-2 border-b border-border py-4",children:[(0,a.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Sending domain"}),(0,a.jsx)("p",{role:"alert",className:"text-sm text-muted-foreground",children:"Couldn't load sending domain. Try again."}),(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",onPress:()=>void o.refetch(),isPending:o.isFetching,children:"Retry"})]});if(c&&d.isError&&void 0===d.data)return(0,a.jsxs)("div",{className:"flex flex-col gap-2 border-b border-border py-4",children:[(0,a.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Sending domain"}),(0,a.jsx)("p",{role:"alert",className:"text-sm text-muted-foreground",children:"Couldn't load sending domain. Try again."}),(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",onPress:()=>void d.refetch(),isPending:d.isFetching,children:"Retry"})]});let L=c&&null!=(n=d.data)?n:[];return(0,a.jsxs)("div",{className:"flex flex-col gap-3 border-b border-border py-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-6",children:[(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Sending domain"}),c?(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Register a subdomain, publish its DNS records, then verify."}):(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Sending domain is included in Pro."})]}),c?null:(0,a.jsx)(eI.N_,{href:"/settings?section=billing",className:"text-sm",children:"Plan"})]}),j?(0,a.jsx)("p",{role:"alert",className:"text-sm text-muted-foreground",children:j}):null,c?L.map(e=>(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,a.jsx)("p",{className:"min-w-0 truncate font-mono text-sm",children:e.domainName}),(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:function(e){var n;let t=null!=(n=e.presentationStatus)?n:e.status;return"verified"===t?"Verified":"failed"===t?"Action needed":"verifying"===t?"Verifying":"Pending"}(e)}),(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",isDisabled:l,isPending:m.isPending,onPress:()=>void D(e.id),children:"Verify records"})]}),(0,a.jsx)(nw,{domain:e})]},e.id)):null,c&&0===L.length?(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end",children:[(0,a.jsxs)(k.A_,{value:h,onChange:e=>{x(e),v&&b(null)},isInvalid:null!==v,isDisabled:l||u.isPending,className:"w-full sm:max-w-sm",children:[(0,a.jsx)(C.JU,{children:"Sending subdomain"}),(0,a.jsx)(E.pd,{placeholder:"mail.yourdomain.com"}),v?(0,a.jsx)(S.bg,{children:v}):null]}),(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",isDisabled:l||!h.trim(),isPending:u.isPending,onPress:()=>void P(),children:"Add domain"})]}):null,j&&null!==N?(0,a.jsx)(y.$n,{variant:"secondary",size:"sm",isDisabled:l,isPending:m.isPending,onPress:()=>void D(N),children:"Retry"}):null]})}var nk=t(73626),nC=t(35664);let nE=new Set(R.HX.map(e=>e.id));function nS(e){return null!==e&&nE.has(e)?e:"profile"}function nR(e,n){let t="/settings?section=".concat(e);return null===n?t:"".concat(t,"&return=").concat(encodeURIComponent(n))}let nI={profile:function(e){let{section:n,headingId:t,onDirtyChange:l}=e,o=(0,i.yj)(),c=function(e){let[n,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>
1{if(!e)return void t(!1);let n=setTimeout(()=>t(!0),R.hD);return()=>clearTimeout(n)},[e]),e&&n}(o.isPending&&void 0===o.data);return o.isError||null===o.data?(0,a.jsx)(T,{headingId:t,heading:n.heading,message:"Couldn't load your profile.",onRetry:()=>void o.refetch(),isRetrying:o.isFetching}):void 0===o.data?(0,a.jsxs)("section",{"aria-labelledby":t,"aria-busy":c||void 0,className:"flex flex-col gap-4",children:[(0,a.jsx)(P,{headingId:t,children:n.heading}),c?(0,a.jsxs)("div",{className:"space-y-4","data-testid":"profile-skeleton",children:[(0,a.jsx)(s.EA,{animationType:"none",className:"h-10 w-10 rounded-full"}),(0,a.jsx)(s.EA,{animationType:"none",className:"h-4 w-1/2 rounded-md"}),(0,a.jsx)(s.EA,{animationType:"none",className:"h-4 w-2/3 rounded-md"})]}):null]}):(0,a.jsx)(L,{me:o.data,heading:n.heading,headingId:t,onDirtyChange:l})},connections:function(e){var n,t,i,l,o,c,d;let{section:u,headingId:m,onConfirmationChange:h}=e,p=(0,el.useRouter)(),g=(0,nv.sK)(),f=(0,nv.of)(),x=(null==(n=(0,ew.NL)().data)?void 0:n.status)==="canceled",v=(0,nk.gt)({connectEnabled:!x}),y=(0,ew.y)(),b=(0,W.NK)(e=>e.activeOrgId),{orgBrands:j,scopedOrgId:w}=(0,r.useMemo)(()=>{var e;let n=null!=(e=y.data)?e:[],t=new Set(n.map(e=>e.organizationId)),a=null!=b?b:1===t.size?[...t][0]:null;return{scopedOrgId:a,orgBrands:a?n.filter(e=>e.organizationId===a):[]}},[y.data,b]),N=null==w?"unresolved":0===j.length?"no-brand":void 0,[k,C]=(0,r.useState)(null),[E,S]=(0,r.useState)(null),R=(0,r.useRef)(null),I=g.isPending&&void 0===g.data,A=f.isPending&&void 0===f.data,P=y.isPending&&void 0===y.data,D=ny(I||A||P),{onGmailDisconnect:L}=function(e){let n=(0,nv.O2)(),t=(0,nv.cD)(),a=(0,r.useRef)(new Set);return(0,r.useEffect)(()=>{for(let n of e){if(a.current.has(n.senderAccountId))continue;a.current.add(n.senderAccountId);let e=nb(n.undoUntil);if(e<=0)continue;let r=(0,nd.oR)("".concat(n.senderEmail," disconnected"),{timeout:e,actionProps:{children:"Undo",onPress:async()=>{try{await t.mutateAsync(n.senderAccountId),nd.oR.close(r)}catch(e){nd.oR.danger("Could not undo. Try again.")}}}})}},[e,t]),{onGmailDisconnect:(0,r.useCallback)(async(e,r)=>{try{let{undoUntil:s}=await n.mutateAsync(e);a.current.add(e);let i=(0,nd.oR)("".concat(r," disconnected"),{timeout:nb(s),actionProps:{children:"Undo",onPress:async()=>{try{await t.mutateAsync(e),nd.oR.close(i)}catch(e){nd.oR.danger("Could not undo. Try again.")}}}})}catch(e){nd.oR.danger("Could not disconnect. Try again.")}},[n,t])}}(null!=(t=f.data)?t:[]);return g.isError&&void 0===g.data||f.isError&&void 0===f.data?(0,a.jsx)(T,{heading:u.heading,headingId:m,message:"Couldn't load connections. Try again.",isRetrying:g.isFetching||f.isFetching,onRetry:()=>{g.refetch(),f.refetch()}}):(0,a.jsxs)("section",{"aria-labelledby":m,className:"flex flex-col gap-4",children:[(0,a.jsx)("h2",{id:m,tabIndex:-1,className:"text-base font-medium text-foreground outline-none",children:u.heading}),D?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.EA,{className:"h-16 w-full"}),(0,a.jsx)(s.EA,{className:"h-16 w-full"})]}):(0,a.jsxs)(a.Fragment,{children:[(null!=(i=g.data)?i:[]).map(e=>(0,a.jsx)(eB,{provider:"gmail",label:"Gmail",description:"reconnect_required"===e.status?"Reconnect ".concat(e.senderEmail):"Connected as ".concat(e.senderEmail),connected:!0,planCanceled:x,onDisconnect:()=>void L(e.senderAccountId,e.senderEmail),onConnect:()=>C({provider:"gmail"})},"gmail-".concat(e.senderAccountId))),(null!=(l=f.data)?l:[]).map(e=>(0,a.jsx)(eB,{provider:"gmail",label:"Gmail",description:"".concat(e.senderEmail," disconnected"),connected:!1,planCanceled:x,onConnect:()=>C({provider:"gmail"})},"gmail-pending-".concat(e.senderAccountId))),0===(null!=(o=g.data)?o:[]).length&&0===(null!=(c=f.data)?c:[]).length?(0,a.jsx)(eB,{provider:"gmail",label:"Gmail",description:"Not connected",connected:!1,planCanceled:x,onConnect:()=>C({provider:"gmail"})}):null,(0,a.jsx)(eY,{planCanceled:x}),(0,a.jsx)(eB,{provider:"instagram",label:"Instagram",description:"Not connected",connected:!1,planCanceled:x,connectLabel:"Connect in chat",onConnect:()=>p.push((0,nC.sQ)("instagram"))}),(0,a.jsx)(eB,{provider:"tiktok",label:"TikTok",description:"Not connected",connected:!1,planCanceled:x,connectLabel:"Connect in chat",onConnect:()=>p.push((0,nC.sQ)("tiktok"))}),(0,a.jsx)(ns,{brands:j,orgId:w,idle:N,planCanceled:x,onConnect:e=>C({provider:"tiktok",brandId:e})}),(0,a.jsx)(nN,{planCanceled:x})]}),(0,a.jsx)(ez,{provider:null!=(d=null==k?void 0:k.provider)?d:null,error:E,onClose:()=>C(null),onConfirm:()=>{if(k){if(S(null),"gmail"===k.provider)v.continueToGoogle();else{var e;null==(e=R.current)||e.call(R)}C(null)}},onConfirmationChange:h}),(null==k?void 0:k.provider)==="tiktok"&&k.brandId?(0,a.jsx)(nc,{brandId:k.brandId,startRef:R}):null]})},billing:function(e){var n,t;let r=(0,W.NK)(e=>e.activeOrgId),{data:s}=(0,X.useSession)();return(0,a.jsx)(eS,{...e},"".concat(null==s||null==(n=s.user)?void 0:n.id,":").concat(r,":").concat(null!=(t=e.billingContextKey)?t:""))},usage:function(e){let{headingId:n}=e,t=(0,W.NK)(e=>e.activeOrgId);return(0,a.jsx)(eq,{headingId:n},t)},data:function(e){let{section:n,headingId:t,onConfirmationChange:s}=e,{metadata:l,quote:o,latest:c,pending:d,showSkeleton:u,job:m,archives:h,cooldownJob:p,running:f,cooldown:x,disabled:v,start:b,download:j,problem:w,retryAfterSeconds:N}=function(){var e,n,t,a,s,l;let o=null==(e=(0,i.yj)().data)?void 0:e.id,c=(0,W.NK)(e=>e.activeOrgId),d=(0,_.jE)(),u=["account-export",o,"latest"],m=(0,F.I)({queryKey:["account-export",o,"metadata"],queryFn:()=>Q.metadata(),enabled:!!o,retry:!1,refetchOnMount:"always",gcTime:1/0}),h=(0,F.I)({queryKey:["account-export",o,c,"quote"],queryFn:()=>Q.quote(),enabled:!!o,retry:!1,refetchOnMount:"always",gcTime:1/0}),p=(0,F.I)({queryKey:u,queryFn:()=>Q.latest(),enabled:!!o,retry:!1,refetchOnMount:"always",gcTime:1/0,refetchInterval:e=>{var n,t,a;return!!["pending","processing"].includes(null!=(a=null==(t=e.state.data)||null==(n=t.job)?void 0:n.status)?a:"")&&2e3}}),[f,x]=(0,r.useState)(null),[v,y]=(0,r.useState)(null),[b,j]=(0,r.useState)(null),w=(0,r.useRef)(!1),N=(0,r.useRef)(null),[k,C]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=setTimeout(()=>C(!0),R.hD);return()=>{clearTimeout(e)}},[]);let E=null==(n=p.data)?void 0:n.job,S=null==(t=p.data)?void 0:t.lastSettledJob,I=[E,S].filter((e,n,t)=>!!e&&["ready","expired"].includes(e.status)&&t.findIndex(n=>(null==n?void 0:n.id)===e.id)===n),[A,T]=(0,r.useState)(Date.now),[P,D]=(0,r.useState)(null),L=p.refetch;(0,r.useEffect)(()=>{var e,n;let t=[null==(e=p.data)?void 0:e.job,null==(n=p.data)?void 0:n.lastSettledJob].flatMap(e=>{var n;return[null==e?void 0:e.nextExportAt,null==e?void 0:e.archiveExpiresAt,null==e||null==(n=e.currentGrant)?void 0:n.expiresAt]}).flatMap(e=>e?[Date.parse(e)]:[]).concat(null===P?[]:[P]).filter(e=>e>A);if(!t.length)return;let a=setTimeout(()=>{T(Date.now()),L()},Math.max(1,Math.min(...t)-Date.now()));return()=>clearTimeout(a)},[p.data,A,L,P]),(0,r.useEffect)(()=>{(null==E?void 0:E.attemptId)===(null==v?void 0:v.attemptId)&&(y(null),j(null))},[null==E?void 0:E.attemptId,null==v?void 0:v.attemptId]);let q=(null==E?void 0:E.status)==="pending"||(null==E?void 0:E.status)==="processing",U=[E,S].find(e=>{var n;return(null==e?void 0:e.nextExportAt)&&Date.parse(e.nextExportAt)>A&&e.organizationId===(null==(n=h.data)?void 0:n.organizationId)}),M=!!U,z=void 0===h.data||h.isError||h.isFetching||!!f||q&&E.organizationId===(null==(a=h.data)?void 0:a.organizationId)||M||null!==P&&P>A||!!v;async function K(e,n){if(w.current||null!==P&&P>Date.now())return;w.current=!0;let t=null!=n?n:{format:e,attemptId:crypto.randomUUID()};x("start"),j(null);try{let e=await Q.start(t);await d.cancelQueries({queryKey:u,exact:!0}),d.setQueryData(u,{job:e,lastSettledJob:null!=S?S:null}),y(null)}catch(r){var a;let e=(0,g.Y3)(r),n=function(e){let n=O.Ik({response:O.Ik({status:O.eu(429),data:O.Ik({retryAfterSeconds:O.ai().int().positive()})})}).safeParse(e instanceof Error?e.cause:void 0);return n.success?n.data.response.data.retryAfterSeconds:void 0}(r);void 0!==n&&(T(Date.now()),D(Date.now()+1e3*n)),y(!e||e>=500?t:null),j({message:null!=(a=(0,g.VR)(r))?a:"Could not confirm your export. Retry the request.",action:"start"}),p.refetch()}finally{w.current=!1,x(null)}}async function B(e){var n,t,a;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"download";if(w.current)return;w.current=!0,x("download"),j(null);let s="issue";try{let a="download"===r?e.currentGrant:null;a&&(null==(n=N.current)?void 0:n.id)===e.id&&(N.current=null),a||(("new-link"===r||(null==(t=N.current)?void 0:t.id)!==e.id)&&(N.current={id:e.id,key:crypto.randomUUID()}),a=await Q.issue(e.id,N.current.key),N.current=null,await p.refetch()),"download"===r&&(s="download",await Q.saveArchive(a))}catch(n){j({message:null!=(a=(0,g.VR)(n))?a:"Could not complete the download request. Try again.",action:s,archive:e})}finally{await p.refetch(),w.current=!1,x(null)}}async function G(){(await h.refetch()).isError||j(null)}let Y=b?{heading:"start"!==b.action?"Download failed":"Export request failed",message:b.message,retry:()=>"issue"===b.action&&b.archive?void B(b.archive,"retry-issuance"):"download"===b.action?void p.refetch():v?void K(v.format,v):void G()}:h.isError?{heading:"Export price unavailable",message:null!=(l=(0,g.VR)(h.error))?l:"Could not load the export price. Try again.",retry:()=>void h.refetch()}:(null==E?void 0:E.status)==="failed"?{heading:"Export failed",message:(null==(s=E.error)?void 0:s.code)==="ACCOUNT_EXPORT_TOO_LARGE"?"This archive exceeds the 32 MB limit. No tokens were charged.":"Your export could not be prepared. No tokens were charged.",retry:()=>void K(E.format)}:p.isError?{heading:"Progress unavailable",message:"Could not refresh your export. Try again.",retry:()=>void p.refetch()}:m.isError?{heading:"Data refresh failed",message:"Showing your last loaded counts. Try refreshing again.",retry:()=>void m.refetch()}:null;return{metadata:m,quote:h,latest:p,pending:f,showSkeleton:k,job:E,archives:I.map(e=>{var n;return{...e,linkExpiredOrFailed:e.linkExpiredOrFailed||(null==b?void 0:b.action)==="download"&&(null==(n=b.archive)?void 0:n.id)===e.id}}),cooldownJob:U,running:q,cooldown:M,disabled:z,start:K,download:B,problem:Y,retryAfterSeconds:(null==b?void 0:b.action)==="start"&&null!==P?Math.max(0,Math.ceil((P-A)/1e3)):void 0}}(),k=void 0!==l.data&&void 0!==c.data,E=(0,r.useRef)(!1);(k||l.isError||c.isError)&&(E.current=!0);let S=(0,a.jsxs)("div",{className:"flex flex-col gap-3 border-t border-border py-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Delete account"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Permanently delete your account and sign out everywhere. Shared organizations and their other members are unaffected."})]}),(0,a.jsx)(ea,{onConfirmationChange:s})]});return l.isError&&void 0===l.data||c.isError&&void 0===c.data?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(T,{heading:n.heading,headingId:t,message:"Could not load your data. Try again.",isRetrying:l.isFetching||c.isFetching,onRetry:()=>{l.refetch(),c.refetch()}}),S]}):(0,a.jsxs)("section",{"aria-labelledby":t,"aria-busy":!k&&u||void 0,className:"flex flex-col gap-4",children:[(0,a.jsx)("h2",{id:t,tabIndex:-1,
1className:"text-base font-medium text-foreground outline-none",children:n.heading}),k?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 py-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Export data"}),(0,a.jsxs)("p",{className:"text-sm text-muted-foreground",children:[l.data.counts.campaigns.toLocaleString()," campaigns \xb7"," ",l.data.counts.creators.toLocaleString()," creators \xb7"," ",l.data.counts.agreements.toLocaleString()," agreements \xb7"," ",l.data.counts.receipts.toLocaleString()," receipts"]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Includes your account and communication history."}),void 0===o.data||o.isError?null:(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:o.data.chargeRequired?"".concat(o.data.tokenAmount.toLocaleString()," tokens ($").concat(o.data.displayUsd.toFixed(2),") per export"):"Included in your plan"})]}),(0,a.jsxs)(q.ms,{children:[(0,a.jsx)(y.$n,{variant:"ghost",isDisabled:v,isPending:"start"===d,children:h.some(e=>"expired"===e.status||!e.archiveAvailable||e.downloadIssued&&0===e.reissuesRemaining)?"Start a new export":"Export"}),(0,a.jsx)(q.ms.Popover,{children:(0,a.jsx)(q.ms.Menu,{"aria-label":"Export format",onAction:e=>{("json"===e||"csv"===e||"md"===e)&&b(e)},children:Object.entries(er).map(e=>{let[n,t]=e;return(0,a.jsx)(q.ms.Item,{id:n,textValue:t,children:(0,a.jsx)(C.JU,{children:t})},n)})})})]})]}),f&&m?(0,a.jsxs)("p",{role:"status",className:"text-sm text-muted-foreground",children:[er[m.format]," \xb7 ",es[m.stage]," \xb7"," ",m.recordsProcessed.toLocaleString()," records"]}):null,h.map(e=>(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[e.platformFailureCredited?(0,a.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:"Your archive is unavailable. We credited 200,000 tokens to your organization."}):null,"expired"===e.status?(0,a.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:void 0===o.data||o.isError?"This export has been removed after 7 days.":o.data.chargeRequired?"This export has been removed after 7 days. Start a new export ($5, 1 per day).":"This export has been removed after 7 days. Start a new export, included in your plan."}):e.archiveAvailable?(0,a.jsxs)(a.Fragment,{children:[e.linkExpiredOrFailed&&e.reissuesRemaining>0?(0,a.jsxs)("p",{role:"status",className:"text-sm text-muted-foreground",children:["Your link expired or the download didn't finish. Your export is still ready until"," ",new Date(e.archiveExpiresAt).toLocaleString(),"; get a new link (",e.reissuesRemaining," of 3 left). You won't be charged again."]}):(0,a.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Available until"," ",new Date(e.archiveExpiresAt).toLocaleString(),e.downloadIssued&&0===e.reissuesRemaining?". No replacement links remain.":""]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[e.currentGrant||!e.downloadIssued?(0,a.jsxs)(y.$n,{variant:"secondary",onPress:()=>void j(e),isDisabled:!!d,isPending:"download"===d,children:["Download ",er[e.format]]}):null,e.downloadIssued&&e.reissuesRemaining>0?(0,a.jsx)(y.$n,{variant:"secondary",onPress:()=>void j(e,"new-link"),isDisabled:!!d,isPending:"download"===d,children:"Get a new link"}):null]})]}):(0,a.jsx)("p",{role:"status",className:"text-sm text-muted-foreground",children:"Start a new export when available."})]},e.id)),x&&p?(0,a.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Next export:"," ",new Date(p.nextExportAt).toLocaleString()]}):null,w?(0,a.jsx)(T,{heading:w.heading,message:w.message,onRetry:w.retry,retryAfterSeconds:N,isRetrying:!!d||o.isFetching||c.isFetching}):null]}):u?(0,a.jsx)(ei,{}):null,E.current?S:null]})}}},62178:(e,n,t)=>{t.d(n,{V:()=>s,default:()=>i});var a=t(54568),r=t(24560);let s="storika-appearance";function i(e){let{children:n}=e;return(0,a.jsx)(r.N,{attribute:"class",defaultTheme:"system",enableSystem:!0,storageKey:s,children:n})}},62346:(e,n,t)=>{t.d(n,{F1:()=>m,WI:()=>u,dq:()=>d,jY:()=>h});var a=t(27736),r=t(4869),s=t(81562);t(7620),t(40973);var i=t(73648),l=t(8972);let o=["payment-method"],c=["invoices"],d=3e4;function u(){let e=(0,l.NK)(e=>e.activeOrgId);return(0,a.I)({queryKey:[...c,e],queryFn:()=>i.A.getInvoices(),staleTime:d,retry:!1})}let m=e=>["campaigns",e,"payment-rows"];function h(){var e;let{enabled:n=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=(0,r.jE)(),c=(0,l.NK)(e=>e.activeOrgId),u=(0,a.I)({queryKey:[...o,c],queryFn:()=>i.A.getPaymentMethod(),enabled:n,staleTime:d}),m=(0,s.n)({mutationFn:()=>i.A.removePaymentMethod(),onSuccess:()=>{t.invalidateQueries({queryKey:o})}});return{card:null!=(e=u.data)?e:null,isLoading:u.isLoading,isFetching:u.isFetching,isError:u.isError,error:u.error,refetch:u.refetch,removePaymentMethod:m.mutate,isRemoving:m.isPending}}},64605:(e,n,t)=>{t.d(n,{A:()=>l,K:()=>s});var a=t(45855),r=t(91618);function s(e){let n=(0,r.Y3)(e),t=(0,r.Pl)(e);return 409===n&&"SIGNUP_CONSENT_NOT_REQUIRED"===t?"not_required":402===n&&"SIGNUP_CARD_REQUIRED"===t?"card_required":503===n&&"SIGNUP_ELIGIBILITY_UNAVAILABLE"===t?"eligibility_unavailable":409===n&&"SIGNUP_TERMS_CHANGED"===t?"terms_changed":null}class i extends a.Ay{async verifyCheckoutSession(e){return this.httpRequired.post("/stripe/verify-checkouts?session_id=".concat(e))}async checkSubscriptionStatus(){return this.http.get("/subscriptions")}async createSignupSetupIntent(e,n){let t=e||n?{...e?{plan:e}:{},...n?{replacementNonce:n}:{}}:void 0;return this.httpRequired.post("/stripe/signup-setup-intent",t)}async createSignupSubscriptionConsent(e){return this.httpRequired.post("/stripe/signup-subscription-consent",e)}
1async createPortalSession(){return this.httpRequired.post("/stripe/create-portal-sessions",{})}async resumeSubscription(e){return this.httpRequired.post("/subscriptions/resume",void 0===e?{}:{expectedSubscriptionId:e})}async cancelSubscription(e){return this.httpRequired.post("/subscriptions/cancel",void 0===e?{}:{expectedSubscriptionId:e})}async reinstateSubscription(){return this.httpRequired.post("/subscriptions/reinstate",{confirm:!0})}}let l=new i},65152:(e,n,t)=>{t.d(n,{Z:()=>a});function a(e){let n=new URLSearchParams;for(let[t,a]of Object.entries(e))if(null!=a)if(Array.isArray(a))for(let e of a)n.append(t,String(e));else n.append(t,String(a));let t=n.toString();return t?"?".concat(t):""}},73626:(e,n,t)=>{t.d(n,{gt:()=>h});var a=t(7620),r=t(27541),s=t(4869),i=t(45288),l=t(38205),o=t(25347),c=t(91618),d=t(85406);let u={access_denied:{kind:"declined",title:"Gmail wasn't connected",description:"You declined access, so we could not connect your inbox. You can try again, or keep sending from your Storika address for now."},session_expired:{kind:"expired",title:"Your sign-in timed out",description:"The connection took too long to finish. Start again and it should go through."},invalid_grant:{kind:"reconsent",title:"We need full permission",description:"Google didn't grant everything we need to send on your behalf. Reconnect and allow all the requested permissions."},no_refresh_token:{kind:"reconsent",title:"One more permission needed",description:"Google didn't return lasting access, usually because Gmail was already linked. Reconnect and choose your account to allow it again."},oauth_error:{kind:"failure",title:"Couldn't connect Gmail",description:"Something went wrong while connecting your Gmail. Try again in a moment."}},m=u.oauth_error;function h(e){let{connectEnabled:n,returnDestination:t}=e,h=(0,s.jE)(),p=(0,r.useRouter)(),g=(0,r.useSearchParams)(),f=(0,l.Sc)(),x=(0,a.useRef)(null),v=(0,a.useRef)(null),y=(0,a.useRef)(null),[b,j]=(0,a.useState)(!1),[w,N]=(0,a.useState)(!1),[k,C]=(0,a.useState)(!1),[E,S]=(0,a.useState)(null),R=(0,a.useCallback)(()=>{null!=y.current&&(y.current(),y.current=null)},[]);(0,a.useEffect)(()=>R,[R]);let I=(0,a.useCallback)(e=>{var n,t;if(R(),null==(n=x.current)||n.close(),x.current=null,"connected"===e.status){i.oR.success(e.email?"".concat(e.email," connected. Campaigns can now send from it."):"Gmail connected. Campaigns can now send from it."),h.invalidateQueries({queryKey:o.D.senderAccounts});return}S((t=e.code)&&t in u?u[t]:m),C(!0)},[h,R]);(0,a.useEffect)(()=>{let e=e=>{x.current&&e&&"storika:gmail-connect"===e.type&&e.flow===v.current&&I({status:e.status,code:e.code,email:e.email})},n=n=>{n.origin===window.location.origin&&e(n.data)};window.addEventListener("message",n);let t=null;try{let n=t=new BroadcastChannel("storika-gmail-connect");n.onmessage=t=>{let a=t.data;if((null==a?void 0:a.type)==="storika:gmail-popup-ping"){if(x.current&&a.flow===v.current)try{var r;n.postMessage({type:"storika:gmail-opener-ack",flow:null!=(r=a.flow)?r:null})}catch(e){}return}e(a)}}catch(e){}return()=>{window.removeEventListener("message",n),null==t||t.close()}},[I]),(0,a.useEffect)(()=>{var e,n;let t=g.get("gmail_connected"),a=g.get("gmail_error");if(!t&&!a)return;I({status:"1"===t?"connected":"error",code:null!=(e=g.get("gmail_error_code"))?e:void 0,email:null!=(n=g.get("gmail_email"))?n:void 0});let r=new URL(window.location.href);for(let e of["gmail_connected","gmail_error","gmail_error_code","gmail_email","sender_account_id"])r.searchParams.delete(e);p.replace(r.pathname+r.search,{scroll:!1})},[]);let A=(0,a.useCallback)(async()=>{var e;null==(e=x.current)||e.close(),x.current=null;try{let e=(0,d.P)();v.current=e;let n="".concat(window.location.origin).concat("/gmail-connected","/").concat(e),a=t?"".concat(n,"?returnTo=").concat(encodeURIComponent(t)):n,{url:r}=await f.mutateAsync(a),s=window.open(r,"storika-gmail-oauth","popup=yes,width=520,height=640");s?(x.current=s,R(),y.current=(0,d.f)(s,()=>{x.current===s&&(x.current=null,v.current=null,(0,i.oR)("Gmail connection canceled - nothing was changed."))})):window.location.href=r}catch(e){if("GMAIL_CONNECT_PLAN_LOCKED"===(0,c.Pl)(e))return void N(!0);i.oR.error("Couldn't start the Gmail connection. Try again.")}},[f,R,t]),T=(0,a.useCallback)(()=>
1{if(!n)return void N(!0);j(!0)},[n]),P=(0,a.useCallback)(()=>{j(!1),A()},[A]),D=(0,a.useCallback)(()=>{C(!1),A()},[A]);return{startConnect:T,explainerOpen:b,setExplainerOpen:j,continueToGoogle:P,upsellOpen:w,setUpsellOpen:N,resultOpen:k,setResultOpen:C,resultCopy:E,retryConnect:D}}},73648:(e,n,t)=>{t.d(n,{A:()=>s});var a=t(45855);class r extends a.Ay{async getPaymentRows(e){return this.httpRequired.get("/campaigns/".concat(e,"/payment-rows"))}async stagePayout(e,n){return this.httpRequired.post("/campaigns/".concat(e,"/results/").concat(n,"/payout/stage"))}async unstagePayout(e,n){return this.httpRequired.post("/campaigns/".concat(e,"/results/").concat(n,"/payout/unstage"))}async createOnboardingLink(e,n){return this.httpRequired.post("/campaigns/".concat(e,"/results/").concat(n,"/connect/onboarding-link"))}async getConnectStatus(e,n){return this.httpRequired.get("/campaigns/".concat(e,"/results/").concat(n,"/connect/status"))}async getCea(e,n){return this.httpRequired.get("/campaigns/".concat(e,"/results/").concat(n,"/cea"))}async acceptCea(e,n,t,a,r,s){return this.httpRequired.post("/campaigns/".concat(e,"/results/").concat(n,"/cea/accept"),{ceaContentHash:t,ceaVersion:a,agreedAmountMinor:r,currency:s})}async createCeaLink(e,n){return this.httpRequired.post("/campaigns/".concat(e,"/results/").concat(n,"/cea/link"))}async sendCeaEmail(e,n,t){let a=(null==t?void 0:t.force)?"?force=true":"";return this.httpRequired.post("/campaigns/".concat(e,"/results/").concat(n,"/cea/send").concat(a))}async getResultCeaTerms(e,n){return this.httpRequired.get("/campaigns/".concat(e,"/results/").concat(n,"/cea-terms"))}async updateResultCeaTerms(e,n,t){return this.httpRequired.put("/campaigns/".concat(e,"/results/").concat(n,"/cea-terms"),t)}async getCampaignCeaTerms(e){return this.httpRequired.get("/campaigns/".concat(e,"/cea-terms"))}async updateCampaignCeaTerms(e,n){return this.httpRequired.put("/campaigns/".concat(e,"/cea-terms"),n)}async createSetupIntent(){return this.httpRequired.post("/stripe/setup-intent")}async getPaymentMethod(){return this.http.get("/stripe/payment-method")}async getInvoices(){return this.httpRequired.get("/stripe/invoices")}async prepareInvoicePayment(e){let n=new URLSearchParams;(null==e?void 0:e.invoiceId)&&n.set("invoiceId",e.invoiceId),(null==e?void 0:e.returnTo)&&n.set("returnTo",e.returnTo);let t=n.toString();return this.httpRequired.get("/stripe/invoices/payment".concat(t?"?".concat(t):""))}async payInvoice(e){return this.httpRequired.post("/stripe/invoices/".concat(e,"/pay"),{})}async verifyInvoiceReturn(e){return this.httpRequired.post("/stripe/invoices/verify-return",e)}async removePaymentMethod(){return this.httpRequired.delete("/stripe/payment-method")}async syncPayoutAmounts(e){return this.httpRequired.post("/campaigns/".concat(e,"/payout-amounts/sync"))}async updatePayoutAmount(e,n,t,a){return this.httpRequired.patch("/campaigns/".concat(e,"/results/").concat(n,"/payout-amount"),{amountMinor:t,currency:a})}async upsertBrandApproval(e,n,t){return this.httpRequired.put("/campaigns/".concat(e,"/results/").concat(n,"/brand-approval"),{approvedAt:t})}async getPayoutBudget(e){return this.httpRequired.get("/campaigns/".concat(e,"/payout-budget"))}}let s=new r},75539:(e,n,t)=>{t.d(n,{N:()=>a});function a(e){let{name:n,email:t}=e;return(null==n?void 0:n.trim())||t}},77074:(e,n,t)=>{t.d(n,{HX:()=>a,Yn:()=>o,fg:()=>s,hD:()=>r,iv:()=>i});let a=[{id:"profile",label:"Profile",heading:"Profile"},{id:"connections",label:"Connections",heading:"Connections"},{id:"billing",label:"Plan and billing",heading:"Plan and billing"},{id:"usage",label:"Usage",heading:"Usage"},{id:"data",label:"Data",heading:"Data"}],r=300,s="(max-width: 640px)",i="data-settings-close",l=["returnTo","tab","return"];function o(e){let n;if(null===e||0===e.length||!e.startsWith("/")||e.startsWith("//")||e.includes("..")||e.includes("\\")||/^[a-z][a-z0-9+.-]*:/i.test(e))return null;try{n=new URL(e,"http://settings.local")}catch(e){return null}if("http://settings.local"!==n.origin||"/chat"!==n.pathname)return null;for(let e of l)if(n.searchParams.has(e))return null;return e}},83020:(e,n,t)=>{function a(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e)}function r(e){let n=e/4e4;
1return"$".concat(n.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:2*!Number.isInteger(n)}))}function s(e){let n=e/100,t=Number.isInteger(n);return"$".concat(n.toLocaleString(void 0,{minimumFractionDigits:2*!t,maximumFractionDigits:2*!t}))}function i(e){return e+Math.max(1e4,Math.ceil(.2*e))}t.d(n,{HG:()=>s,Md:()=>i,O_:()=>r,Rk:()=>a})},85406:(e,n,t)=>{function a(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"".concat(Math.random().toString(36).slice(2)).concat(Date.now().toString(36))}function r(e,n){let t=null,a=()=>{null!=t&&(window.clearInterval(t),t=null)};return t=window.setInterval(()=>{e.closed&&(a(),window.setTimeout(n,1500))},1e3),a}t.d(n,{P:()=>a,f:()=>r})},87627:(e,n,t)=>{t.d(n,{E:()=>s,n:()=>l});var a=t(7620);let r=new Set;function s(){r.forEach(e=>e())}async function i(e){try{return await fetch("".concat("/storika_mark_orange.svg","?connectivity=").concat(Date.now()),{method:"HEAD",cache:"no-store",signal:e}),!0}catch(e){return!1}}function l(){let[e,n]=a.useState(!0);return a.useEffect(()=>{let e=null,t=null,a=!1,s=()=>{null==e||e.abort(),e=null,null!==t&&(clearInterval(t),t=null)},l=()=>{s(),n(!0)},o=async()=>{if(navigator.onLine)return void l();null==e||e.abort();let t=new AbortController;e=t;let r=await i(t.signal);a||t.signal.aborted||n(r)},c=()=>{null===t&&(o(),t=setInterval(()=>void o(),3e4))};navigator.onLine||c();let d=()=>void o();return r.add(d),window.addEventListener("online",l),window.addEventListener("offline",c),()=>{a=!0,s(),r.delete(d),window.removeEventListener("online",l),window.removeEventListener("offline",c)}},[]),e}},89746:(e,n,t)=>{t.d(n,{l:()=>c});var a=t(7620),r=t(27736),s=t(96006),i=t(73648),l=t(48395),o=t(56952);function c(e){var n,t,c,d;let{data:u}=(0,s.useSession)(),m=(0,o.NL)({retry:!1}),h=(0,l.YO)(null==(n=m.data)?void 0:n.status),p=(null==(c=e.enabled)||c)&&!!u&&h,g=(0,r.I)({queryKey:["invoice-payment-preparation",e.returnTo],queryFn:()=>i.A.prepareInvoicePayment({returnTo:e.returnTo}),enabled:p,staleTime:3e4,retry:!1}),f=null!=(d=null==(t=g.data)?void 0:t.invoice)?d:null,[x,v]=(0,a.useState)(!1),[y,b]=(0,a.useState)(null),j=async()=>{if(!f||x)return"unresolved";v(!0),b(null);try{let e=await i.A.payInvoice(f.invoiceId);if("paid"===e.status)return"paid";if(f.hostedInvoiceUrl)return window.location.assign(f.hostedInvoiceUrl),"redirected";return b("That payment needs another step. Update your card to finish."),"unresolved"}catch(e){return b("That payment did not go through. Try again or update your card."),"unresolved"}finally{v(!1)}};return{pastDue:h,invoice:f,isPreparing:p&&g.isPending,isPaying:x,error:y,pay:j}}},90546:(e,n,t)=>{t.d(n,{U:()=>r});var a=t(7620);function r(e){let[n,t]=a.useState(()=>"function"==typeof matchMedia&&matchMedia(e).matches);return a.useEffect(()=>{function n(e){t(e.matches)}let a=matchMedia(e);return a.addEventListener("change",n),t(a.matches),()=>a.removeEventListener("change",n)},[e]),n}},94409:(e,n,t)=>{t.d(n,{bB:()=>v});var a=t(54568),r=t(7620),s=t(96006),i=t(28689),l=t(86630),o=t(25472),c=t(90546),d=t(56952),u=t(33713),m=t(12677),h=t(77074),p=t(51526);function g(e){let{current:n,isSheet:t,onSectionChange:s,onPanelBindingChange:l}=e,o=(0,r.useRef)(null);return((0,r.useEffect)(()=>{var e,n,t;null==(t=o.current)||null==(n=t.querySelector('[role="tab"][aria-selected="true"]'))||null==(e=n.scrollIntoView)||e.call(n,{inline:"nearest",block:"nearest"})},[n,t]),(0,r.useLayoutEffect)(()=>{if(!l)return;if(!t)return void l(null);let e=o.current;if(!e)return;let n=()=>{let n=e.querySelector('[role="tab"][aria-selected="true"]'),t=null==n?void 0:n.getAttribute("aria-controls");l((null==n?void 0:n.id)&&t?{tabId:n.id,panelId:t}:null)};n();let a=new MutationObserver(n);return a.observe(e,{attributes:!0,attributeFilter:["aria-selected","aria-controls","id"],subtree:!0,childList:!0}),()=>a.disconnect()},[t,l]),t)?(0,a.jsx)(p.tU,{selectedKey:n,onSelectionChange:e=>{let t=h.HX.find(n=>n.id===e);t&&t.id!==n&&s(t.id)},keyboardActivation:"manual",variant:"secondary",className:"min-w-0",ref:o,children:(0,a.jsx)(p.tU.ListContainer,{className:"min-w-0",children:(0,a.jsx)(p.tU.List,{"aria-label":"Settings sections",className:"px-6 scroll-px-6",children:h.HX.map(e=>(0,a.jsxs)(p.tU.Tab,{id:e.id,className:"min-h-11 whitespace-nowrap",children:[e.label,(0,a.jsx)(p.tU.Indicator,{})]},e.id))})})}):(0,a.jsx)("nav",{"aria-label":"Settings sections",className:"sticky top-0 w-[9.375rem] self-start",children:(0,a.jsx)("ul",{className:"flex flex-col gap-0.5",children:h.HX.map(e=>{let t=e.id===n;return(0,a.jsx)("li",{children:(0,a.jsx)(i.N_,{"aria-current":t?"page":void 0,onPress:()=>{t||s(e.id)},className:t?"block whitespace-nowrap rounded-md bg-default px-2 py-1.5 text-sm text-foreground no-underline":"block whitespace-nowrap rounded-md px-2 py-1.5 text-sm text-muted-foreground no-underline hover:text-foreground",children:e.label})},e.id)})})})}function f(e){let{headingId:n}=e;return(0,a.jsxs)("section",{"aria-labelledby":n,className:"flex flex-col gap-4",children:[(0,a.jsx)("h2",{id:n,tabIndex:-1,
1className:"text-base font-medium text-foreground outline-none",children:"Sign in to open Settings"}),(0,a.jsx)(i.N_,{href:"/login",children:"Sign in"})]})}function x(e){let{headingId:n,onRequestClose:t}=e,s=(0,r.useSyncExternalStore)(u.jj,u.YQ,()=>"idle");return(0,a.jsxs)("section",{"aria-labelledby":n,className:"flex flex-col gap-4",children:[(0,a.jsx)("h2",{id:n,tabIndex:-1,className:"text-base font-medium text-foreground outline-none",children:"This workspace is closed"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"This workspace has been permanently closed and can't be restored."}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,a.jsx)(l.$n,{variant:"primary",isPending:"loading"===s,onPress:()=>{(0,u.tP)(),t()},children:"Contact support"}),(0,a.jsx)(i.N_,{href:"mailto:".concat(m.ei),className:"text-sm",children:m.ei})]}),"failed"===s?(0,a.jsxs)("p",{role:"alert",className:"text-sm text-muted-foreground",children:["Support chat couldn't load. Email us at ",m.ei,"."]}):null]})}function v(e){var n,t,i,u;let{isOpen:m,section:p,sections:v,onSectionChange:y,onClose:b,onOperationReceipt:j,onConfirmationChange:w,billingContextKey:N,billingWall:k,onAddCard:C}=e,E=(0,r.useId)(),S=(0,c.U)(h.fg),{status:R}=(0,s.useSession)(),[I,A]=(0,r.useState)(!1),[T,P]=(0,r.useState)(null),[D,L]=(0,r.useState)(!1),[q,_]=(0,r.useState)(!1),F=(0,r.useCallback)(e=>{_(e),null==w||w(e)},[w]),U=(0,r.useRef)(void 0),O=(0,r.useCallback)((e,n)=>{U.current=n,A(e)},[]);(0,r.useEffect)(()=>{if(!m)return;let e=requestAnimationFrame(()=>{var e;null==(e=document.getElementById(E))||e.focus()});return()=>cancelAnimationFrame(e)},[m,p,E]),(0,r.useEffect)(()=>{m||L(!1)},[m]);let M=(0,d.NL)({enabled:m&&"authenticated"===R,retry:!1}),z=!M.isError&&(null==(t=M.data)||null==(n=t.lifecycle)?void 0:n.closedViaCancellation)===!0,K=null!=(i=v[p])?i:v.profile,B=null!=(u=h.HX.find(e=>e.id===p))?u:h.HX[0],G=!S&&"unauthenticated"!==R&&!z;return(0,a.jsx)(o.aF,{isOpen:m,onOpenChange:e=>{e||(()=>{if(!q){if(I)return L(!0);b()}})()},children:(0,a.jsx)(o.aF.Backdrop,{isDismissable:!q,inert:q,children:(0,a.jsx)(o.aF.Container,{size:S?"full":"lg",placement:"center",scroll:"inside",children:(0,a.jsxs)(o.aF.Dialog,{"aria-labelledby":E,className:G?"h-[min(50rem,calc(100dvh-5rem))] w-full max-w-[62.5rem]":"w-full max-w-[62.5rem]",children:[(0,a.jsx)(o.aF.CloseTrigger,{"aria-label":"Back to chats",className:"size-11 items-center justify-center",[h.iv]:""}),(0,a.jsxs)(o.aF.Body,{className:"pt-10",children:[D?(0,a.jsxs)("div",{role:"alertdialog","aria-label":"Unsaved changes",className:"mb-4 flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface-secondary px-3 py-2",children:[(0,a.jsx)("p",{className:"text-sm text-foreground",children:"You have unsaved changes."}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(l.$n,{variant:"secondary",size:"sm",autoFocus:!0,onPress:()=>L(!1),children:"Keep editing"}),(0,a.jsx)(l.$n,{variant:"danger",size:"sm",onPress:()=>{var e;null==(e=U.current)||e.call(U),L(!1),A(!1),b()},children:"Discard"})]})]}):null,"unauthenticated"===R?(0,a.jsx)(f,{headingId:E}):z?(0,a.jsx)(x,{headingId:E,onRequestClose:b}):(0,a.jsxs)("div",{className:S?"flex flex-col gap-6":"grid grid-cols-[9.375rem_minmax(0,45rem)] gap-8",children:[(0,a.jsx)(g,{current:B.id,isSheet:S,onSectionChange:e=>{q||y(e)},onPanelBindingChange:P}),(0,a.jsx)("div",{className:"min-w-0",id:S?null==T?void 0:T.panelId:void 0,role:S&&T?"tabpanel":void 0,"aria-labelledby":S?null==T?void 0:T.tabId:void 0,children:(0,a.jsx)(K,{section:B,headingId:E,onDirtyChange:O,onConfirmationChange:F,onOperationReceipt:j,billingContextKey:N,billingWall:k,onAddCard:C},B.id)})]})]})]})})})})}}}]);

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.