1import{j as e}from"./vendor-radix-D95_QOwI.js";import{u as je,r as n}from"./vendor-react-D8kazXLH.js";import{u as pe,f as Ne,g as _e,i as ve,K as we,M as K,L as k,F as W,l as p,T as X,B as N,S as C,C as h,a2 as se,e as F,b as J,d as Q,k as U,a1 as be,q as te,a as ae,D as ye,w as Se,x as ke,y as Ce,z as De,a3 as Ie,j as ze,E as Ae,s as y,m as o}from"./index-C8HR-Dmp.js";import{S as Te,a as Fe,b as Le,c as Pe,d as L}from"./select-DcSgkidw.js";import{F as Be}from"./FeatureInfo-CXjSK3B8.js";import{t as Y}from"./activityTracker-Bpk60PNy.js";import{R as Z}from"./refresh-cw-DrSLLTZA.js";import{L as Ee}from"./lightbulb-DHVhpWvL.js";import{I as ee}from"./image-Zb_d4N0p.js";import{I as Re}from"./info-BXz5S6FJ.js";import{F as Me}from"./file-text-BHuf7mbe.js";import"./vendor-shopify-BAYZQhWM.js";import"./vendor-data-DTxAkKxM.js";import"./vendor-charts-Bku11YKm.js";import"./chevron-up-BCDUseZd.js";const Oe=(t,l)=>{const r=[];return t.has_meta_description||r.push(l("audit.issues.missing_meta")),t.has_alt_text||r.push(l("audit.issues.missing_alt")),t.has_schema_markup||r.push(l("audit.issues.missing_schema")),r},D=({icon:t,label:l,status:r,t:m})=>{let x="bg-secondary text-secondary-foreground",g=m("audit.detail.ok"),f=e.jsx(te,{className:"h-4 w-4 text-green-600"});return(r==="missing"||r==="short"||r==="generic"||r==="long")&&(x="bg-destructive/10 text-destructive border border-destructive/20",g=m(r==="missing"?"audit.detail.missing":r==="short"?"audit.detail.short":r==="long"?"audit.detail.long":"audit.detail.generic"),f=e.jsx(se,{className:"h-4 w-4 text-destructive"})),e.jsxs("div",{className:ae("flex items-center justify-between p-3 rounded-lg bg-secondary/30",x),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t,e.jsx("span",{className:"text-sm font-medium",children:l})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[f,e.jsx("span",{className:"text-xs font-semibold",children:g})]})]})},ts=()=>{const{t}=pe(),{user:l}=Ne(),{balance:r}=_e(),m=je(),x=ve(),{shopDomain:g}=we(),f=r<.025,[ie,w]=n.useState(!0),[I,P]=n.useState(!1),[B,E]=n.useState(0),[R,M]=n.useState(!1),[j,re]=n.useState(null),[_,O]=n.useState(null),[v,q]=n.useState([]),[ne,le]=n.useState(0),[b,ce]=n.useState("score_desc"),[S,z]=n.useState(null),[u,oe]=n.useState(null),G=s=>{let a=100;const i={title_status:"ok",desc_status:"ok",image_status:"ok",schema_status:s.has_schema_markup||!1},c=(s.title||"").length;s.title?c<20?(i.title_status="short",a-=15):c>70&&(i.title_status="long",a-=10):(i.title_status="short",a-=50);const d=(s.description||"").length;return s.description?d<50&&(i.desc_status="short",a-=20):(i.desc_status="missing",a-=40),!s.image_url||s.image_url.includes("no-image")?(i.image_status="missing",a-=30):s.image_url.includes("cdn.shopify.com")&&s.image_url.includes("/products/")&&(i.image_status="generic",a-=10),s.has_schema_markup||(a-=15),{score:Math.max(0,a),breakdown:i}},V=s=>{let a=0,i=0;const c=s.map(T=>{const{score:H,breakdown:fe}=G(T);return a+=H,i+=T.geo_score||0,{...T,content_score:H,score_breakdown:fe}}),d=s.length>0?Math.round((a+i)/(s.length*2)):0;return q(c),le(d),{enrichedProducts:c,overall:d}},A=async()=>{if(!x&&!l){w(!1);return}try{if(x&&g){const{data:s,error:a}=await y.functions.invoke("shopify-dashboard",{body:{shop_domain:g,limit:100}});if(a){console.error("[Audit] Dashboard error:",a),w(!1);return}s?.found&&s.products&&(O(s.store?.id||null),V(s.products)),w(!1);return}if(l){const{data:s}=await y.from("stores").select("id").eq("user_id",l.id).eq("is_active",!0).maybeSingle();if(!s){q([]),w(!1);return}O(s.id);const{data:a}=await y.from("products").select("id, title, handle, description, image_url, geo_score, geo_status, has_meta_description, has_alt_text, has_schema_markup").eq("store_id",s.id).order("synced_at",{ascending:!1}).limit(50);V(a||[])}}catch(s){console.error("Error:",s),o.error(t("common.error"))}finally{w(!1)}};n.useEffect(()=>{x&&!g||A()},[l,x,g]);const de=s=>{ce(s)},me=n.useMemo(()=>{const s=[...v];return s.sort((a,i)=>{const c=a.content_score||0,d=i.content_score||0;return b==="score_desc"?c-d:b==="score_asc"?d-c:b==="name_asc"?a.title.localeCompare(i.title):0}),s},[v,b]),xe=s=>{z(s);const a=s.score_breakdown,{score:i}=G(s);oe({content_score:i,geo_score:s.geo_score||0,overall_score:Math.round((i+(s.geo_score||0))/2),breakdown:a})},$=async s=>{if(f){o.error(t("wallet.insufficient"),{description:t("wallet.add_funds")});return}try{await y.functions.invoke("optimize-geo",{body:{product_id:s.id,user_id:l?.id,store_id:_}}),Y("product_optimized_from_audit","optimization",{entityType:"product",entityId:s.id}),o.success(`${t("audit.toast.optimized")}: ${s.title}`),await A()}catch(a){console.error("Optimization error:",a),o.error(t("audit.toast.error"))}},ue=async()=>
1{if(!_&&!x){o.info(t("empty.configure")),m("/settings");return}P(!0),E(0);const s=setInterval(()=>{E(a=>a>=100?(clearInterval(s),100):a+5)},100);setTimeout(async()=>{await A(),P(!1),o.success(t("audit.toast.scan_success"))},2e3)},he=async()=>{if(f){o.error(t("wallet.insufficient"),{description:t("wallet.add_funds")});return}if(!_){o.error(t("audit.empty.title"));return}M(!0);try{const{data:s,error:a}=await y.functions.invoke("smart-audit",{body:{store_id:_,industry:"e-commerce"}});if(a)throw a;Y("smart_audit_run","geo",{entityType:"store",entityId:_}),re(s.analysis),o.success(t("audit.toast.smart_audit_success"))}catch(s){console.error("Smart audit error:",s),o.error(t("audit.toast.smart_audit_error"))}finally{M(!1)}},ge=s=>s<60?e.jsx(p,{variant:"critical",children:t("audit.status.critical")}):s<90?e.jsx(p,{variant:"warning",children:t("audit.status.needs_work")}):e.jsx(p,{variant:"optimized",children:t("audit.status.excellent")});return ie?e.jsx(K,{children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(k,{className:"h-8 w-8 animate-spin text-primary"})})}):e.jsxs(K,{children:[e.jsxs("div",{className:"mb-8 flex flex-col items-center text-center gap-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold tracking-tight flex items-center justify-center gap-2",children:[e.jsx(W,{className:"text-geo-emerald"}),t("audit.title"),e.jsx(Be,{featureKey:"audit"})]}),e.jsx("p",{className:"text-muted-foreground",children:t("audit.subtitle")})]}),e.jsxs("div",{className:"w-full flex flex-col items-center gap-2",children:[f&&e.jsxs(p,{variant:"destructive",className:"animate-pulse",children:[e.jsx(X,{className:"mr-1 h-3 w-3"}),t("wallet.low_balance")]}),e.jsxs(N,{variant:"default",size:"lg",onClick:he,disabled:R||f||!_,className:"w-full max-w-[300px] shadow-md",children:[R?e.jsx(k,{className:"mr-2 h-5 w-5 animate-spin"}):e.jsx(C,{className:"mr-2 h-5 w-5"}),t("audit.buttons.smart_audit")]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2 w-full",children:[e.jsxs(N,{variant:"outline",onClick:ue,disabled:I,children:[I?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Z,{className:"mr-2 h-4 w-4"}),t("audit.buttons.scan")]}),e.jsx("div",{className:"w-[140px] md:w-[160px]",children:e.jsxs(Te,{value:b,onValueChange:de,children:[e.jsx(Fe,{className:"w-full",children:e.jsx(Le,{})}),e.jsxs(Pe,{children:[e.jsx(L,{value:"score_desc",children:t("audit.sort.score_desc")}),e.jsx(L,{value:"score_asc",children:t("audit.sort.score_asc")}),e.jsx(L,{value:"name_asc",children:t("audit.sort.name_asc")})]})]})})]})]}),v.length===0?e.jsxs(h,{variant:"glass",className:"p-12 text-center animate-fade-in-up",children:[e.jsx(se,{className:"h-16 w-16 mx-auto mb-4 text-muted-foreground"}),e.jsx("h2",{className:"text-2xl font-bold mb-2",children:t("audit.empty.title")}),e.jsx("p",{className:"text-muted-foreground mb-6 max-w-md mx-auto",children:t("audit.empty.desc")}),e.jsxs(N,{variant:"geo",onClick:()=>m("/settings"),size:"lg",children:[e.jsx(Z,{className:"mr-2 h-5 w-5"}),t("audit.empty.sync_button")]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-4 mb-6",children:[e.jsxs(h,{variant:"glow",className:"p-6 animate-fade-in-up",children:[e.jsx("div",{className:"text-4xl font-bold text-center",children:ne}),e.jsx("div",{className:"text-center text-sm text-muted-foreground",children:t("audit.stats.global_score")})]}),e.jsxs(h,{variant:"glass",className:"p-6 animate-fade-in-up animation-delay-100",children:[e.jsx("div",{className:"text-center text-destructive font-bold",children:v.filter(s=>(s.content_score||0)<60).length}),e.jsx("div",{className:"text-center text-xs text-destructive",children:t("audit.stats.critical")})]}),e.jsxs(h,{variant:"glass",className:"p-6 animate-fade-in-up animation-delay-200",children:[e.jsx("div",{className:"text-center text-warning font-bold",children:v.filter(s=>(s.content_score||0)>=60&&(s.content_score||0)<90).length}),e.jsx("div",{className:"text-center text-xs text-warning",children:t("audit.stats.weak")})]}),e.jsxs(h,{variant:"glass",className:"p-6 animate-fade-in-up animation-delay-300",children:[e.jsx("div",{className:"text-center text-geo-emerald font-bold",children:v.filter(s=>(s.content_score||0)>=90).length}),e.jsx("div",{className:"text-center text-xs text-geo-emerald",children:t("audit.stats.excellent")})]})]}),I&&e.jsx(h,{variant:"glass",className:"mb-6 animate-fade-in-up",children:e.jsx(F,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("h3",{className:"font-semibold text-sm",children:t("audit.scan.analyzing")}),e.jsx("div",{className:"w-full bg-secondary/20 h-2 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-geo-gradient transition-all duration-300",style:{width:`${B}%`}})}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:t("audit.scan.metadata")}),e.jsxs("span",{children:[B,"%"]})]})]}),e.jsx(k,{className:"h-8 w-8 animate-spin text-primary shrink-0"})]})})}),j&&e.jsxs(h,{variant:"glass",className:"mb-6 animate-fade-in-up",children:[e.jsxs(J,{children:[e.jsxs(Q,{className:"flex items-center gap-2",children:[e.jsx(C,{className:"h-5 w-5 text-geo-purple"}),t("audit.smart.title")]}),e.jsx(U,{children:t("audit.smart.subtitle")})]}),e.jsxs(F,{className:"space-y-6",children:[j.missing_keywords?.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(be,{className:"h-4 w-4 text-geo-amber"}),t("audit.smart.missing_keywords")]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:j.missing_keywords.map((s,a)=>e.jsx(p,{variant:"warning",className:"text-xs",children:s},a))})]}),j.content_gaps?.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4 text-destructive"}),t("audit.smart.content_gaps")]}),e.jsx("ul",{className:"space-y-1 text-sm text-muted-foreground",children:j.content_gaps.map((s,a)=>e.jsxs("li",{children:["⢠",s]},a))})]}),j.recommendations?.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(Ee,{className:"h-4 w-4 text-geo-emerald"}),t("audit.smart.recommendations")]}),e.jsx("ul",{className:"space-y-1 text-sm text-muted-foreground",children:j.recommendations.map((s,a)=>e.jsxs("li",{children:["⢠",s]},a))})]})]})]}),e.jsxs(h,{variant:"glass",className:"animate-fade-in-up animation-delay-400",children:[e.jsxs(J,{children:[e.jsx(Q,{children:t("audit.products.title")}),e.jsx(U,{children:t("audit.products.subtitle")})]}),e.jsx(F,{children:e.jsx("div",{className:"space-y-3",children:me.map(s=>{const a=s.content_score||0,i=Oe(s,t);return e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between p-4 rounded-lg bg-secondary/30 hover:bg-secondary/50 transition-colors gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"h-12 w-12 rounded-lg bg-secondary flex items-center justify-center overflow-hidden shrink-0",children:s.image_url?e.jsx("img",{src:s.image_url,alt:s.title,className:"h-full w-full object-cover"}):e.jsx(ee,{className:"h-6 w-6 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm truncate",children:s.title}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:i.length>0?i.slice(0,2).map((c,d)=>e.jsx(p,{variant:"critical",className:"text-[10px]",children:c},d)):e.jsxs(p,{variant:"optimized",className:"text-[10px]",children:[e.jsx(te,{className:"h-3 w-3 mr-1"}),t("audit.status.excellent")]})})]})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:ae("font-mono font-bold text-lg",a>=90?"text-geo-emerald":a>=60?"text-geo-amber":"text-geo-rose"),children:a}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"/100"})]}),ge(a),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(N,{variant:"outline",size:"sm",onClick:()=>xe(s),children:e.jsx(Re,{className:"h-4 w-4"})}),e.jsx(N,{variant:"geo",size:"sm",onClick:()=>$(s),children:e.jsx(C,{className:"h-4 w-4"})})]})]})]},s.id)})})})]})]}),e.jsx(ye,{open:!!S,onOpenChange:()=>z(null),children:e.jsxs(Se,{className:"max-w-lg",children:[e.jsxs(ke,{children:[e.jsxs(Ce,{className:"flex items-center gap-2",children:[e.jsx(W,{className:"h-5 w-5 text-primary"}),t("audit.detail.title")]}),e.jsx(De,{children:S?.title})]}),u&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"text-center p-3 rounded-lg bg-secondary/50",children:[e.jsx("div",{className:"text-2xl font-bold",children:u.content_score}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Content"})]}),e.jsxs("div",{className:"text-center p-3 rounded-lg bg-secondary/50",children:[e.jsx("div",{className:"text-2xl font-bold",children:u.geo_score}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"GEO"})]}),e.jsxs("div",{className:"text-center p-3 rounded-lg bg-primary/20",children:[e.jsx("div",{className:"text-2xl font-bold text-primary",children:u.overall_score}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Overall"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:t("audit.detail.breakdown")}),e.jsx(D,{icon:e.jsx(Me,{className:"h-4 w-4"}),label:t("audit.detail.title_field"),status:u.breakdown?.title_status||"ok",t}),e.jsx(D,{icon:e.jsx(Ie,{className:"h-4 w-4"}),label:t("audit.detail.description"),status:u.breakdown?.desc_status||"ok",t}),e.jsx(D,{icon:e.jsx(ee,{className:"h-4 w-4"}),label:t("audit.detail.image"),status:u.breakdown?.image_status||"ok",t}),e.jsx(D,{icon:e.jsx(ze,{className:"h-4 w-4"}),label:t("audit.detail.schema"),status:u.breakdown?.schema_status?"ok":"missing",t})]})]}),e.jsxs(Ae,{children:[e.jsx(N,{variant:"outline",onClick:()=>z(null),children:t("common.close")}),e.jsxs(N,{variant:"geo",onClick:()=>S&&$(S),children:[e.jsx(C,{className:"mr-2 h-4 w-4"}),t("audit.actions.optimize")]})]})]})})]})};export{ts 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.