PageSourceSearch

https://app.bubblegoods.com/assets/_shell.settings-CGnZRGAw.js

js bubblegoods.com collected 2026-09-25 19:51:30 UTC 49,991 bytes, 27 lines download raw bytes

1var Ze=Object.defineProperty;var et=(t,s,n)=>s in t?Ze(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var we=(t,s,n)=>et(t,typeof s!="symbol"?s+"":s,n);import{a as h,y as tt,w as st,v as nt,t as it}from"./chunk-OE4NN4TA-BenRlXdM.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{u as q}from"./auth-0DWDKJ4Q.js";import{t as _}from"./index-CREiFGB9.js";import{B as g}from"./button-CTa4yazt.js";import{C as K,b as z,c as Q,a as H,d as rt}from"./card-jWHuzOG8.js";import{I as P}from"./input-DpncSzF1.js";import{a as be,d as at,e as ot,b as Ee,f as ct}from"./utils-DUm1yI1Y.js";import{L as E}from"./label-BUqOJE26.js";import{R as lt}from"./rich-text-editor-BuBc8E8t.js";import{b as Be}from"./imagekit-_kkUnUVD.js";import{c as ae}from"./createLucideIcon-CAD-8-qT.js";import{M as dt}from"./map-pin-BZJOKPoD.js";import{p as ut,E as ke,U as De,F as mt,T as Oe}from"./external-text-link-BIh1HnWO.js";import{B as W}from"./badge-CH8DlUG6.js";import{D as Y,f as _e,a as V,b as J,c as X,d as Z,e as ee}from"./dialog-BIM9qI1e.js";import{S as pt,a as ht,b as xt,c as ft,d as jt}from"./select-BQq_BHoc.js";import{T as Me,a as $e,b as ie,c as B,d as Ke,e as D}from"./table-BgKSaZha.js";import{D as gt}from"./download-s6ch6R1w.js";import{b as yt,u as U}from"./types-DQ17uVlW.js";import{k,l as vt,u as oe}from"./badminton-CYrPzTfD.js";import{b as te,u as ze,a as bt}from"./use-brand-detail-1bx5sB31.js";import{C as _t}from"./check-CuIcivPN.js";import{X as St}from"./x-FDBsefeU.js";import{E as Qe,l as Nt,u as He,a as Ge,C as pe}from"./index-B_mB7Q9y.js";import{S as Ct}from"./separator-BLR1HbfZ.js";import{g as M}from"./posthog-CmwHPb0E.js";import{T as We}from"./triangle-alert-DJCNN_oB.js";import{S as me}from"./skeleton-DCAWwkWx.js";import{u as wt}from"./use-active-brand-Ch2dZB-K.js";import{g as ge}from"./errors-BWVSHThV.js";import"./index-DGUGZJKc.js";import"./external-link-BKyIHbB7.js";import"./index-QrAWYNvO.js";import"./index-BTANnojy.js";import"./index-yzV9GOu0.js";import"./index-2So3xZIN.js";import"./tslib.es6-De9GV7Vy.js";import"./index-DWcQMumL.js";import"./index-Cs6n0GbS.js";import"./index-5duchfgp.js";import"./brand-gateway-BsBZOcM3.js";import"./active-brand-provider-0xhB3gaj.js";/**
2 * @license lucide-react v0.469.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Et=ae("Camera",[["path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z",key:"1tc9qg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]);/**
7 * @license lucide-react v0.469.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const kt=ae("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]);/**
12 * @license lucide-react v0.469.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Ie=ae("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);/**
17 * @license lucide-react v0.469.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Dt=ae("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);/**
22 * @license lucide-react v0.469.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const Ft=ae("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]),Rt="Failed to upload document";function Pt(t){const s=new FormData;return s.append("file",t.file),s.append("document_type",t.documentType),t.expiresAt&&s.append("expires_at",t.expiresAt),t.issuedAt&&s.append("issued_at",t.issuedAt),t.issuedBy&&s.append("issued_by",t.issuedBy),s}async function Tt(t){const s=await k.GET("/api/brands/{brand_pub_id}/documents",{params:{path:{brand_pub_id:t}}});return yt(s).items??[]}async function qt(t,s){const n=Pt(s);vt("Badminton","#2563eb","POST","/api/brands/{brand_pub_id}/documents"),await ut(`https://sell.bubblegoods.com/api/brands/${t}/documents`,n,Rt)}async function Ut(t,s){const n=await k.DELETE("/api/brands/{brand_pub_id}/documents/{doc_pub_id}",{params:{path:{brand_pub_id:t,doc_pub_id:s}}});if(n.error)throw n.error}function Fe({icon:t,className:s,...n}){return e.jsxs("div",{className:"relative",children:[e.jsx(t,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(P,{className:be("pl-9",s),...n})]})}function ye(t){var s;return{name:t.name??"",description:t.description??"",website:((s=t.website)==null?void 0:s.replace(/^https?:\/\//,""))??"",location:t.location??"",profileImage:null}}const At=/,\s*[A-Z]{2}$/,Lt='Location must be in "City, ST" format (e.g. Brooklyn, NY)';function Re(t){return t&&!At.test(t)?Lt:null}function Bt({brand:t,previewFile:s,onFileSelect:n}){const i=h.useRef(null),r=h.useMemo(()=>s?URL.createObjectURL(s):null,[s]);h.useEffect(()=>()=>{r&&URL.revokeObjectURL(r)},[r]);const l=r||(t.profile_image?Be(t.profile_image):null);return e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:i,type:"file",accept:"image/jpeg,image/png,image/webp",onChange:a=>{var d;const m=(d=a.target.files)==null?void 0:d[0];m&&n(m)},className:"sr-only"}),e.jsxs("button",{type:"button",onClick:()=>{var a;return(a=i.current)==null?void 0:a.click()},className:"group relative h-16 w-16 shrink-0 cursor-pointer overflow-hidden rounded-full",children:[l?e.jsx("img",{src:l,alt:t.name??"",className:"h-full w-full object-cover"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-muted font-semibold text-muted-foreground text-xl",children:(t.name??"B").charAt(0).toUpperCase()}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/0 transition-colors group-hover:bg-black/40",children:e.jsx(Et,{className:"h-5 w-5 text-white opacity-0 transition-opacity group-hover:opacity-100"})})]})]})}function Ot({brand:t}){const s=t.profile_image?Be(t.profile_image):null;return e.jsx("div",{className:"h-16 w-16 shrink-0 overflow-hidden rounded-full",children:s?e.jsx("img",{src:s,alt:t.name??"",className:"h-full w-full object-cover"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-muted font-semibold text-muted-foreground text-xl",children:(t.name??"B").charAt(0).toUpperCase()})})}function Mt(t){return new DOMParser().parseFromString(t,"text/html").body.textContent??""}function $t({brand:t,editing:s,onEdit:n,onCancel:i,onSave:r,isSaving:l}){const[a,m]=h.useState(()=>ye(t)),[d,j]=h.useState(null),p=()=>{m(ye(t)),j(null),n()},y=()=>{m(ye(t)),j(null),i()},b=()=>{const x=Re(a.location);
26if(x){j(x);return}r({name:a.name,description:a.description||null,website:a.website?`https://${a.website.replace(/^https?:\/\//,"")}`:null,location:a.location||null,profileImage:a.profileImage})},f=h.useMemo(()=>t.description?Mt(t.description):null,[t.description]);return s?e.jsxs(K,{className:"h-full",children:[e.jsx(z,{children:e.jsx(Q,{children:"Brand Profile"})}),e.jsxs(H,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Bt,{brand:t,previewFile:a.profileImage,onFileSelect:x=>m({...a,profileImage:x})}),e.jsx("div",{className:"min-w-0 flex-1 space-y-2",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:"brand-name",children:"Name"}),e.jsx(P,{id:"brand-name",value:a.name,onChange:x=>m({...a,name:x.target.value}),maxLength:255})]})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"font-medium text-sm",children:"Description"}),e.jsx("div",{className:"overflow-hidden rounded-md border border-input ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",children:e.jsx(lt,{value:a.description,onChange:x=>m({...a,description:x}),placeholder:"Describe your brand..."})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:"brand-website",children:"Website"}),e.jsx(Fe,{icon:kt,id:"brand-website",value:a.website,onChange:x=>m({...a,website:x.target.value}),placeholder:"www.example.com",maxLength:255})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:"brand-location",children:"Location"}),e.jsx(Fe,{icon:dt,id:"brand-location",value:a.location,onChange:x=>{m({...a,location:x.target.value}),d&&j(null)},onBlur:()=>j(Re(a.location)),placeholder:"Brooklyn, NY","aria-describedby":"brand-location-hint","aria-invalid":!!d}),d&&e.jsx("p",{id:"brand-location-hint",className:"text-destructive text-xs",children:d})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(g,{variant:"outline",size:"sm",onClick:y,children:"Cancel"}),e.jsx(g,{size:"sm",onClick:b,disabled:l,children:l?"Saving...":"Save"})]})]})]}):e.jsxs(K,{className:"h-full",children:[e.jsxs(z,{className:"flex flex-row items-center justify-between",children:[e.jsx(Q,{children:"Brand Profile"}),e.jsx(g,{variant:"ghost",size:"icon",onClick:p,"aria-label":"Edit brand profile",children:e.jsx(Ie,{className:"h-4 w-4"})})]}
26),e.jsxs(H,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Ot,{brand:t}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium",children:t.name}),f&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-sm",children:f})]})]}),e.jsxs("dl",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("dt",{className:"font-medium text-muted-foreground text-xs uppercase tracking-wide",children:"Website"}),e.jsx("dd",{className:"text-sm",children:t.website?e.jsx("a",{href:t.website,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:t.website.replace(/^https?:\/\//,"")}):e.jsx("span",{className:"text-muted-foreground",children:"Not set"})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("dt",{className:"font-medium text-muted-foreground text-xs uppercase tracking-wide",children:"Location"}),e.jsx("dd",{className:"text-sm",children:t.location||e.jsx("span",{className:"text-muted-foreground",children:"Not set"})})]})]})]})]})}const $={w9:{label:"W-9",required:!0,requiresExpiration:!1},food_safety_cert:{label:"Facility Safety Certification",required:!0,requiresExpiration:!0},other:{label:"Other",required:!1,requiresExpiration:!1}},Pe=Object.keys($).filter(t=>$[t].required);function Kt({documents:t,isLoading:s,isError:n,uploadOpen:i,onUploadOpen:r,onUpload:l,isUploading:a,onDelete:m,isDeleting:d}){const[j,p]=h.useState("w9"),[y,b]=h.useState(null),[f,x]=h.useState(null),[v,C]=h.useState(""),[u,w]=h.useState(null),c=$[j].requiresExpiration,F=(()=>{const o=new Date;return o.setDate(o.getDate()+1),o.toLocaleDateString("en-CA")})(),O=!!v&&v>=F,ce=!!f&&!a&&(!c||O),xe=()=>{f&&(c&&!O||l(f,j,c?v:void 0))},le=o=>{w(o),m(o)},de=o=>{p(o??"w9"),b(o),x(null),C("")},fe=o=>{de(o),r(!0)},A=o=>{var R;return e.jsxs(ie,{children:[e.jsx(D,{children:e.jsx(W,{variant:"outline",children:((R=$[o.document_type])==null?void 0:R.label)??o.document_type})}),e.jsx(D,{className:"font-medium",children:o.filename}),e.jsx(D,{className:"text-muted-foreground",children:at(o.uploaded_at)}),e.jsx(D,{className:"text-muted-foreground",children:o.expires_at?ot(o.expires_at):"—"}),e.jsx(D,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(g,{variant:"ghost",size:"icon",asChild:!0,children:e.jsx("a",{href:o.url,target:"_blank",rel:"noopener noreferrer","aria-label":`Download ${o.filename}`,children:e.jsx(gt,{className:"h-4 w-4"})})}),e.jsx(g,{variant:"ghost",size:"icon",onClick:()=>le(o.pub_id),disabled:d&&u===o.pub_id,"aria-label":`Delete ${o.filename}`,children:e.jsx(Oe,{className:"h-4 w-4"})})]})})]},o.pub_id)},se=o=>e.jsxs(ie,{children:[e.jsx(D,{children:e.jsx(W,{variant:"outline",children:$[o].label})}),e.jsx(D,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{variant:"destructive",children:"Required"}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"Not uploaded"})]})}),e.jsx(D,{className:"text-muted-foreground",children:"—"}),e.jsx(D,{className:"text-muted-foreground",children:"—"}),e.jsx(D,{children:e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>fe(o),"aria-label":`Upload ${$[o].label}`,children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),"Upload"]})})]},o),je=Pe.map(o=>({type:o,docs:t.filter(R=>R.document_type===o)})),ue=t.filter(o=>!Pe.includes(o.document_type));return e.jsxs(K,{children:[e.jsxs(z,{className:"flex flex-row items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{children:"Documents"}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:["We need a W-9 and a Facility Safety Certification before you can sell. See"," ",e.jsx(ke,{href:"https://bubblegoods.zendesk.com/hc/en-us/articles/51942713116052-Required-Seller-Documentation",children:"Required Seller Documentation"})," ","for what each document should include."]})]}),e.jsxs(Y,{open:i,onOpenChange:o=>{o&&de(null),r(o)},children:[e.jsx(_e,{asChild:!0,children:e.jsxs(g,{variant:"outline",size:"sm",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),"Upload"]})}),e.jsxs(V,{children:[e.jsxs(J,{children:[e.jsx(X,{children:"Upload Document"}),e.jsx(Z,{children:"Upload a PDF document for your brand."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"document-type",children:"Document Type"}),e.jsxs(pt,{value:j,onValueChange:o=>p(o),disabled:y!==null,children:[e.jsx(ht,{id:"document-type",children:e.jsx(xt,{})}),e.jsx(ft,{children:Object.entries($).map(([o,{label:R}])=>e.jsx(jt,{value:o,children:R},o))})]}),j==="food_safety_cert"&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:["Upload your facility's safety certification (e.g. from your co-packer or manufacturing facility). See"," ",e.jsx(ke,{href:"https://bubblegoods.zendesk.com/hc/en-us/articles/51942713116052-Required-Seller-Documentation",children:"Required Seller Documentation"})," ","for what qualifies."]})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"expires-at",children:"Expiration date"}),e.jsx(P,{id:"expires-at",type:"date",value:v,min:F,onChange:o=>C(o.target.value),required:!0}),v&&!O&&e.jsx("p",{className:"text-destructive text-xs",children:"Expiration must be a future date."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"File"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mt,{accept:".pdf",onFile:x,variant:"outline",size:"sm",children:"Choose File"}),e.jsx("span",{className:"text-muted-foreground text-sm",children:(f==null?void 0:f.name)??"No file chosen"})]})]})]}),e.jsxs(ee,{children:[e.jsx(g,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(g,{onClick:xe,disabled:!ce,children:a?"Uploading...":"Upload"})]})]})]})]}),e.jsx(H,{children:s?e.jsx("p",{className:"text-muted-foreground text-sm",children:"Loading documents..."}):n?e.jsx("p",{className:"text-muted-foreground text-sm",children:"Couldn't load documents. Refresh the page to try again."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Me,{children:[e.jsx($e,{children:e.jsxs(ie,{children:[e.jsx(B,{children:"Type"}),e.jsx(B,{children:"Filename"}),e.jsx(B,{children:"Uploaded"}),e.jsx(B,{children:"Expires"}),e.jsx(B,{className:"w-[100px]"})]})}),e.jsxs(Ke,{children:[je.map(({type:o,docs:R})=>R.length>0?R.map(A):se(o)),ue.map(A)]})]})})})]})}function zt(t){return U({mutationFn:async({shopDomain:s,returnUrl:n})=>{const{data:i,error:r}=await k.POST("/api/brands/{brand_pub_id}/shopify/oauth/start",{params:{path:{brand_pub_id:t}},body:{shop_domain:s,return_url:n}});if(r)throw r;return i}})}function Qt(t){const s=q();return U({mutationFn:async()=>{const{error:n}=await k.DELETE("/api/brands/{brand_pub_id}/shopify",{params:{path:{brand_pub_id:t}}});if(n)throw n},onSuccess:()=>{s.invalidateQueries({queryKey:te.detail(t)})}})}const Ye={status:t=>["stripe-connect",t]};function Ht(t){return U({mutationFn:async({return_url:s,refresh_url:n})=>{const{data:i,error:r}=await k.POST("/api/brands/{brand_pub_id}/stripe-connect/link",{params:{path:{brand_pub_id:t}},body:{return_url:s,refresh_url:n}});if(r)throw r;return i}})}function Gt(t){const s=q(),n=oe({queryKey:Ye.status(t),queryFn:async()=>{const{data:i,error:r}=await k.GET("/api/brands/{brand_pub_id}/stripe-connect",{params:{path:{brand_pub_id:t}}});if(r)throw r;return i},enabled:!!t,refetchOnWindowFocus:!0});return h.useEffect(()=>{n.isSuccess&&n.data&&s.invalidateQueries({queryKey:te.detail(t)})},[n.isSuccess,n.data,s,t]),n}function Wt(t){const s=q();return U({mutationFn:async()=>{const{error:n}=await k.DELETE("/api/brands/{brand_pub_id}/stripe-connect",{params:{path:{brand_pub_id:t}}});if(n)throw n},onSuccess:()=>{s.invalidateQueries({queryKey:Ye.status(t)}),s.invalidateQueries({queryKey:te.detail(t)})}})}function Te(t){if(!t)return null;try{return new URL(t).host||null}catch{return t.trim()||null}}function It(t){var a;const s=t.shopify_store_url??"",n=Te(s),i=((a=Te(t.storefront_url))==null?void 0:a.replace(/^www\./,""))||null,r=t.shopify_app_status,l=s?t.shopify_connection_status:null;if(l==="good")return{kind:"connected",storeUrl:s};if(r==="per_brand_ready")return!n&&i?{kind:"waiting",storeDomain:i}:n?l==="credential error: no shopify integration"?{kind:"ready",storeDomain:n,firstConnect:!0}:l?{kind:"unhealthy_self_serve",storeDomain:n,rawStatus:l}:{kind:"ready",storeDomain:n,firstConnect:!t.shopify_connection_status_check_time}:{kind:"unhealthy_support",rawStatus:t.shopify_connection_status??"",detail:"You've disconnected from Shopify. Contact support to reconnect."};if(r==="legacy"){const m=i??n;return t.created_via!=="legacy-portal"&&!t.shopify_connection_status&&m?{kind:"waiting",storeDomain:m}:{kind:"unhealthy_support",rawStatus:l??""}}return{kind:"waiting",storeDomain:i??n}}function Yt(t){return t.startsWith("Uninstalled by brand")?"Your Shopify store removed the Bubble Goods app. Reconnect to resume syncing.":t.startsWith("credential error")?"Couldn't reach your Shopify store. Reconnect to renew credentials.":t.startsWith("missing scopes")?"Additional permissions are needed. Reconnect to grant access.":"Connection needs your attention. Reconnect to continue syncing."}function qe({brandId:t,shopDomain:s,label:n,variant:i}){const r=zt(t),l=()=>{const a=window.open("about:blank","_blank");r.mutate({shopDomain:s,returnUrl:`${window.location.origin}/settings`},{onSuccess:m=>{a&&!a.closed?a.location.href=m.oauth_url:window.location.href=m.oauth_url},onError:()=>{a&&!a.closed&&a.close(),_.error("Couldn't start the Shopify connection. Please try again.")}})};return e.jsx(g,{size:"sm",variant:i,onClick:l,disabled:r.isPending,children:r.isPending?"Connecting…":n})}function Vt({brandId:t}){const[s,n]=h.useState(!1),i=Qt(t),r=()=>{i.mutate(void 0,{onSuccess:()=>{_.success("Shopify disconnected"),n(!1)},onError:()=>{_.error("Failed to disconnect Shopify")}})};return e.jsxs(Y,{open:s,onOpenChange:n,children:[e.jsx(_e,{asChild:!0,children:e.jsx(g,{variant:"outline",size:"sm",className:"text-destructive hover:bg-destructive/10 hover:text-destructive",children:"Disconnect"})}),e.jsxs(V,{children:[e.jsxs(J,{children:[e.jsx(X,{children:"Disconnect Shopify"}),e.jsx(Z,{children:"Bubble Goods will no longer accept orders for your products, and all order history will be retained according to our data policy."})]}),e.jsxs(ee,{children:[e.jsx(g,{variant:"outline",onClick:()=>n(!1),disabled:i.isPending,children:"Cancel"}),e.jsx(g,{variant:"destructive",onClick:r,disabled:i.isPending,children:i.isPending?"Disconnecting…":"Disconnect"})]})]})]})}function G({name:t,connected:s,detail:n,detailTitle:i,action:r}){return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-2 py-2",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-medium text-sm",children:t}),e.jsx("p",{className:be("text-muted-foreground text-xs transition-opacity duration-300",n?"opacity-100":"opacity-0"),title:n?i:void 0,children:n||" "})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[s&&e.jsxs(W,{variant:"success",children:[e.jsx(_t,{className:"mr-1 h-3 w-3"}),"Connected"]}),r]})]})}function Jt({brand:t,brandId:s}
26){const n=It(t);switch(n.kind){case"connected":return e.jsx(G,{name:"Shopify",connected:!0,detail:n.storeUrl||null,action:e.jsx(Vt,{brandId:s})});case"ready":return e.jsx(G,{name:"Shopify",connected:!1,detail:n.firstConnect?"Install the Bubble Goods app from the link we emailed you first — then connect your store here.":n.storeDomain||null,detailTitle:n.firstConnect?n.storeDomain:void 0,action:e.jsx(qe,{brandId:s,shopDomain:n.storeDomain,label:n.firstConnect?"Installed? Connect to Shopify":"Connect to Shopify",variant:n.firstConnect?"outline":"default"})});case"unhealthy_self_serve":return e.jsx(G,{name:"Shopify",connected:!1,detail:Yt(n.rawStatus),detailTitle:n.rawStatus,action:e.jsx(qe,{brandId:s,shopDomain:n.storeDomain,label:"Reconnect to Shopify",variant:"outline"})});case"unhealthy_support":return e.jsx(G,{name:"Shopify",connected:!1,detail:n.detail??"Connection broken. Contact support.",detailTitle:n.rawStatus||void 0});case"waiting":return e.jsx(G,{name:"Shopify",connected:!1,detail:n.storeDomain?`We're setting up your Bubble Goods app for ${n.storeDomain}. We'll email you when it's ready.`:"We're setting up your Bubble Goods app. We'll email you when it's ready."})}}function Ue({onClick:t,pending:s,redirecting:n,label:i,variant:r}){return e.jsx(g,{size:"sm",variant:r,onClick:t,disabled:s||n,children:n?"Redirecting…":s?"Connecting…":i})}function Xt(t,s){var l;const n=(l=s.data)==null?void 0:l.status,i=!n&&s.isError&&t.stripe_connect_status_cached;return{state:n??(s.isError?t.stripe_connect_status_cached?"connected":"broken":"not_connected"),isCachedConnectedFallback:i}}function Zt({brand:t,brandId:s}){var w;const n=Gt(s),i=Ht(s),r=Wt(s),[l,a]=h.useState(!1),[m,d]=h.useState(!1),[j,p]=tt(),{state:y,isCachedConnectedFallback:b}=Xt(t,n),f=((w=n.data)==null?void 0:w.detail)??null;h.useEffect(()=>{var c;if(n.isSuccess&&((c=n.data)==null?void 0:c.status)==="connecting"&&j.get("stripe_return")==="1"){_.warning("Stripe may need more info — finish setup to start receiving payouts.");const F=new URLSearchParams(j);F.delete("stripe_return"),p(F,{replace:!0})}},[n.isSuccess,n.data,j,p]);const x=()=>{const c=new URL(window.location.href);c.searchParams.set("stripe_return","1");const F=c.toString();i.mutate({return_url:F,refresh_url:F},{onSuccess:O=>{d(!0),window.location.href=O.url},onError:()=>{_.error("Couldn't start Stripe onboarding. Please try again.")}})},v=()=>{r.mutate(void 0,{onSuccess:()=>{_.success("Stripe disconnected"),a(!1)},onError:()=>{_.error("Failed to disconnect Stripe")}})};let C=null,u=null;if(!n.isLoading)switch(y){case"connected":u=b?"Couldn't reach Stripe — showing last known status":f,C=e.jsx(g,{variant:"outline",size:"sm",className:"text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>a(!0),children:"Disconnect"});break;case"connecting":u="Finish setup to start receiving payouts",C=e.jsx(Ue,{onClick:x,pending:i.isPending,redirecting:m,label:"Resume",variant:"outline"});break;case"broken":u="Can't reach Stripe",C=e.jsx(g,{variant:"outline",size:"sm",onClick:()=>n.refetch(),disabled:n.isFetching,children:n.isFetching?"Retrying…":"Retry"});break;default:u=null,C=e.jsx(Ue,{onClick:x,pending:i.isPending,redirecting:m,label:"Start onboarding",variant:"default"});break}return e.jsxs(e.Fragment,{children:[e.jsx(G,{name:"Stripe Connect",connected:y==="connected",detail:u,action:C&&e.jsx("div",{className:"fade-in-0 animate-in duration-300",children:C})}),e.jsx(Y,{open:l,onOpenChange:a,children:e.jsxs(V,{children:[e.jsxs(J,{children:[e.jsx(X,{children:"Disconnect Stripe"}),e.jsx(Z,{children:"This will remove the Stripe Connect integration. You can reconnect later."})]}),e.jsxs(ee,{children:[e.jsx(g,{variant:"outline",onClick:()=>a(!1),disabled:r.isPending,children:"Cancel"}),e.jsx(g,{variant:"destructive",onClick:v,disabled:r.isPending,children:r.isPending?"Disconnecting…":"Disconnect"})]})]})})]})}function es({brand:t,brandId:s}){const n=t.labels==="shopify_integration";return e.jsxs(K,{className:"h-full",children:[e.jsx(z,{children:e.jsx(Q,{children:"Integrations"})}),e.jsx(H,{children:e.jsxs("div",{className:"divide-y",children:[n&&e.jsx(Jt,{brand:t,brandId:s}),e.jsx(Zt,{brand:t,brandId:s})]})})]})}function ve(t){return{name:(t==null?void 0:t.name)??"",company:(t==null?void 0:t.company)??"",street_1:(t==null?void 0:t.street_1)??"",street_2:(t==null?void 0:t.street_2)??"",city:(t==null?void 0:t.city)??"",state:(t==null?void 0:t.state)??"",postal_code:(t==null?void 0:t.postal_code)??"",phone:(t==null?void 0:t.phone)??""}}function Ae(t,s){if(!s.trim())return`${{street_1:"Street address",city:"City",state:"State",postal_code:"Postal code"}[t]} is required`}function ts(t){return t?[t.name,t.company,t.street_1,t.street_2,[t.city,t.state,t.postal_code].filter(
26Boolean).join(", ")].filter(Boolean).join(`
27`):"Not set"}function ss({label:t,address:s,addressType:n,editing:i,onEdit:r,onCancel:l,onSave:a,isSaving:m}){const[d,j]=h.useState(()=>ve(s)),[p,y]=h.useState({}),b=u=>{const w=Ae(u,d[u]);y(c=>({...c,[u]:w}))},f=(u,w)=>{j(c=>({...c,[u]:w})),u in p&&y(c=>({...c,[u]:void 0}))},x=()=>{const u={};for(const w of["street_1","city","state","postal_code"]){const c=Ae(w,d[w]);c&&(u[w]=c)}if(Object.keys(u).length>0){y(u);return}a(n,d)},v=()=>{j(ve(s)),y({}),l()},C=()=>{j(ve(s)),y({}),r()};return i?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium text-sm",children:t}),e.jsx(g,{variant:"ghost",size:"icon",onClick:v,"aria-label":`Cancel editing ${t.toLowerCase()}`,children:e.jsx(St,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:`${n}-name`,children:"Name"}),e.jsx(P,{id:`${n}-name`,value:d.name,onChange:u=>f("name",u.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:`${n}-company`,children:"Company"}),e.jsx(P,{id:`${n}-company`,value:d.company,onChange:u=>f("company",u.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:`${n}-street_1`,children:"Street Address"}),e.jsx(P,{id:`${n}-street_1`,value:d.street_1,onChange:u=>f("street_1",u.target.value),onBlur:()=>b("street_1"),"aria-invalid":!!p.street_1}),p.street_1&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:p.street_1})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:`${n}-street_2`,children:"Street Address Line 2"}),e.jsx(P,{id:`${n}-street_2`,value:d.street_2,onChange:u=>f("street_2",u.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:`${n}-city`,children:"City"}),e.jsx(P,{id:`${n}-city`,value:d.city,onChange:u=>f("city",u.target.value),onBlur:()=>b("city"),"aria-invalid":!!p.city}),p.city&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:p.city})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:`${n}-state`,children:"State"}),e.jsx(P,{id:`${n}-state`,value:d.state,onChange:u=>f("state",u.target.value),onBlur:()=>b("state"),"aria-invalid":!!p.state}),p.state&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:p.state})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:`${n}-postal_code`,children:"Postal Code"}),e.jsx(P,{id:`${n}-postal_code`,value:d.postal_code,onChange:u=>f("postal_code",u.target.value),onBlur:()=>b("postal_code"),"aria-invalid":!!p.postal_code}),p.postal_code&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:p.postal_code})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:`${n}-phone`,children:"Phone"}),e.jsx(P,{id:`${n}-phone`,value:d.phone,onChange:u=>f("phone",u.target.value)})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(g,{variant:"outline",size:"sm",onClick:v,children:"Cancel"}),e.jsx(g,{size:"sm",onClick:x,disabled:m,children:m?"Saving...":"Save"})]})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium text-sm",children:t}),e.jsx(g,{variant:"ghost",size:"icon",onClick:C,"aria-label":`Edit ${t.toLowerCase()}`,children:e.jsx(Ie,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"whitespace-pre-line text-muted-foreground text-sm",children:ts(s)})]})}function ns({fulfillmentAddress:t,isLoading:s,editingAddressType:n,onEditAddress:i,onCancelAddress:r,onSave:l,savingAddressType:a}){return e.jsxs(K,{children:[e.jsx(z,{children:e.jsx(Q,{children:"Shipping"})}),e.jsx(H,{children:s?e.jsx("p",{className:"text-muted-foreground text-sm",children:"Loading addresses..."}):e.jsx(ss,{label:"Fulfillment Address",address:t,addressType:"fulfillment",editing:n==="fulfillment",onEdit:()=>i("fulfillment"),onCancel:r,onSave:l,isSaving:a==="fulfillment"})})]})}var is="Invariant failed";function I(t,s){if(!t)throw new Error(is)}const Se={all:t=>["billing",t]};function rs(t){return oe({queryKey:Se.all(t),queryFn:async()=>{const{data:s,error:n}=await k.GET("/api/brands/{brand_pub_id}/billing",{params:{path:{brand_pub_id:t}}});if(n)throw n;return s}})}
27class he extends Error{constructor(n,i){super(n);we(this,"status");this.name="SubscribeError",this.status=i}}function as(t){const s=q(),n=()=>{s.invalidateQueries({queryKey:Se.all(t)}),s.invalidateQueries({queryKey:te.detail(t)})};return U({mutationFn:async({payment_method_id:i})=>{const{data:r,error:l,response:a}=await k.POST("/api/brands/{brand_pub_id}/billing/subscribe",{params:{path:{brand_pub_id:t}},body:i?{payment_method_id:i}:{}});if(l)throw new he(l.error??"Subscription failed",a.status);return r},onSuccess:n,onError:i=>{i instanceof he&&i.status===409&&n()}})}function os(t){const s=q();return U({mutationFn:async({payment_method_id:n})=>{const{data:i,error:r}=await k.POST("/api/brands/{brand_pub_id}/billing/payment-method",{params:{path:{brand_pub_id:t}},body:{payment_method_id:n}});if(r)throw r;return i},onSuccess:()=>{s.invalidateQueries({queryKey:Se.all(t)}),s.invalidateQueries({queryKey:te.detail(t)})}})}const cs="pk_live_oFNwTQrGBdqtRUXuiJxIwGpt",T=Nt(cs),ls=new Set(["active","paused"]),ds=new Set(["past_due","unpaid","incomplete","incomplete_expired"]),us={trialing:"Trial active",active:"Active"};function ms(t){var i,r;const s=((i=t==null?void 0:t.subscription)==null?void 0:i.status)??null,n=!!((r=t==null?void 0:t.card)!=null&&r.last4);return!n&&!s?"pre-commit":n&&!s?"incomplete":s==="trialing"?"trialing":s==="canceled"?"canceled":s&&ds.has(s)?"past-due":(s&&ls.has(s),"active")}function re(t){return t==="pre-commit"||t==="incomplete"}function ps({brandId:t}){const{data:s}=rs(t),n=s==null?void 0:s.subscription;if((n==null?void 0:n.status)==="paused"||n!=null&&n.collection_paused)return null;const i=ms(s),r=i!=="pre-commit";return e.jsxs(K,{children:[e.jsxs(z,{children:[e.jsx(Q,{children:"Subscription"}),e.jsx(rt,{children:"An active subscription is required to be live on Bubble Goods."})]}
27),e.jsxs(H,{children:[e.jsx(hs,{billing:s,mode:i,brandId:t}),r&&e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"my-6"}),e.jsx(Ss,{brandId:t,card:s==null?void 0:s.card})]})]})]})}function hs({billing:t,mode:s,brandId:n}){var d,j;const i=(t==null?void 0:t.plan)??null,r=(t==null?void 0:t.setup_fee)??null,l=((d=t==null?void 0:t.subscription)==null?void 0:d.current_period_end)??null,a=i?Ee(i.amount_cents/100):null,m=r?Ee(r.amount_cents/100):null;return e.jsxs("div",{className:"space-y-4",children:[s==="past-due"&&e.jsx(js,{}),s==="canceled"&&e.jsx(gs,{}),e.jsx(xs,{mode:s,monthly:a,setup:m}),e.jsx(fs,{mode:s,monthly:a,periodEnd:l}),re(s)&&e.jsx(bs,{brandId:n,hasCard:!!((j=t==null?void 0:t.card)!=null&&j.last4),monthly:a})]})}function Le(t){return re(t)?"Pricing":"Your plan"}function xs({mode:t,monthly:s,setup:n}){if(!s)return e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs uppercase tracking-wide",children:Le(t)}),e.jsx("p",{className:"mt-1 font-semibold text-lg",children:"Monthly subscription"})]});const i=us[t]??null;return e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs uppercase tracking-wide",children:Le(t)}),e.jsxs("p",{className:"mt-1 font-semibold text-lg tabular-nums",children:[s,e.jsx("span",{className:"font-normal text-muted-foreground",children:" /month"}),n&&re(t)&&e.jsxs("span",{className:"font-normal text-muted-foreground",children:[" ","+ ",n," one-time onboarding fee"]}),i&&e.jsxs("span",{className:"font-normal text-muted-foreground",children:[" · ",i]})]})]})}function fs({mode:t,monthly:s,periodEnd:n}){if(!s)return re(t)?e.jsx("p",{className:"text-muted-foreground text-sm",children:"Subscribing starts your monthly subscription today. Pricing is temporarily unavailable — please try again shortly."}):null;const i=n?ct(n):null;return re(t)?e.jsx(Ve,{monthly:s}):t==="trialing"?e.jsx("p",{className:"text-muted-foreground text-sm",children:i?e.jsxs(e.Fragment,{children:["First ",e.jsx("span",{className:"tabular-nums",children:s})," monthly charge on ",e.jsx("span",{className:"font-medium text-foreground",children:i}),". Monthly billing after that."]}):e.jsxs(e.Fragment,{children:["First ",e.jsx("span",{className:"tabular-nums",children:s})," monthly charge after your trial ends. Monthly billing after that."]})}):t==="active"?e.jsx("p",{className:"text-muted-foreground text-sm",children:i?e.jsxs(e.Fragment,{children:["Next charge on"," ",e.jsx("span",{className:"font-medium text-foreground",children:i}),"."]}):e.jsx(e.Fragment,{children:"Renews monthly."})}):null}function js(){return e.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-destructive-foreground text-sm",children:[e.jsx(We,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-destructive",children:"Payment failed"}),e.jsx("p",{className:"text-destructive/90",children:"Update your card to avoid service interruption."})]})]})}function gs(){return e.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-md border bg-muted p-3 text-sm",children:[e.jsx(We,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Subscription canceled"}),e.jsx("p",{className:"text-muted-foreground",children:"Reach out to support if you'd like to reactivate."})]})]})}const ys=/requires .{0,20}authentication/i,vs="This card requires extra verification we can't process here yet — please try a different card.";function Ve({monthly:t}){return e.jsxs("p",{className:"text-muted-foreground text-sm",children:["By clicking Subscribe, you agree to be charged"," ",e.jsx("span",{className:"tabular-nums",children:t})," today, then"," ",e.jsx("span",{className:"tabular-nums",children:t}),"/month until you cancel. Cancel anytime by contacting support."]})}function bs({brandId:t,hasCard:s,monthly:n}){const i=as(t),{data:r}=ze(t),[l,a]=h.useState(!1),[m,d]=h.useState(null),[j,p]=h.useState(!1);h.useEffect(()=>{T&&T.then(x=>{x&&p(!0)})},[]);const y=x=>{d(null),i.mutate(x?{payment_method_id:x}:{},{onSuccess:()=>{var v;(v=M())==null||v.capture("subscription_started",{created_via:r==null?void 0:r.created_via,card_on_file:s}),a(!1)},onError:v=>{var u;if(v instanceof he&&v.status===409){a(!1);return}const C=ys.test(v.message);d(C?vs:v.message),(u=M())==null||u.capture("subscription_failed",{decline_code:C?"authentication_required":v instanceof he&&v.status===400?"card_declined":null,error_message:v.message,card_on_file:s})}})},b=n!==null,f=b?`Subscribe — ${n}/mo`:"Subscribe";return s?e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{onClick:()=>y(),disabled:!b||i.isPending,children:i.isPending?"Subscribing…":f}),m&&e.jsx("p",{className:"text-destructive text-sm",role:"alert",children:m})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{onClick:()=>a(!0),disabled:!b||!T||!j||i.isPending,children:f}),!T&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"Payments are temporarily unavailable. Please try again later."}),T&&n&&e.jsx(Y,{open:l,onOpenChange:a,children:e.jsxs(V,{children:[e.jsxs(J,{children:[e.jsx(X,{children:"Subscribe"}),e.jsx(Z,{children:"Enter your card details below."})]}),e.jsx(Qe,{stripe:T,children:e.jsx(_s,{monthly:n,onSubscribe:y,pending:i.isPending,subscribeError:m,onClose:()=>a(!1)})})]})})]})}function _s({monthly:t,onSubscribe:s,pending:n,subscribeError:i,onClose:r}){const l=He(),a=Ge(),[m,d]=h.useState(!1),[j,p]=h.useState(),y=async()=>{I(l&&a);const f=a.getElement(pe);I(f);const{paymentMethod:x,error:v}=await l.createPaymentMethod({type:"card",card:f});if(v){p(v.message);return}I(x),s(x.id)},b=j??i;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"py-4",children:[e.jsx(pe,{onChange:f=>{var x;d(f.complete),p((x=f.error)==null?void 0:x.message)}}),b&&e.jsx("p",{className:"mt-2 text-destructive text-sm",children:b})]}),e.jsx(Ve,{monthly:t}),e.jsxs(ee,{children:[e.jsx(g,{variant:"outline",onClick:r,children:"Cancel"}),e.jsx(g,{onClick:y,disabled:!m||n,children:n?"Subscribing…":"Subscribe"})]})]})}function Ss({brandId:t,card:s}){const[n,i]=h.useState(!1),[r,l]=h.useState(!1);return h.useEffect(()=>{T&&T.then(a=>{a&&l(!0)})},[]),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs uppercase tracking-wide",children:"Payment method"}),e.jsx("p",{className:"text-sm",children:s!=null&&s.last4?e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium",children:[s.brand?Cs(s.brand):"Card"," ····"," ",s.last4]}),s.exp_month!=null&&s.exp_year!=null&&e.jsxs("span",{className:"ml-2 text-muted-foreground",children:["Expires ",String(s.exp_month).padStart(2,"0"),"/",s.exp_year]})]}):e.jsx("span",{className:"text-muted-foreground",children:"No card on file"})}),e.jsxs("div",{children:[e.jsx(g,{variant:"outline",size:"sm",onClick:()=>i(!0),disabled:!T||!r,children:s!=null&&s.last4?"Update payment method":"Add payment method"}),!T&&e.jsx("p",{className:"mt-2 text-muted-foreground text-sm",children:"Payment updates are temporarily unavailable."})]}),T&&e.jsx(Y,{open:n,onOpenChange:i,children:e.jsxs(V,{children:[e.jsxs(J,{children:[e.jsx(X,{children:s!=null&&s.last4?"Update payment method":"Add payment method"}),e.jsx(Z,{children:"Enter your card details below."})]}),e.jsx(Qe,{stripe:T,children:e.jsx(Ns,{brandId:t,onClose:()=>i(!1)})})]})})]})}function Ns({brandId:t,onClose:s}){const n=He(),i=Ge(),r=os(t),[l,a]=h.useState(!1),[m,d]=h.useState(),j=async()=>{I(n&&i);const p=i.getElement(pe);I(p);const{paymentMethod:y,error:b}=await n.createPaymentMethod({type:"card",card:p});if(b){d(b.message);return}I(y),r.mutate({payment_method_id:y.id},{onSuccess:()=>{_.success("Payment method updated"),s()},onError:()=>{_.error("Failed to update payment method")}})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"py-4",children:[e.jsx(pe,{onChange:p=>{var y;a(p.complete),d((y=p.error)==null?void 0:y.message)}}),m&&e.jsx("p",{className:"mt-2 text-destructive text-sm",children:m})]}),e.jsxs(ee,{children:[e.jsx(g,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(g,{onClick:j,disabled:!l||r.isPending,children:r.isPending?"Upd
27ating…":"Update"})]})]})}function Cs(t){return{visa:"Visa",mastercard:"Mastercard",amex:"Amex",discover:"Discover",diners:"Diners Club",jcb:"JCB",unionpay:"UnionPay"}[t]??t.charAt(0).toUpperCase()+t.slice(1)}const ws={owner:"default",admin:"secondary",full:"outline"},Es={active:"default",invited:"secondary",expired:"outline"};function ks({members:t,isLoading:s,inviteOpen:n,onInviteOpen:i,onInvite:r,isInviting:l,onRemove:a,isRemoving:m}){const[d,j]=h.useState(""),[p,y]=h.useState(),[b,f]=h.useState(null),x=c=>{if(!c.trim())return"Email is required";if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c))return"Invalid email"},v=()=>{d&&y(x(d))},C=c=>{j(c),p&&y(void 0)},u=()=>{const c=x(d);if(c){y(c);return}r(d)},w=c=>{f(c),a(c)};return e.jsxs(K,{children:[e.jsxs(z,{className:"flex flex-row items-center justify-between",children:[e.jsx(Q,{children:"Team"}),e.jsxs(Y,{open:n,onOpenChange:i,children:[e.jsx(_e,{asChild:!0,children:e.jsxs(g,{variant:"outline",size:"sm",children:[e.jsx(Dt,{className:"mr-2 h-4 w-4"}),"Invite"]})}),e.jsxs(V,{children:[e.jsxs(J,{children:[e.jsx(X,{children:"Invite Team Member"}),e.jsx(Z,{children:"Send an invitation to join your brand team."})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"invite-email",children:"Email"}),e.jsx(P,{id:"invite-email",type:"email",placeholder:"[email protected]",value:d,onChange:c=>C(c.target.value),onBlur:v,"aria-invalid":!!p}),p&&e.jsx("p",{className:"text-destructive text-xs",children:p})]})}),e.jsxs(ee,{children:[e.jsx(g,{variant:"outline",onClick:()=>i(!1),children:"Cancel"}),e.jsx(g,{onClick:u,disabled:l,children:l?"Sending...":"Send Invite"})]})]})]})]}),e.jsx(H,{children:s?e.jsx("p",{className:"text-muted-foreground text-sm",children:"Loading team members..."}):t.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2 py-8 text-center",children:[e.jsx(Ft,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"No team members yet."})]}):e.jsxs(Me,{children:[e.jsx($e,{children:e.jsxs(ie,{children:[e.jsx(B,{children:"Name / Email"}),e.jsx(B,{children:"Role"}),e.jsx(B,{children:"Status"}),e.jsx(B,{className:"w-[80px]"})]})}),e.jsx(Ke,{children:t.map(c=>e.jsxs(ie,{children:[e.jsx(D,{children:e.jsxs("div",{children:[c.name&&e.jsx("p",{className:"font-medium",children:c.name}),e.jsx("p",{className:"text-muted-foreground text-sm",children:c.email})]})}),e.jsx(D,{children:e.jsx(W,{variant:ws[c.role??""]??"outline",children:c.role})}),e.jsx(D,{children:e.jsx(W,{variant:Es[c.status??""]??"outline",children:c.status})}),e.jsx(D,{children:c.role!=="owner"&&c.pub_id&&e.jsx(g,{variant:"ghost",size:"icon",onClick:()=>{c.pub_id&&w(c.pub_id)},disabled:m&&b===c.pub_id,"aria-label":`Remove ${c.email}`,children:e.jsx(Oe,{className:"h-4 w-4"})})})]},c.email))})]})})]})}const Je={all:["addresses"],list:t=>["addresses","list",t]};function Ds(t){return oe({queryKey:Je.list(t),queryFn:async()=>{const{data:s,error:n}=await k.GET("/api/brands/{brand_pub_id}/addresses",{params:{path:{brand_pub_id:t}}});if(n)throw n;return s},enabled:!!t})}function Fs(t){const s=q();return U({mutationFn:async({addressType:n,data:i})=>{const{data:r,error:l}=await k.PUT("/api/brands/{brand_pub_id}/addresses/{address_type}",{params:{path:{brand_pub_id:t,address_type:n}},body:i});if(l)throw l;return r},onSuccess:()=>{s.invalidateQueries({queryKey:Je.list(t)})}})}const Ne={all:["documents"],list:t=>["documents","list",t]};function Rs(t){return oe({queryKey:Ne.list(t),queryFn:async()=>({items:await Tt(t)}),enabled:!!t,refetchInterval:300*1e3})}function Ps(t){const s=q();return U({mutationFn:({file:n,documentType:i,expiresAt:r})=>qt(t,{file:n,documentType:i,expiresAt:r}),onSuccess:()=>{s.invalidateQueries({queryKey:Ne.list(t)})}})}function Ts(t){const s=q();return U({mutationFn:n=>Ut(t,n),onSuccess:()=>{s.invalidateQueries({queryKey:Ne.list(t)})}})}const Ce={all:["team"],list:t=>["team","list",t]};function qs(t){return oe({queryKey:Ce.list(t),queryFn:async()=>{const{data:s,error:n}=await k.GET("/api/brands/{brand_pub_id}/team",{params:{path:{brand_pub_id:t}}});if(n)throw n;return s},enabled:!!t})}function Us(t){const s=q();return U({mutationFn:async({email:n})=>{const{error:i}=await k.POST("/api/brands/{brand_pub_id}/team/invite",{params:{path:{brand_pub_id:t}},body:{email:n}});if(i)throw i},onSuccess:()=>{s.invalidateQueries({queryKey:Ce.list(t)})}})}function As(t){const s=q();return U({mutationFn:async n=>{const{error:i}=await k.DELETE("/api/brands/{brand_pub_id}/team/{invite_pub_id}",{params:{path:{brand_pub_id:t,invite_pub_id:n}}});if(i)throw i},onSuccess:()=>{s.invalidateQueries({queryKey:Ce.list(t)})}})}const Dn={breadcrumb:"Settings"};function Ls(t,s){const n=r=>(r??"").replace(/^https?:\/\//,""),i=[];return(t.name??"")!==(s.name??"")&&i.push("name"),(t.description??"")!==(s.description??"")&&i.push("description"),n(t.website)!==n(s.website)&&i.push("website"),(t.location??"")!==(s.location??"")&&i.push("location"),t.profileImage&&i.push("profile_image"),i}const Fn=st(function(){var R;const{brandId:s}=wt(),{data:n,isLoading:i}=ze(s),{data:r,isLoading:l,isError:a}=Rs(s),{data:m,isLoading:d}=Ds(s),j=Fs(s),{data:p,isLoading:y}=qs(s),b=Us(s),f=As(s),x=Ps(s),v=Ts(s),C=bt(s),[u,w]=h.useState(!1),[c,F]=h.useState(),[O,ce]=h.useState(!1),[xe,le]=h.useState(!1),de=nt(),fe=q(),A=it(),se=h.useRef(null);h.useEffect(()=>{var ne;const N=new URLSearchParams(A.search),S=N.get("shopify");if(!S){se.current=null;return}if(se.current===A.search)return;se.current=A.search;const L=N.get("reason");if(S==="connected")_.success("Shopify connected"),(ne=M())==null||ne.capture("shopify_connected"),fe.invali
27dateQueries({queryKey:te.detail(s)});else if(S==="cancelled")_.info("Shopify connection cancelled");else{const Xe={csrf:"Security check failed. Please try again.",expired:"Connection link expired. Please try again.",exchange_failed:"Couldn't complete the Shopify connection. Please try again."};_.error(L&&Xe[L]||"Couldn't connect to Shopify. Please try again.")}de("/settings",{replace:!0})},[A.search]);const[je,ue]=h.useState(null);h.useEffect(()=>{if(i||!n)return;const N=A.hash.replace(/^#/,"");if(!N)return;const S=document.getElementById(N);if(!S)return;S.scrollIntoView({behavior:"smooth",block:"start"}),ue(N);const L=window.setTimeout(()=>ue(null),1500);return()=>window.clearTimeout(L)},[A.hash,i,!!n]);const o=N=>be("scroll-mt-4 rounded-xl transition-shadow duration-500",je===N&&"ring-2 ring-primary ring-offset-2 ring-offset-background");return i?e.jsxs("div",{className:"space-y-6",children:[e.jsx(me,{className:"h-8 w-48"}),e.jsx(me,{className:"h-48 w-full"}),e.jsx(me,{className:"h-32 w-full"}),e.jsx(me,{className:"h-48 w-full"})]}):n?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-bold text-2xl",children:"Settings"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage your brand profile and account settings."})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-2",children:[e.jsx("div",{id:"brand-profile",className:o("brand-profile"),children:e.jsx($t,{brand:n,editing:u,onEdit:()=>w(!0),onCancel:()=>w(!1),onSave:N=>C.mutate(N,{onSuccess:()=>{var S;_.success("Profile updated"),(S=M())==null||S.capture("brand_profile_saved",{fields_changed:Ls(N,n)}),w(!1)},onError:S=>_.error(ge(S,"Failed to update profile"))}),isSaving:C.isPending})}),e.jsx("div",{id:"integrations",className:o("integrations"),children:e.jsx(es,{brand:n,brandId:s})})]}),e.jsx("div",{id:"shipping",className:o("shipping"),children:e.jsx(ns,{fulfillmentAddress:m==null?void 0:m.fulfillment,isLoading:d,editingAddressType:c,onEditAddress:F,onCancelAddress:()=>F(void 0),onSave:(N,S)=>j.mutate({addressType:N,data:S},{onSuccess:()=>{var L;_.success("Address updated"),(L=M())==null||L.capture("shipping_address_saved",{address_type:N}),F(void 0)},onError:()=>_.error("Failed to update address")}),savingAddressType:j.isPending?(R=j.variables)==null?void 0:R.addressType:void 0})}),e.jsx("div",{id:"documents",className:o("documents"),children:e.jsx(Kt,{documents:(r==null?void 0:r.items)??[],isLoading:l,isError:a,uploadOpen:xe,onUploadOpen:le,onUpload:(N,S,L)=>x.mutate({file:N,documentType:S,expiresAt:L},{onSuccess:()=>{var ne;_.success("Document uploaded"),(ne=M())==null||ne.capture("document_uploaded",{doc_type:S}),le(!1)},onError:()=>_.error("Failed to upload document")}),isUploading:x.isPending,onDelete:N=>v.mutate(N,{onSuccess:()=>_.success("Document deleted"),onError:()=>_.error("Failed to delete document")}),isDeleting:v.isPending})}),e.jsx(ks,{members:(p==null?void 0:p.members)??[],isLoading:y,inviteOpen:O,onInviteOpen:ce,onInvite:N=>b.mutate({email:N},{onSuccess:()=>{var S;_.success("Invitation sent"),(S=M())==null||S.capture("team_member_invited"),ce(!1)},onError:S=>_.error(ge(S,"Failed to send invitation"))}),isInviting:b.isPending,onRemove:N=>f.mutate(N,{onSuccess:()=>_.success("Team member removed"),onError:S=>_.error(ge(S,"Failed to remove team member"))}),isRemoving:f.isPending}),e.jsx("div",{id:"subscription",className:o("subscription"),children:e.jsx(ps,{brandId:s})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"font-bold text-2xl",children:"Settings"}),e.jsx("p",{className:"text-destructive",children:"Failed to load brand details."})]})});export{Fn as default,Dn as handle};

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.