1import{r as i,j as e}from"./vendor-motion-CWthwBHV.js";import{a as A}from"./index-DbXfi5N8.js";import{u as E,w as T,F as g,bu as b,aT as F,E as $,bM as B}from"./session-card-DfDogMnt.js";import{a as v,u as L,c as D}from"./vendor-query-CIlvkMVG.js";import{A as U}from"./App-DucJjLMU.js";import{P as M}from"./page-footer-DgQVBoUK.js";import{U as q}from"./users-3zLgccbJ.js";import{C as O}from"./chevron-up-BgErrXh0.js";import{C as k}from"./clock-DS3tHqp7.js";import{C as z}from"./circle-alert-WYCRbN3w.js";import{C as R}from"./chart-no-axes-column-BRVsqO8L.js";import"./index-UQ4Qr5Bx.js";import"./vendor-radix-XKDS9LlS.js";import"./api-base-B8hCG6H6.js";import"./vendor-charts-DVgyNbFy.js";import"./clerk-preview-Xs8fmqyU.js";import"./zap-DKaaT3bk.js";const y="/".replace(/\/$/,"");async function V(s){const t=await fetch(`${y}/api/brands/my/owned`,{headers:{Authorization:`Bearer ${s}`}});if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()}async function I(s,t){const a=await fetch(`${y}/api/brands/my/${s}/polls`,{headers:{Authorization:`Bearer ${t}`}});if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.json()}async function H(s,t,a,o){const n=await fetch(`${y}/api/brands/my/${s}/polls`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({question:t,durationDays:a})});if(!n.ok){const c=await n.json().catch(()=>({}));throw new Error(c.message??`HTTP ${n.status}`)}return n.json()}function K(s){if(s.logoUrl)return s.logoUrl;if(!s.website)return null;try{return`https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://${new URL(s.website).hostname.replace(/^www\./,"")}&size=128`}catch{return null}}function N(s){return new Date(s).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})}function Q({poll:s}){const t=new Date(s.expiresAt)>new Date,a=s.eligibleCount>0?Math.round(s.responseCount/s.eligibleCount*100):null;return e.jsxs("div",{className:"rounded-xl p-4 space-y-3",style:{background:"rgba(58,28,0,0.03)",border:"1px solid rgba(58,28,0,0.08)"},children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("p",{className:"text-sm font-medium leading-snug",style:{color:"#2e1505"},children:s.question}),e.jsx("span",{className:"flex-shrink-0 inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[12px] font-bold uppercase tracking-wide",style:{background:t?"#dcfce7":"rgba(58,28,0,0.06)",color:t?"#15803d":"rgba(58,28,0,0.45)"},children:t?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"w-2.5 h-2.5"}),"Active"]}):"Closed"})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[12px] font-mono uppercase tracking-wider mb-0.5",style:{color:"rgba(58,28,0,0.4)"},children:"Responses"}),e.jsxs("p",{className:"text-lg font-semibold",style:{color:"#2e1505"},children:[s.responseCount,a!==null&&e.jsxs("span",{className:"text-xs font-normal ml-1",style:{color:"rgba(58,28,0,0.45)"},children:["(",a,"%)"]})]})]}),s.proudPercent!==null&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[12px] font-mono uppercase tracking-wider mb-0.5",style:{color:"rgba(58,28,0,0.4)"},children:"Proud"}),e.jsxs("p",{className:"text-lg font-semibold",style:{color:"#b5622a"},children:[s.proudPercent,"%"]})]}),s.avgLevel!==null&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[12px] font-mono uppercase tracking-wider mb-0.5",style:{color:"rgba(58,28,0,0.4)"},children:"Avg level"}),e.jsxs("p",{className:"text-lg font-semibold",style:{color:"#2e1505"},children:[s.avgLevel.toFixed(1),"/5"]})]})]}),e.jsxs("p",{className:"text-[11px]",style:{color:"rgba(58,28,0,0.35)"},children:[t?"Expires":"Expired"," ",N(s.expiresAt)," · Created ",N(s.createdAt),s.createdByUsername&&e.jsxs(e.Fragment,{children:[" · Sent by ",e.jsxs("span",{className:"font-medium",style:{color:"rgba(58,28,0,0.5)"},children:["@",s.createdByUsername]})]})]})]})}function G({brand:s,token:t}){const a=L(),[o,n]=i.useState(!1),[c,d]=i.useState(!1),[x]=i.useState(`Thinking of your last experience with ${s.name}, how proud are you when using our products?`),[l,f]=i.useState(7),[j,u]=i.useState(null),{data:p=[],isLoading:C}=v({queryKey:["brand-owner-polls",s.id],queryFn:()=>I(s.id,t),enabled:o}),h=D({mutationFn:()=>H(s.id,x.trim(),l,t),onSuccess:()=>{a.invalidateQueries({queryKey:["brand-owner-polls",s.id]}),d(!1),f(7),u(null)},onError:r=>u(r.message)}),w=K(s),m=p[0],P=!m||(Date.now()-new Date(m.createdAt).getTime())/(1e3*60*60*24)>=30,S=m?Math.max(0,Math.ceil(30-(Date.now()-new Date(m.createdAt).getTime())/(1e3*60*60*24))):0;return e.jsxs("div",{className:"rounded-2xl overflow-hidden",style:{background:"white",border:"1px solid rgba(58,28,0,0.08)"},children:[e.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"w-full text-left p-5 flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-full flex-shrink-0 flex items-center justify-center overflow-hidden",style:{background:"rgba(58,28,0,0.05)",border:"1px solid rgba(58,28,0,0.08)"},children:w?e.jsx("img",{src:w,alt:s.name,className:"w-full h-full object-cover",onError:r=>{r.currentTarget.style.display="none"}}):e.jsx(b,{className:"w-6 h-6",style:{color:"rgba(58,28,0,0.25)"}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-semibold",style:{color:"#2e1505"},children:s.name}),s.isVerified&&e.jsx(A,{size:15,style:{color:"#2563eb"}})]}),e.jsxs("p",{className:"text-xs mt-0.5",style:{color:"rgba(58,28,0,0.45)"},children:[e.jsx(q,{className:"w-3 h-3 inline mr-1"}),s.followerCount," using this",s.category&&e.jsxs(e.Fragment,{children:[" · ",s.category]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[e.jsxs(g,{href:`/brands/${s.slug}`,onClick:r=>r.stopPropagation(),className:"text-[11px] hover:opacity-70 transition-opacity flex items-center gap-1",style:{color:"rgba(58,28,0,0.4)"},children:[e.jsx(F,{className:"w-3 h-3"}),"View"]}
1),o?e.jsx(O,{className:"w-4 h-4",style:{color:"rgba(58,28,0,0.35)"}}):e.jsx($,{className:"w-4 h-4",style:{color:"rgba(58,28,0,0.35)"}})]})]}),o&&e.jsxs("div",{className:"px-5 pb-5 space-y-4 border-t",style:{borderColor:"rgba(58,28,0,0.06)"},children:[e.jsxs("div",{className:"pt-4 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-normal",style:{color:"#2e1505",fontFamily:"'Tinos', Georgia, serif"},children:"Polls"}),P?e.jsxs("button",{type:"button",onClick:()=>d(r=>!r),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all",style:{background:"#2e1505",color:"#fdf8f0"},children:[e.jsx(B,{className:"w-3.5 h-3.5"}),"New Poll"]}):e.jsxs("span",{className:"text-[11px] flex items-center gap-1",style:{color:"rgba(58,28,0,0.4)"},children:[e.jsx(k,{className:"w-3 h-3"}),"Next poll in ",S,"d"]})]}),c&&e.jsxs("form",{onSubmit:r=>{r.preventDefault(),h.mutate()},className:"rounded-xl p-4 space-y-3",style:{background:"rgba(181,98,42,0.04)",border:"1px solid rgba(181,98,42,0.15)"},children:[e.jsx("p",{className:"text-[12px] font-bold uppercase tracking-widest",style:{color:"#b5622a"},children:"New Follower Poll"}),e.jsx("div",{className:"px-4 py-3 rounded-xl text-sm leading-relaxed",style:{background:"white",border:"1px solid rgba(181,98,42,0.15)",color:"#2e1505"},children:x}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs mb-1",style:{color:"rgba(58,28,0,0.5)"},children:"Duration"}),e.jsx("select",{value:l,onChange:r=>f(Number(r.target.value)),className:"rounded-lg px-3 py-2 text-sm border focus:outline-none",style:{background:"white",border:"1px solid rgba(58,28,0,0.15)",color:"#2e1505"},children:[3,5,7,14].map(r=>e.jsxs("option",{value:r,children:[r," days"]},r))})]}),j&&e.jsxs("p",{className:"text-xs flex items-center gap-1",style:{color:"#dc2626"},children:[e.jsx(z,{className:"w-3.5 h-3.5 flex-shrink-0"}),j]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",disabled:h.isPending||!x.trim(),className:"px-4 py-1.5 rounded-lg text-xs font-semibold disabled:opacity-50",style:{background:"#b5622a",color:"white"},children:h.isPending?"Sendingâ¦":"Send to Followers"}),e.jsx("button",{type:"button",onClick:()=>{d(!1),u(null)},className:"px-4 py-1.5 rounded-lg text-xs",style:{color:"rgba(58,28,0,0.5)"},children:"Cancel"})]})]}),C?e.jsx("p",{className:"text-sm text-center py-6",style:{color:"rgba(58,28,0,0.4)"},children:"Loadingâ¦"}):p.length===0?e.jsxs("div",{className:"text-center py-8 rounded-xl",style:{background:"rgba(58,28,0,0.02)",border:"1px solid rgba(58,28,0,0.06)"},children:[e.jsx(R,{className:"w-7 h-7 mx-auto mb-2",style:{color:"rgba(58,28,0,0.15)"}}),e.jsx("p",{className:"text-sm",style:{color:"rgba(58,28,0,0.4)"},children:"No polls yet."}),e.jsx("p",{className:"text-xs mt-1",style:{color:"rgba(58,28,0,0.3)"},children:"Create a poll to hear from your followers."})]}):e.jsx("div",{className:"space-y-3",children:p.map(r=>e.jsx(Q,{poll:r},r.id))})]})]})}function xe(){const{isSignedIn:s,isLoaded:t}=E(),{getToken:a}=T(),[o,n]=i.useState(null),{data:c=[],isLoading:d,error:x}=v({queryKey:["brand-owner-brands"],queryFn:async()=>{const l=o??await a();if(!l)throw new Error("Not authenticated");return o||n(l),V(l)},enabled:t&&!!s});return t?e.jsxs("div",{className:"min-h-screen flex flex-col",style:{background:"#f0e8dc"},children:[e.jsx(U,{}),e.jsxs("div",{className:"max-w-3xl mx-auto px-6 py-10",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs("div",{className:"text-[11px] font-mono uppercase tracking-widest mb-4",style:{color:"rgba(58,28,0,0.4)"},children:[e.jsx(g,{href:"/brands",className:"hover:opacity-70 transition-opacity",children:"Brands"})," / ","My Brand"]}),e.jsx("h1",{className:"font-display text-3xl mb-2",style:{color:"#2e1505"},children:"My Brand"}),e.jsx("p",{className:"text-sm",style:{color:"rgba(58,28,0,0.55)"},children:"Manage your brand's follower polls and view engagement."})]}),s?d?e.jsx("div",{className:"text-center py-20",style:{color:"rgba(58,28,0,0.4)"},children:"Loadingâ¦"}):x?e.jsx("div",{className:"rounded-2xl p-8 text-center",style:{background:"white",border:"1px solid #fca5a5"},children:e.jsx("p",{className:"text-sm",style:{color:"#dc2626"},children:"Failed to load brands."})}):c.length===0?e.jsxs("div",{className:"rounded-2xl p-14 text-center",style:{background:"white",border:"1px solid rgba(58,28,0,0.08)"},children:[e.jsx(b,{className:"w-10 h-10 mx-auto mb-4",style:{color:"rgba(58,28,0,0.15)"}}),e.jsx("p",{className:"font-semibold mb-2",style:{color:"#2e1505"},children:"No brands assigned"}),e.jsx("p",{className:"text-sm",style:{color:"rgba(58,28,0,0.5)"},children:"Contact an admin to be assigned as brand owner."})]}):e.jsx("div",{className:"space-y-4",children:c.map(l=>e.jsx(G,{brand:l,token:o??""},l.id))}):e.jsxs("div",{className:"rounded-2xl p-10 text-center",style:{background:"white",border:"1px solid rgba(58,28,0,0.08)"},children:[e.jsx(b,{className:"w-8 h-8 mx-auto mb-3",style:{color:"rgba(58,28,0,0.2)"}}),e.jsx("p",{className:"font-semibold mb-4",style:{color:"#2e1505"},children:"Sign in to manage your brand"}),e.jsx(g,{href:"/sign-in",className:"inline-flex px-5 py-2 rounded-xl text-sm font-semibold",style:{background:"#b5622a",color:"#fff"},children:"Sign in"})]})]}),e.jsx(M,{})]}):null}export{xe as default};
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.