PageSourceSearch

https://socialnex.ai/assets/social_.businesses-Cr6g63M6.js

js socialnex.ai collected 2026-10-05 15:11:02 UTC 46,696 bytes, 1 lines download raw bytes

1import{r as e,j as s}from"./react-vendor-hAxFZxNQ.js";import{$ as t,a0 as a,a1 as n,a2 as i,al as r,ar as o,aj as l,at as d,ai as c,c as m,aw as u,_ as h,f as x,as as p,aO as g,aU as f,m as b,Z as j,L as v,b6 as y,b7 as N,b8 as w,b9 as k,ba as C,bb as S,bc as _,bd as z,D as F,Q as $,U as A,V as E,W as B,Y as L}from"./main-C-ofR5-x.js";import{C as T,a as R,b as P,d as I,c as U}from"./card-DrHTqHqj.js";import{S as O}from"./switch-DrPErZvU.js";import"./ui-DlHKYJvh.js";function D({open:x,onOpenChange:p,onCreated:g}){const[f,b]=e.useState(""),[j,v]=e.useState(!1);e.useEffect(()=>{x&&b("")},[x]);const y=async()=>{if(f.trim()){v(!0);try{const e=await u.createCompanyProfile({name:f.trim()});g(e),h({title:"Business profile created"})}catch(e){h({title:"Failed to create business profile",description:e instanceof Error?e.message:"Unknown error",variant:"destructive"})}finally{v(!1)}}};return s.jsx(t,{open:x,onOpenChange:p,children:s.jsxs(a,{children:[s.jsxs(n,{children:[s.jsx(i,{children:"Add business profile"}),s.jsx(r,{children:"Create a business profile to use as AI context for posts, even before connecting a social account."})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:"new-business-name",children:"Business name"}),s.jsx(l,{id:"new-business-name",value:f,onChange:e=>b(e.target.value),placeholder:"Your business name",autoFocus:!0,onKeyDown:e=>{"Enter"===e.key&&f.trim()&&y()}})]}),s.jsxs(d,{children:[s.jsx(c,{variant:"ghost",onClick:()=>p(!1),disabled:j,children:"Cancel"}),s.jsxs(c,{onClick:y,disabled:j||!f.trim(),children:[j&&s.jsx(m,{name:"Loader2",className:"size-4 mr-1.5 animate-spin"}),"Create"]})]})]})})}function M({profile:t,onSaved:a}){const n=e.useRef(null),[i,r]=e.useState(!1),[o,l]=e.useState(!1),d=Boolean(t.brand_logo_url),x=i||o;return s.jsxs("div",{className:"w-40 md:w-44 shrink-0 space-y-1.5",children:[s.jsx("p",{className:"text-sm font-medium leading-none",children:"Brand logo"}),s.jsx("div",{className:"aspect-square w-full flex items-center justify-center overflow-hidden rounded-lg border border-border bg-muted/50",children:d?s.jsx("img",{src:t.brand_logo_url,alt:`${t.name||"Business"} logo`,className:"size-full object-contain p-3"}):s.jsx(m,{name:"Image",className:"size-7 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-2 pt-0.5",children:[s.jsxs(c,{type:"button",variant:"outline",size:"sm",onClick:()=>n.current?.click(),disabled:x,className:"w-full",children:[i?s.jsx(m,{name:"Loader2",className:"size-3.5 mr-1.5 animate-spin"}):s.jsx(m,{name:"Upload",className:"size-3.5 mr-1.5"}),d?"Replace logo":"Upload logo"]}),d&&s.jsxs(c,{type:"button",variant:"outline",size:"sm",onClick:async()=>{l(!0);try{const e=await u.removeBrandLogo(t.id);a(e),h({title:"Brand logo removed"})}catch(e){h({title:"Failed to remove logo",description:e instanceof Error?e.message:"Unknown error",variant:"destructive"})}finally{l(!1)}},disabled:x,className:"w-full text-destructive hover:text-destructive",children:[o?s.jsx(m,{name:"Loader2",className:"size-3.5 mr-1.5 animate-spin"}):s.jsx(m,{name:"Trash2",className:"size-3.5 mr-1.5"}),"Remove"]}),s.jsx("p",{className:"text-[11px] leading-snug text-muted-foreground",children:"PNG, JPG, GIF or WebP, up to 5MB"})]}),s.jsx("input",{ref:n,type:"file",accept:"image/*",className:"hidden",onChange:async e=>{const s=e.target.files?.[0];if(e.target.value="",s)if(s.type.startsWith("image/"))if(s.size>5242880)h({title:"Logo is too large",description:"Choose an image under 5MB.",variant:"destructive"});else{r(!0);try{const e=await u.uploadBrandLogo(t.id,s);a(e),h({title:"Brand logo updated"})}catch(n){h({title:"Failed to upload logo",description:n instanceof Error?n.message:"Unknown error",variant:"destructive"})}finally{r(!1)}}else h({title:"That file isn’t an image",description:"Choose a PNG, JPG, GIF or WebP file.",variant:"destructive"})}})]})}function W({profile:t,onSaved:a}){const[n,i]=e.useState(!1),r=Boolean(t.brand_logo_url);return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg bg-muted/50 p-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-medium",children:"Automatically add my logo to AI-generated creatives"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:r?"Your logo is placed on every image the AI generates for this business.":"Upload a logo first to turn this on."})]}),s.jsx(O,{checked:t.auto_attach_logo,onCheckedChange:async e=>{i(!0);try{const s=await u.updateCompanyProfile(t.id,{auto_attach_logo:e});a(s)}catch(s){h({title:"Failed to update logo setting",description:s instanceof Error?s.message:"Unknown error",variant:"destructive"})}finally{i(!1)}},disabled:n||!r,"aria-label":"Automatically add my logo to AI-generated creatives"})]})}function K(e){return"edited"===e.origin||"suppressed"===e.origin}function G(e){return"list"===e.input?Array.isArray(e.value)?[...e.value]:e.value?[String(e.value)]:[]:Array.isArray(e.value)?e.value.join(", "):e.value??""}function Y(e,s){return Array.isArray(e)&&Array.isArray(s)?e.length===s.length&&e.every((e,t)=>e===s[t]):e===s}function H(e){return e.split(",").map(e=>
1e.trim()).filter(Boolean)}function V({section:t,idPrefix:a,saving:n,onSave:i,onReset:r,onCancel:d}){const[u,h]=e.useState(()=>Object.fromEntries(t.fields.map(e=>[e.key,G(e)]))),[g,f]=e.useState({}),b=t.fields.filter(K),j=e=>{const s=u[e.key];return"list"===e.input?[...Array.isArray(s)?s:[],...H(g[e.key]??"")]:"string"==typeof s?s.trim():""},v=()=>{const e={};for(const s of t.fields){const t=j(s);Y(t,G(s))||(e[s.category]||(e[s.category]={}),e[s.category][s.key]=t)}return e},y=(e,s)=>{h(t=>({...t,[e]:s}))},N=Object.keys(v()).length>0;return s.jsxs("div",{className:"rounded-lg border border-border p-4 space-y-3",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-semibold",children:t.label}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Your edits replace what we detected and survive future website analyses."})]}),b.length>0&&s.jsxs(c,{variant:"ghost",size:"sm",onClick:()=>r((()=>{const e={};for(const s of b)e[s.category]||(e[s.category]={}),e[s.category][s.key]=null;return e})()),disabled:n,className:"shrink-0 h-7 px-2 text-xs text-muted-foreground hover:text-foreground",title:"Delete your edits and go back to the detected values",children:[s.jsx(m,{name:"RotateCcw",className:"size-3.5 mr-1.5"}),"Reset to detected"]})]}),s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:t.fields.map(e=>{const t=`${a}-${e.category}-${e.key}`,i="text"!==e.input,r=u[e.key];return s.jsxs("div",{className:x("space-y-1.5",i&&"sm:col-span-2"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(o,{htmlFor:t,children:e.label}),"edited"===e.origin&&s.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wide text-primary",children:"Edited"}),"suppressed"===e.origin&&s.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:"Hidden"})]}),"list"===e.input?s.jsx(q,{id:t,chips:Array.isArray(r)?r:[],pendingText:g[e.key]??"",disabled:n,onChipsChange:s=>y(e.key,s),onPendingChange:s=>f(t=>({...t,[e.key]:s}))}):"textarea"===e.input?s.jsx(p,{id:t,rows:3,value:"string"==typeof r?r:"",onChange:s=>y(e.key,s.target.value),disabled:n,placeholder:"Nothing detected yet"}):s.jsx(l,{id:t,value:"string"==typeof r?r:"",onChange:s=>y(e.key,s.target.value),disabled:n,placeholder:"Nothing detected yet"}),"suppressed"===e.origin&&s.jsx("p",{className:"text-xs text-muted-foreground",children:"Cleared on purpose — this line is left out of the AI prompt."})]},`${e.category}.${e.key}`)})}),s.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:"Clear a field to leave it out of the prompt entirely."}),s.jsxs("div",{className:"flex justify-end gap-2 shrink-0",children:[s.jsx(c,{variant:"ghost",size:"sm",onClick:d,disabled:n,children:"Cancel"}),s.jsxs(c,{size:"sm",onClick:()=>i(v()),disabled:n||!N,children:[n&&s.jsx(m,{name:"Loader2",className:"size-4 mr-1.5 animate-spin"}),"Save"]})]})]})]})}function q({id:e,chips:t,pendingText:a,disabled:n,onChipsChange:i,onPendingChange:r}){const o=e=>{const s=H(e).filter(e=>!t.includes(e));s.length&&i([...t,...s]),r("")};return s.jsxs("div",{className:x("flex flex-wrap items-center gap-1.5 rounded-md border border-input bg-transparent px-2 py-1.5 shadow-sm","focus-within:outline-none focus-within:ring-1 focus-within:ring-ring",n&&"cursor-not-allowed opacity-50"),children:[t.map((e,a)=>s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-muted px-2 py-0.5 text-xs text-foreground",children:[e,s.jsx("button",{type:"button",onClick:()=>i(t.filter((e,s)=>s!==a)),disabled:n,className:"text-muted-foreground hover:text-destructive transition-colors disabled:pointer-events-none",title:`Remove ${e}`,children:s.jsx(m,{name:"X",className:"size-3"})})]},`${e}-${a}`)),s.jsx("input",{id:e,value:a,onChange:e=>r(e.target.value),onKeyDown:e=>{if("Enter"===e.key||","===e.key)return e.preventDefault(),void o(a);"Backspace"===e.key&&!a&&t.length&&(e.preventDefault(),i(t.slice(0,-1)))},onBlur:()=>o(a),disabled:n,placeholder:t.length?"Add another...":"Nothing detected yet",className:"flex-1 min-w-[8rem] bg-transparent py-0.5 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed md:text-sm"})]})}const J=/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function X(e){const s=J.exec(e.trim());return s?`#${(3===s[1].length?s[1].split("").map(e=>e+e).join(""):s[1]).toLowerCase()}`:null}function Z(e){return{colors:e.colors,headingFont:e.fonts.heading,bodyFont:e.fonts.body,address:e.address,services:e.services,tagline:e.tagline,cta:e.cta}}const Q={colors:[["visual_brand","primary_colors"],["visual_brand","secondary_colors"]],headingFont:[["visual_brand","heading_font"]],bodyFont:[["visual_brand","body_font"]],address:[["location","address"]],services:[["identity","services"]],tagline:[["brand","tagline"]],cta:[["brand","cta"]]};function ee(e,s){return Q[s].some(([s,t])=>t in(e.knowledge_overrides?.[s]??{}))}function se(e,s,t,a){e[s]||(e[s]={}),e[s][t]=a}function te({profile:t,onSaved:a,refreshToken:n,onKnowledgeSaved:i,onRefreshFromWebsite:r,refreshDisabledReason:o,refreshing:d}){const[p,f]=e.useState(null),[b,j]=e.useState(!0),[v,y]=e.useState(null),[N,w]=e.useState(!1),[k,C]=e.useState(null),[S,_]=e.useState(""),[z,F]=e.useState(new Set),[$,A]=e.useState(!1),[E,B]=e.useState(!1),L=e.useRef(null),T=e.useCallback(()=>{j(!0),y(null),u.getBrandKit(t.id).then(f).catch(e=>y(e instanceof Error?e.message:"Failed to load brand kit")).finally(()=>j(!1))},[t.id]);e.useEffect(()=>{T()},[T,t.updated_at,t.brand_logo_url,n]);const R=()=>{w(!1),C(null),F(new Set)},P=(e,s)=>{C(t=>t?{...t,[e]:s}:t),F(s=>{if(!s.has(e))return s;const t=new Set(s);return t.delete(e),t})},I=e=>{F(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t}),p&&C(s=>s?{...s,[e]:Z(p)[e]}:s)},U=e=>{const s=document.getElementById(`${e}-${t.id}`);s?.scrollIntoView({behavior:"smooth",block:"center"}
1),s?.focus({preventScroll:!0})};return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"text-base font-semibold text-foreground",children:"Brand kit"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"The logo, colors, fonts and details the AI Graphic Studio puts on every graphic."})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs(c,{variant:"outline",size:"sm",onClick:r,disabled:Boolean(o)||d||$,title:o,children:[s.jsx(m,{name:d?"Loader2":"RefreshCw",className:x("size-4 mr-1.5",d&&"animate-spin")}),d?"Refreshing...":"Refresh from website"]}),!N&&s.jsxs(c,{variant:"outline",size:"sm",onClick:()=>{p&&(C(Z(p)),_(""),F(new Set),w(!0))},disabled:!p||b,children:[s.jsx(m,{name:"Pencil",className:"size-4 mr-1.5"}),"Edit"]})]})]}),v&&!p?s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-destructive/30 bg-destructive/5 dark:bg-destructive/10 p-3",children:[s.jsx("p",{className:"text-sm text-destructive",children:v}),s.jsx(c,{variant:"outline",size:"sm",onClick:T,children:"Retry"})]}):p?N&&k?s.jsxs("div",{className:"rounded-lg border border-border p-4 space-y-4",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsxs(re,{label:"Brand colors",wide:!0,edited:ee(p,"colors"),resetting:z.has("colors"),onToggleReset:()=>I("colors"),disabled:$,children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[k.colors.map((e,t)=>s.jsxs("div",{className:"flex items-center gap-1.5 rounded-md border border-input p-1 pr-1.5",children:[s.jsx("input",{type:"color","aria-label":`Brand color ${t+1}`,value:X(e)??"#000000",onChange:e=>P("colors",k.colors.map((s,a)=>a===t?e.target.value:s)),disabled:$,className:"size-7 cursor-pointer rounded border-0 bg-transparent p-0"}),s.jsx(l,{value:e,onChange:e=>P("colors",k.colors.map((s,a)=>a===t?e.target.value:s)),disabled:$,className:"h-7 w-24 px-2 text-xs font-mono"}),s.jsx("button",{type:"button",onClick:()=>P("colors",k.colors.filter((e,s)=>s!==t)),disabled:$,className:"text-muted-foreground hover:text-destructive transition-colors disabled:pointer-events-none",title:"Remove color",children:s.jsx(m,{name:"X",className:"size-3.5"})})]},t)),s.jsxs(c,{type:"button",variant:"ghost",size:"sm",onClick:()=>P("colors",[...k.colors,k.colors[k.colors.length-1]??"#1a73e8"]),disabled:$,className:"h-8 px-2 text-xs",children:[s.jsx(m,{name:"Plus",className:"size-3.5 mr-1"}),"Add color"]})]}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"The first color is treated as your primary brand color."})]}),s.jsx(re,{label:"Heading font",htmlFor:`brand-kit-heading-${t.id}`,edited:ee(p,"headingFont"),resetting:z.has("headingFont"),onToggleReset:()=>I("headingFont"),disabled:$,children:s.jsx(l,{id:`brand-kit-heading-${t.id}`,value:k.headingFont,onChange:e=>P("headingFont",e.target.value),disabled:$,placeholder:"e.g. Montserrat"})}),s.jsx(re,{label:"Body font",htmlFor:`brand-kit-body-${t.id}`,edited:ee(p,"bodyFont"),resetting:z.has("bodyFont"),onToggleReset:()=>I("bodyFont"),disabled:$,children:s.jsx(l,{id:`brand-kit-body-${t.id}`,value:k.bodyFont,onChange:e=>P("bodyFont",e.target.value),disabled:$,placeholder:"e.g. Open Sans"})}),s.jsx(re,{label:"Tagline",htmlFor:`brand-kit-tagline-${t.id}`,edited:ee(p,"tagline"),resetting:z.has("tagline"),onToggleReset:()=>I("tagline"),disabled:$,children:s.jsx(l,{id:`brand-kit-tagline-${t.id}`,value:k.tagline,onChange:e=>P("tagline",e.target.value),disabled:$,placeholder:"Nothing detected yet"})}),s.jsx(re,{label:"Call to action",htmlFor:`brand-kit-cta-${t.id}`,edited:ee(p,"cta"),resetting:z.has("cta"),onToggleReset:()=>I("cta"),disabled:$,children:s.jsx(l,{id:`brand-kit-cta-${t.id}`,value:k.cta,onChange:e=>P("cta",e.target.value),disabled:$,placeholder:"e.g. Call today for a free quote"})}),s.jsx(re,{label:"Address",htmlFor:`brand-kit-address-${t.id}`,wide:!0,edited:ee(p,"address"),resetting:z.has("address"),onToggleReset:()=>I("address"),disabled:$,children:s.jsx(l,{id:`brand-kit-address-${t.id}`,value:k.address,onChange:e=>P("address",e.target.value),disabled:$,placeholder:"123 Main St, Phoenix, AZ 85001"})}),s.jsx(re,{label:"Services",htmlFor:`brand-kit-services-${t.id}`,wide:!0,edited:ee(p,"services"),resetting:z.has("services"),onToggleReset:()=>I("services"),disabled:$,children:s.jsx(q,{id:`brand-kit-services-${t.id}`,chips:k.services,pendingText:S,disabled:$,onChipsChange:e=>P("services",e),onPendingChange:_})})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:"Phone, website and email come from the business details above. Your edits survive future website refreshes."}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(c,{variant:"ghost",size:"sm",onClick:R,disabled:$,children:"Cancel"}),s.jsxs(c,{size:"sm",onClick:async()=>{const e=(()=>
1{if(!p||!k)return{};const e={},s=Z(p);for(const n of z)for(const[s,t]of Q[n])se(e,s,t,null);if(!z.has("colors")&&k.colors.join("\n")!==s.colors.join("\n")){const s=[];for(const e of k.colors){const t=X(e);if(!t)return`"${e}" isn't a hex color (e.g. #1a73e8).`;s.includes(t)||s.push(t)}se(e,"visual_brand","primary_colors",s.slice(0,1)),se(e,"visual_brand","secondary_colors",s.slice(1))}const t=[...k.services,...S.split(",").map(e=>e.trim()).filter(Boolean)];z.has("services")||t.join("\n")===s.services.join("\n")||se(e,"identity","services",t);const a=[["headingFont","visual_brand","heading_font"],["bodyFont","visual_brand","body_font"],["address","location","address"],["tagline","brand","tagline"],["cta","brand","cta"]];for(const[n,i,r]of a){const t=k[n].trim();z.has(n)||t===s[n]||se(e,i,r,t)}return e})();if("string"!=typeof e)if(Object.keys(e).length){A(!0);try{await u.updateKnowledgeOverrides(t.id,e),R(),T(),i(),h({title:"Brand kit saved"})}catch(s){h({title:"Failed to save brand kit",description:s instanceof Error?s.message:"Unknown error",variant:"destructive"})}finally{A(!1)}}else R();else h({title:"Check your brand colors",description:e,variant:"destructive"})},disabled:$,children:[$&&s.jsx(m,{name:"Loader2",className:"size-4 mr-1.5 animate-spin"}),"Save"]})]})]})]}):s.jsxs("div",{className:x("grid grid-cols-1 sm:grid-cols-2 gap-4",b&&"opacity-60 transition-opacity"),children:[s.jsx(ae,{label:"Logo",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"size-20 shrink-0 rounded-lg border border-border bg-muted/40 dark:bg-muted/20 overflow-hidden flex items-center justify-center",children:p.logo_url?s.jsx("img",{src:p.logo_url,alt:`${p.name||"Business"} logo`,className:"size-full object-contain p-2"}):s.jsx(m,{name:"ImageOff",className:"size-6 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-1.5 min-w-0",children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:"brand_logo"===p.logo_source?"Your uploaded logo":"asset"===p.logo_source?"Detected automatically — upload your own to replace it":"No logo yet"}),s.jsx("input",{ref:L,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"hidden",onChange:async e=>{const s=e.target.files?.[0];if(e.target.value="",s)if(s.size>5242880)h({title:"Logo is too large",description:"Logo must be 5MB or smaller.",variant:"destructive"});else{B(!0);try{a(await u.uploadBrandLogo(t.id,s)),h({title:"Logo uploaded"})}catch(n){h({title:"Failed to upload logo",description:n instanceof Error?n.message:"Unknown error",variant:"destructive"})}finally{B(!1)}}}}),s.jsxs(c,{variant:"outline",size:"sm",onClick:()=>L.current?.click(),disabled:E,className:"h-7 px-2.5 text-xs",children:[s.jsx(m,{name:E?"Loader2":"Upload",className:x("size-3.5 mr-1.5",E&&"animate-spin")}),"brand_logo"===p.logo_source?"Replace":"Upload logo"]})]})]})}),s.jsx(ae,{label:"Colors",edited:ee(p,"colors"),children:p.colors.length?s.jsx("div",{className:"flex flex-wrap gap-2",children:p.colors.map(e=>s.jsxs("div",{className:"flex flex-col items-center gap-1",children:[s.jsx("span",{className:"size-10 rounded-md border border-border shadow-sm",style:{backgroundColor:e},title:e}),s.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:e})]},e))}):s.jsx(ne,{children:"No brand colors detected yet"})}),s.jsx(ae,{label:"Fonts",edited:ee(p,"headingFont")||ee(p,"bodyFont"),children:p.fonts.heading||p.fonts.body?s.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-sm",children:[s.jsx("dt",{className:"text-muted-foreground",children:"Heading"}),s.jsx("dd",{className:"font-semibold text-foreground truncate",style:{fontFamily:p.fonts.heading||void 0},children:p.fonts.heading||"—"}),s.jsx("dt",{className:"text-muted-foreground",children:"Body"}),s.jsx("dd",{className:"text-foreground truncate",style:{fontFamily:p.fonts.body||void 0},children:p.fonts.body||"—"})]}):s.jsx(ne,{children:"No fonts detected yet"})}),s.jsx(ae,{label:"Contact",children:s.jsxs("div",{className:"space-y-1 text-sm",children:[s.jsx(ie,{icon:"Phone",value:p.phone,placeholder:"No phone",onEdit:()=>U("phone")}),s.jsx(ie,{icon:"Globe",value:p.website,placeholder:"No website",onEdit:()=>U("website")}),s.jsx(ie,{icon:"Mail",value:p.email,placeholder:"No email",onEdit:()=>U("email")})]})}),s.jsx(ae,{label:"Address",edited:ee(p,"address"),children:p.address?s.jsx("p",{className:"text-sm text-foreground",children:p.address}):p.city||p.state?s.jsx("p",{className:"text-sm text-foreground",children:[p.city,p.state].filter(
1Boolean).join(", ")}):s.jsx(ne,{children:"No address detected yet"})}),s.jsx(ae,{label:"Tagline & call to action",edited:ee(p,"tagline")||ee(p,"cta"),children:s.jsxs("div",{className:"space-y-1 text-sm",children:[p.tagline?s.jsx("p",{className:"text-foreground",children:p.tagline}):s.jsx(ne,{children:"No tagline"}),p.cta?s.jsx("p",{className:"font-medium text-primary",children:p.cta}):s.jsx(ne,{children:"No call to action"})]})}),s.jsx(ae,{label:"Services",edited:ee(p,"services"),wide:!0,children:p.services.length?s.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.services.map(e=>s.jsx("span",{className:"rounded bg-muted px-2 py-0.5 text-xs text-foreground",children:e},e))}):s.jsx(ne,{children:"No services detected yet"})})]}):s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsx(g,{className:"h-24"}),s.jsx(g,{className:"h-24"}),s.jsx(g,{className:"h-16"}),s.jsx(g,{className:"h-16"})]})]})}function ae({label:e,edited:t=!1,wide:a=!1,children:n}){return s.jsxs("div",{className:x("rounded-lg border border-border bg-card p-3 space-y-2",a&&"sm:col-span-2"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:e}),t&&s.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wide text-primary",children:"Edited"})]}),n]})}function ne({children:e}){return s.jsx("p",{className:"text-sm text-muted-foreground italic",children:e})}function ie({icon:e,value:t,placeholder:a,onEdit:n}){return s.jsxs("div",{className:"group flex items-center gap-2 min-w-0",children:[s.jsx(m,{name:e,className:"size-3.5 shrink-0 text-muted-foreground"}),s.jsx("span",{className:x("truncate",t?"text-foreground":"text-muted-foreground italic"),children:t||a}),s.jsx("button",{type:"button",onClick:n,className:"ml-auto shrink-0 text-muted-foreground hover:text-foreground transition-colors",title:"Edit in business details",children:s.jsx(m,{name:"Pencil",className:"size-3.5"})})]})}function re({label:e,htmlFor:t,wide:a=!1,edited:n,resetting:i,onToggleReset:r,disabled:l,children:d}){return s.jsxs("div",{className:x("space-y-1.5",a&&"sm:col-span-2"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(o,{htmlFor:t,children:e}),n&&!i&&s.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wide text-primary",children:"Edited"}),n&&s.jsx("button",{type:"button",onClick:r,disabled:l,className:"ml-auto text-xs text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none",title:"Drop your edit and use the detected value",children:i?"Keep my edit":"Use detected"})]}),s.jsx("div",{className:x("space-y-1.5",i&&"opacity-50 pointer-events-none"),children:d}),i&&s.jsx("p",{className:"text-xs text-muted-foreground",children:"Will switch back to the detected value when you save."})]})}function oe({companyProfileId:t,competitors:a,onCompetitorsChange:n}){const[i,r]=e.useState(!1),[d,x]=e.useState(""),[p,g]=e.useState(""),[f,b]=e.useState(""),[j,v]=e.useState(""),[y,N]=e.useState(!1),[w,k]=e.useState(null),C=(a?.length??0)>=3,S=()=>{x(""),g(""),b(""),v(""),r(!1)};return s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-3 gap-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-semibold",children:"Competitors"}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:["Track up to ",3," competitors for this business"]})]}),!C&&!i&&s.jsxs(c,{variant:"outline",size:"sm",onClick:()=>r(!0),className:"shrink-0",children:[s.jsx(m,{name:"Plus",className:"size-3.5 mr-1.5"}),"Add competitor"]})]}),null===a?s.jsx("div",{className:"flex items-center py-4",children:s.jsx(m,{name:"Loader2",className:"size-4 animate-spin text-muted-foreground"})}):s.jsxs("div",{className:"space-y-2",children:[a.map(e=>s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg bg-muted/50 p-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:e.name}),s.jsx("p",{className:"text-xs text-muted-foreground truncate",children:[e.website,e.phone].filter(
1Boolean).join(" · ")||e.address||"No details added"})]}),s.jsx("button",{type:"button",onClick:()=>(async e=>{if(confirm(`Remove ${e.name} from competitors?`)){k(e.id);try{await u.deleteCompetitor(t,e.id),n(s=>s?.filter(s=>s.id!==e.id)??s)}catch(s){h({title:"Failed to remove competitor",description:s instanceof Error?s.message:"Unknown error",variant:"destructive"})}finally{k(null)}}})(e),disabled:w===e.id,className:"p-1.5 rounded-lg text-muted-foreground hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors disabled:opacity-50 shrink-0",title:"Remove competitor",children:w===e.id?s.jsx(m,{name:"Loader2",className:"size-4 animate-spin"}):s.jsx(m,{name:"Trash2",className:"size-4"})})]},e.id)),0===a.length&&!i&&s.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No competitors added yet."})]}),i&&s.jsxs("div",{className:"mt-3 rounded-lg border border-border p-4 space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:"new-competitor-name",children:"Name"}),s.jsx(l,{id:"new-competitor-name",value:d,onChange:e=>x(e.target.value),placeholder:"Competitor business name",autoFocus:!0,className:"bg-background"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:"new-competitor-website",children:"Website"}),s.jsx(l,{id:"new-competitor-website",type:"url",value:p,onChange:e=>g(e.target.value),placeholder:"https://competitor.com",className:"bg-background"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:"new-competitor-phone",children:"Phone"}),s.jsx(l,{id:"new-competitor-phone",type:"tel",value:f,onChange:e=>b(e.target.value),placeholder:"(555) 123-4567",className:"bg-background"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:"new-competitor-address",children:"Address"}),s.jsx(l,{id:"new-competitor-address",value:j,onChange:e=>v(e.target.value),placeholder:"City, State",className:"bg-background"})]})]}),s.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[s.jsx(c,{variant:"ghost",size:"sm",onClick:S,disabled:y,children:"Cancel"}),s.jsxs(c,{size:"sm",onClick:async()=>{if(d.trim()&&!C){N(!0);try{const e={name:d.trim()};p.trim()&&(e.website=p.trim()),f.trim()&&(e.phone=f.trim()),j.trim()&&(e.address=j.trim());const s=await u.addCompetitor(t,e);n(e=>[...e??[],s]),S(),h({title:"Competitor added"})}catch(e){h({title:"Failed to add competitor",description:e instanceof Error?e.message:"Unknown error",variant:"destructive"})}finally{N(!1)}}},disabled:y||!d.trim(),children:[y&&s.jsx(m,{name:"Loader2",className:"size-4 mr-1.5 animate-spin"}),"Add competitor"]})]})]})]})}function le({companyProfileId:t,businessName:a,refreshToken:n=0,onKnowledgeSaved:i}){const[r,o]=e.useState(!1),[l,d]=e.useState(null),[p,g]=e.useState(!1),[y,N]=e.useState(null),[w,k]=e.useState(!1),[C,S]=e.useState(!1),[_,z]=e.useState(null),[F,$]=e.useState(null),[A,E]=e.useState(0),B=e.useCallback(()=>{g(!0),N(null),u.getContextPreview(t).then(d).catch(e=>N(e instanceof Error?e.message:"Failed to load AI context preview")).finally(()=>g(!1))},[t]);e.useEffect(()=>{n&&(z(null),r?B():d(null))},[n]);const L=async(e,s,{successTitle:a,failureTitle:n,keepOpen:r})=>{if(Object.keys(s).length){$(e);try{const e=await u.updateKnowledgeOverrides(t,s);d(e),E(e=>e+1),r||z(null),i?.(),h({title:a})}catch(o){h({title:n,description:o instanceof Error?o.message:"Unknown error",variant:"destructive"})}finally{$(null)}}else z(null)},T=l?.sections.find(e=>e.key===_)??null;return s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-3 gap-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-semibold",children:"What the AI knows about this business"}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:["See what info is being used to write posts for ",a||"this business"]})]}),s.jsxs(c,{variant:"outline",size:"sm",onClick:()=>{const e=!r;o(e),!e||l||p||B()},className:"shrink-0",children:[p?s.jsx(m,{name:"Loader2",className:"size-3.5 mr-1.5 animate-spin"}):s.jsx(m,{name:r?"ChevronUp":"Eye",className:"size-3.5 mr-1.5"}),r?"Hide":"Show"]})]}),s.jsx(f,{initial:!1,children:r&&s.jsx(b.div,{initial:{height:0,opacity:0}
1,animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.25,ease:"easeOut"},className:"overflow-hidden",children:s.jsxs("div",{className:"pt-1 space-y-3",children:[y&&s.jsx("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-3 text-sm text-destructive",children:y}),p&&!l&&s.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-muted-foreground",children:[s.jsx(m,{name:"Loader2",className:"size-4 animate-spin"}),"Assembling the same context the AI would receive..."]}),l&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-wrap gap-1.5",children:l.sections.map(e=>{const t=function(e){return Boolean(e.editable)&&Array.isArray(e.fields)&&e.fields.length>0}(e),a=function(e){return Array.isArray(e.fields)?e.fields.filter(K).length:0}(e),n=_===e.key;return s.jsxs(j,{variant:e.included?"secondary":"outline",className:x(e.included?"text-foreground":"font-normal text-muted-foreground",t&&"group cursor-pointer select-none hover:text-foreground",n&&"ring-1 ring-ring"),title:t?n?"Close editor":`Edit what the AI knows about ${e.label.toLowerCase()}`:e.reason??void 0,role:t?"button":void 0,tabIndex:t?0:void 0,"aria-expanded":t?n:void 0,onClick:t?()=>z(n?null:e.key):void 0,onKeyDown:t?s=>{"Enter"!==s.key&&" "!==s.key||(s.preventDefault(),z(n?null:e.key))}:void 0,children:[e.included?s.jsx(m,{name:"Check",className:"size-3 mr-1 text-green-600 dark:text-green-500"}):s.jsx(m,{name:"Minus",className:"size-3 mr-1"}),e.label,e.detail?` (${e.detail})`:"",a>0&&s.jsx("span",{className:"ml-1.5 size-1.5 shrink-0 rounded-full bg-primary",title:`${a} value${1===a?"":"s"} edited by your team`}),t&&s.jsx(m,{name:n?"X":"Pencil",className:"size-3 ml-1.5 opacity-40 group-hover:opacity-100 transition-opacity"})]},e.key)})}),s.jsx(f,{initial:!1,children:T&&s.jsx(b.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.25,ease:"easeOut"},className:"overflow-hidden",children:s.jsx(V,{section:T,idPrefix:`knowledge-${t}`,saving:F===T.key,onCancel:()=>z(null),onSave:e=>L(T.key,e,{successTitle:`${T.label} updated`,failureTitle:`Failed to update ${T.label.toLowerCase()}`,keepOpen:!1}),onReset:e=>L(T.key,e,{successTitle:`${T.label} reset to detected values`,failureTitle:`Failed to reset ${T.label.toLowerCase()}`,keepOpen:!0})},`${T.key}-${A}`)})}),l.sections.some(e=>!e.included&&e.actionable&&e.reason)&&s.jsx("div",{className:"rounded-md border border-dashed p-2.5 space-y-1.5",children:l.sections.filter(e=>!e.included&&e.actionable&&e.reason).map(e=>s.jsxs("p",{className:"text-xs leading-snug text-muted-foreground",children:[s.jsxs("span",{className:"font-medium text-foreground",children:[e.label,":"]})," ","competitive"===e.key||"owner_instructions"===e.key?s.jsx("button",{type:"button",onClick:()=>document.getElementById("competitive"===e.key?`competitors-${t}`:`ai-instructions-${t}`)?.scrollIntoView({behavior:"smooth",block:"center"}),className:"text-left underline decoration-dotted underline-offset-2 hover:text-foreground transition-colors",children:e.reason}):s.jsx(v,{to:"/local/reviews",className:"underline decoration-dotted underline-offset-2 hover:text-foreground transition-colors",children:e.reason})]},e.key))}),s.jsxs("button",{type:"button",onClick:()=>S(e=>!e),className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(m,{name:C?"ChevronUp":"ChevronDown",className:"size-3.5"}),C?"Hide the raw AI prompt":"Show the raw AI prompt (technical)"]}),C&&s.jsxs("div",{className:"rounded-md border bg-muted/50 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b bg-muted/50",children:[s.jsxs("span",{className:"text-xs text-muted-foreground font-medium",children:[l.context_length.toLocaleString()," characters"]}),s.jsx("button",{type:"button",onClick:async()=>{l?.context&&(await navigator.clipboard.writeText(l.context),k(!0),setTimeout(()=>k(!1),2e3))},className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",children:w?s.jsxs(s.Fragment,{children:[s.jsx(m,{name:"Check",className:"size-3.5"}),"Copied"]}):s.jsxs(s.Fragment,{children:[s.jsx(m,{name:"Copy",className:"size-3.5"}),"Copy"]})})]}),s.jsx("pre",{className:"max-h-96 overflow-auto whitespace-pre-wrap break-words p-3 font-mono text-xs text-foreground",children:l.context||"Nothing here yet — this business has no saved details, posts, or reviews yet."})]})]})]})})})]})}function de(e){const s=new Date(e),t=new Date,a=Math.floor((t.getTime()-s.getTime())/1e3);if(a<60)return"just now";const n=Math.floor(a/60);if(n<60)return`${n}m ago`;const i=Math.floor(n/60);if(i<24)return`${i}h ago`;const r=Math.floor(i/24);if(r<30)return`${r}d ago`;const o=Math.floor(r/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}function ce({profile:t,onSaved:a,onDeleted:n,highlighted:i=!1}){const[r,d]=e.useState(t.name),[x,g]=e.useState(t.website),[f,b]=e.useState(t.phone),[j,v]=e.useState(t.email),[F,$]=e.useState(t.ai_content_instructions),[A,E]=e.useState(!1),[B,L]=e.useState(!1),[O,D]=e.useState(!1),[K,G]=e.useState(!1),[Y,H]=e.useState(!1),[V,q]=e.useState(!1),[J,X]=e.useState(0),[Z,Q]=e.useState(0);e.useEffect(()=>{i&&document.getElementById(`business-${t.id}`)?.scrollIntoView({behavior:"smooth",block:"center"})},[i,t.id]);const[ee,se]=e.useState(null),ae=e.useCallback(()=>{u.getCompetitors(t.id).then(se).catch(()=>se([]))},[t.id]);e.useEffect(()=>{ae()},[ae]);const ne=r!==t.name||x!==t.website||f!==t.phone||j!==t.email||F!==t.ai_content_instructions,ie="queued"===t.website_scrape_status||"running"===t.website_scrape_status,re=x!==t.website,ce=async()=>
1{if(x.trim()&&!ie&&!re){q(!0);try{const e=await u.triggerWebsiteScrape(t.id);a(e)}catch(e){h({title:"Failed to start website analysis",description:e instanceof Error?e.message:"Unknown error",variant:"destructive"})}finally{q(!1)}}};return e.useEffect(()=>{if(!ie)return;const e=setInterval(async()=>{try{const e=await u.getCompanyProfile(t.id);a(e),"done"===e.website_scrape_status?(X(e=>e+1),Q(e=>e+1),h({title:"Website analyzed",description:`Extracted business details from ${e.website}`})):"failed"===e.website_scrape_status&&h({title:"Website analysis failed",description:"Could not extract business details from this website — check the URL and try again.",variant:"destructive"})}catch{}},3e3);return()=>clearInterval(e)},[ie,t.id]),s.jsxs(T,{id:`business-${t.id}`,className:i?"ring-2 ring-primary transition-shadow":void 0,children:[s.jsx(R,{children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx(P,{className:"text-xl truncate",children:t.name||"Untitled business"}),s.jsx(I,{children:t.domain||"Details used for AI-generated post content"})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs(c,{variant:"outline",size:"sm",onClick:()=>{const e={name:t.name,website:t.website,phone:t.phone,email:t.email,ai_content_instructions:t.ai_content_instructions,competitors:(ee??[]).map(e=>({name:e.name,website:e.website,phone:e.phone,address:e.address}))},s=`${(t.name||"business").replace(/[^a-zA-Z0-9]+/g,"-")}-context.json`,a=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(a),i=document.createElement("a");i.href=n,i.download=s,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(n)},children:[s.jsx(m,{name:"Download",className:"size-4 mr-1.5"}),"Export"]}),s.jsxs(c,{variant:"outline",size:"sm",onClick:()=>G(!0),disabled:B,children:[B?s.jsx(m,{name:"Loader2",className:"size-4 mr-1.5 animate-spin"}):s.jsx(m,{name:"Eraser",className:"size-4 mr-1.5"}),"Reset info"]}),s.jsxs(c,{variant:"outline",size:"sm",onClick:()=>H(!0),disabled:O,className:"text-destructive hover:text-destructive",children:[O?s.jsx(m,{name:"Loader2",className:"size-4 mr-1.5 animate-spin"}):s.jsx(m,{name:"Trash2",className:"size-4 mr-1.5"}),"Delete"]}),s.jsxs(c,{size:"sm",onClick:async()=>{E(!0);try{const e=await u.updateCompanyProfile(t.id,{name:r,website:x,phone:f,email:j,ai_content_instructions:F});a(e),h({title:"Business profile saved"})}catch(e){h({title:"Failed to save",description:e instanceof Error?e.message:"Unknown error",variant:"destructive"})}finally{E(!1)}},disabled:!ne||A,children:[A?s.jsx(m,{name:"Loader2",className:"size-4 mr-1.5 animate-spin"}):s.jsx(m,{name:"Check",className:"size-4 mr-1.5"}),"Save"]})]})]})}),s.jsxs(U,{className:"space-y-6",children:[s.jsxs("div",{id:`brand-logo-${t.id}`,className:"space-y-4 scroll-mt-6",children:[s.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[s.jsx(M,{profile:t,onSaved:a}),s.jsxs("div",{className:"flex-1 min-w-0 grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:`name-${t.id}`,children:"Business name"}),s.jsx(l,{id:`name-${t.id}`,value:r,onChange:e=>d(e.target.value),placeholder:"Your business name",className:"bg-background"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:`website-${t.id}`,children:"Website"}),s.jsx(l,{id:`website-${t.id}`,type:"url",value:x,onChange:e=>g(e.target.value),placeholder:"https://www.example.com",className:"bg-background"}),s.jsxs("div",{className:"flex items-center gap-2 pt-0.5",children:[s.jsxs(c,{type:"button",variant:"outline",size:"sm",onClick:ce,disabled:!x.trim()||ie||re||V,title:x.trim()?re?"Save your website changes before analyzing":ie?"Analysis already in progress":void 0:"Add a website first",className:"h-7 px-2.5 text-xs",children:[ie||V?s.jsx(m,{name:"Loader2",className:"size-3.5 mr-1.5 animate-spin"}):s.jsx(m,{name:"Sparkles",className:"size-3.5 mr-1.5"}),ie?"Analyzing...":"Analyze website"]}),!ie&&"failed"===t.website_scrape_status&&s.jsx("span",{className:"text-xs text-destructive",children:"Last analysis failed"}),!ie&&"done"===t.website_scrape_status&&t.website_last_scraped_at&&s.jsxs("span",{className:"text-xs text-muted-foreground",children:["Last analyzed ",de(t.website_last_scraped_at)]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:`phone-${t.id}`,children:"Phone"}),s.jsx(l,{id:`phone-${t.id}`,type:"tel",value:f,onChange:e=>b(e.target.value),placeholder:"(555) 123-4567",className:"bg-background"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(o,{htmlFor:`email-${t.id}`,children:"Email"}),s.jsx(l,{id:`email-${t.id}`,type:"email",value:j,onChange:e=>v(e.target.value),placeholder:"[email protected]",className:"bg-background"})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2 scroll-mt-6",id:`ai-instructions-${t.id}`,children:[s.jsx(o,{htmlFor:`ai-instructions-input-${t.id}`,children:"Universal posting instructions"}),s.jsx(p,{id:`ai-instructions-input-${t.id}`,value:F,onChange:e=>$(e.target.value),placeholder:"e.g. End every post with #YourHashtag. Mention our happy-hour drink specials when relevant. Never use emojis.",maxLength:1500,rows:3,className:"resize-y bg-background"}),s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:"Rules the AI must follow in every social post it writes for this business — single posts and batch generation."}),F.length>0&&s.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums shrink-0",children:[F.length,"/",1500]})]})]})]})]}),s.jsx(W,{profile:t,onSaved:a})]}),s.jsx("div",{id:`brand-kit-${t.id}`,className:"pt-6 border-t border-border scroll-mt-6",children:s.jsx(te,{profile:t,onSaved:a,refreshToken:Z,onKnowledgeSaved:()=>X(e=>e+1),onRefreshFromWebsite:ce,refreshing:ie||V,refreshDisabledReason:t.website.trim()?re?"Save your website changes before refreshing":void 0:"Add a website in the business details first"})}),s.jsx("div",{id:`competitors-${t.id}`,className:"pt-6 border-t border-border scroll-mt-6",children:s.jsx(oe,{companyProfileId:t.id,competitors:ee,onCompetitorsChange:se})}),s.jsx("div",{className:"pt-6 border-t border-border",children:s.jsx(le,{companyProfileId:t.id,businessName:t.name,refreshToken:J,onKnowledgeSaved:()=>Q(e=>e+1)})})]}),s.jsx(y,{open:K,onOpenChange:G,children:s.jsxs(N,{children:[s.jsxs(w,{children:[s.jsx(k,{children:"Reset business info?"}),s.jsxs(C,{children:['This resets the website, phone, and email for "',t.name||"this business",'" and removes'," ",ee?.length?`all ${ee.length} competitor${1===ee.length?"":"s"}`:"its competitors",". The business name and universal posting instructions are kept. This can't be und
1one."]})]}),s.jsxs(S,{children:[s.jsx(_,{children:"Cancel"}),s.jsx(z,{onClick:async()=>{L(!0);try{const e=await u.updateCompanyProfile(t.id,{website:"",phone:"",email:""});for(const s of ee??[])await u.deleteCompetitor(t.id,s.id);g(""),b(""),v(""),a(e),ae(),h({title:"Business info reset"})}catch(e){h({title:"Failed to reset business info",description:e instanceof Error?e.message:"Unknown error",variant:"destructive"})}finally{L(!1)}},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Reset info"})]})]})}),s.jsx(y,{open:Y,onOpenChange:H,children:s.jsxs(N,{children:[s.jsxs(w,{children:[s.jsx(k,{children:"Delete business profile?"}),s.jsx(C,{asChild:!0,children:s.jsxs("span",{children:['This permanently deletes "',t.name||"this business","\" and all of its saved info (competitors, website, phone, email). This can't be undone.",t.linked_account_count>0&&s.jsxs("span",{className:"mt-2 block font-medium text-destructive",children:[t.name||"This business"," has ",t.linked_account_count," connected account",1===t.linked_account_count?"":"s"," that will lose"," ",1===t.linked_account_count?"its":"their"," saved business info."]})]})})]}),s.jsxs(S,{children:[s.jsx(_,{children:"Cancel"}),s.jsx(z,{onClick:async()=>{D(!0);try{await u.deleteCompanyProfile(t.id),n(t.id),h({title:"Business profile deleted"})}catch(e){h({title:"Failed to delete business profile",description:e instanceof Error?e.message:"Unknown error",variant:"destructive"})}finally{D(!1)}},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete profile"})]})]})})]})}const me={hidden:{opacity:0,y:20},visible:{opacity:1,y:0,transition:{duration:.4,ease:"easeOut"}}};function ue(){return s.jsx(F,{children:s.jsx(he,{})})}function he(){const[t,a]=e.useState(null),[n,i]=e.useState(null),[r,o]=e.useState(!1),[l]=e.useState(()=>new URLSearchParams(window.location.search).get("highlight")),[d,h]=e.useState(null),x=e.useCallback(()=>{u.getCompanyProfiles().then(e=>{a(e),i(null)}).catch(e=>i(e instanceof Error?e.message:"Failed to load business profiles"))},[]);e.useEffect(()=>{x()},[x]),e.useEffect(()=>{if(!t?.length||d)return;const e=l&&t.find(e=>e.id===l)||[...t].sort((e,s)=>s.linked_account_count-e.linked_account_count)[0];h(e.id)},[t,d,l]);const p=t?.find(e=>e.id===d)??null;return s.jsxs("div",{className:"mx-auto max-w-7xl px-6 py-6",children:[s.jsxs("div",{className:"mb-8 flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Business Profiles"}),s.jsx("p",{className:"text-muted-foreground mt-1",children:"Manage the business details, brand logo, and competitors used to personalize AI-generated content for your connected accounts."})]}),s.jsxs(c,{size:"sm",onClick:()=>o(!0),className:"shrink-0",children:[s.jsx(m,{name:"Plus",className:"size-4 mr-1.5"}),"Add business profile"]})]}),n&&s.jsx("div",{className:"mb-6 rounded-lg border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive",children:n}),null===t?s.jsx("div",{className:"flex items-center justify-center py-16",children:s.jsx(m,{name:"Loader2",className:"size-6 animate-spin text-muted-foreground"})}):0===t.length?s.jsx(T,{children:s.jsxs(U,{className:"py-12 text-center",children:[s.jsx(m,{name:"Building2",className:"size-8 text-muted-foreground mx-auto mb-3"}),s.jsx("p",{className:"text-sm font-medium",children:"No business profiles yet"}),s.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Connect a social account and a business profile will be created for it automatically, or add one manually."})]})}):s.jsxs("div",{className:"space-y-4",children:[t.length>1&&s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("label",{className:"text-sm font-medium text-foreground shrink-0",children:"Business"}),s.jsxs($,{value:d??void 0,onValueChange:h,children:[s.jsx(A,{className:"w-full max-w-md",children:s.jsx(E,{placeholder:"Select a business"})}),s.jsx(B,{children:[...t].sort((e,s)=>s.linked_account_count-e.linked_account_count||e.name.localeCompare(s.name)).map(e=>s.jsxs(L,{value:e.id,children:[e.name,e.linked_account_count>0&&s.jsxs("span",{className:"ml-1.5 text-muted-foreground",children:["· ",e.linked_account_count," ",1===e.linked_account_count?"account":"accounts"]})]},e.id))})]})]}),p&&s.jsx(b.div,{initial:"hidden",animate:"visible",variants:me,children:s.jsx(ce,{profile:p,onSaved:e=>{a(s=>s?.map(s=>s.id===e.id?e:s)??s)},onDeleted:e=>{a(s=>{const t=s?.filter(s=>s.id!==e)??s;return e===d&&h(t?.[0]?.id??null),t})},highlighted:p.id===l})}
1,p.id)]}),s.jsx(D,{open:r,onOpenChange:o,onCreated:e=>{a(s=>[...s??[],e]),h(e.id),o(!1)}})]})}export{ue as component};

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.