1import{r as x,j as e,a as w}from"./app-COgPBknL.js";import{A as R}from"./AuthenticatedLayout-BvAT1w6L.js";import{P as p}from"./Panel-CCND_Ao-.js";import{f as M}from"./functions-Cl0IUnBH.js";import{g as S,t as A}from"./managementRequests-_zfHfnM7.js";import"./Dropdown-CvI5P8_q.js";import"./transition--Yi9rC3o.js";import"./BlockingLoader-CVmxx5HX.js";import"./Loader-C5QQKbTn.js";import"./LinkButton-qOO-XiqT.js";import"./Alert-C-AfV-eG.js";const C=2e3;function i({icon:m,label:g,value:h,subValue:n,color:t="indigo"}){const o={indigo:"from-indigo-500 to-indigo-600",green:"from-green-500 to-emerald-600",orange:"from-orange-400 to-orange-500",red:"from-red-500 to-rose-600",gray:"from-gray-400 to-gray-500"};return e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm hover:shadow-md transition-all",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-lg bg-gradient-to-br ${o[t]} flex items-center justify-center text-white`,children:e.jsx("i",{className:`fas fa-${m}`})}),e.jsx("p",{className:"text-gray-500 text-sm",children:g})]}),e.jsx("p",{className:"text-3xl font-bold text-gray-800",children:h}),n&&e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:n})]})}const G={approved:"bg-green-100 text-green-700",pending:"bg-yellow-100 text-yellow-700",disapproved:"bg-red-100 text-red-700"};function q({auth:m,tabs:g,current_tab:h,config:n,counts:t,last_synced_at:o,recent_failures:y=[],review_counts:r={approved:0,pending:0,disapproved:0},listed_products:j=[],orphans:b=[]}){const[u,_]=x.useState(null),[a,d]=x.useState(null),c=x.useRef(null),v=a?.status==="running";function N(){c.current&&(clearInterval(c.current),c.current=null)}function f(){c.current||(c.current=setInterval(()=>{S().then(s=>{d(s),s.status!=="running"&&(N(),w.reload({only:["counts","last_synced_at","recent_failures","review_counts","listed_products","orphans"]}))})},C))}x.useEffect(()=>(S().then(s=>{d(s),s.status==="running"&&f()}),N),[]);function k(){A().then(s=>{d(s),s.status==="running"?f():w.reload({only:["counts","last_synced_at","recent_failures","review_counts","listed_products","orphans"]})}).catch(s=>{s?.status==="running"?(d(s),f()):d({status:"failed",error:s?.error||"Failed to start sync."})})}return e.jsx(R,{user:m.user,header:"Google Shopping",tabs:g,current_tab:h,isAdmin:!0,children:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-gradient-to-r from-indigo-600 to-purple-600 rounded-2xl p-6 text-white shadow-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-14 h-14 bg-white/20 backdrop-blur rounded-xl flex items-center justify-center",children:e.jsx("i",{className:"fas fa-basket-shopping text-2xl"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Google Shopping"}),e.jsx("p",{className:"text-indigo-100 text-sm mt-1",children:"Merchant Center listing sync and health"})]})]}),e.jsx("button",{type:"button",disabled:v||!n.configured,onClick:k,className:"flex items-center gap-2 px-4 py-2 bg-white/20 hover:bg-white/30 rounded-lg transition-colors text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:v?e.jsxs(e.Fragment,{children:[e.jsx("i",{className:"fas fa-spinner fa-spin"})," Syncingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx("i",{className:"fas fa-rotate"})," Sync Now"]})})]})}),!n.configured&&e.jsx("div",{className:"text-sm text-red-600 bg-red-50 rounded-xl p-4",children:"Google Merchant isn't configured â check the service account credentials file and GOOGLE_MERCHANT_ID / GOOGLE_DATA_SOURCE_ID."}),a?.status==="failed"&&e.jsx("div",{className:"text-sm text-red-600 bg-red-50 rounded-xl p-4",children:a.error||"Sync failed. Check the logs for details."}),a?.status==="completed"&&e.jsxs("div",{className:"text-sm text-green-700 bg-green-50 rounded-xl p-4",children:["Last run synced ",a.synced," product(s)",a.failed>0&&e.jsxs("span",{className:"text-red-600",children:[" â ",a.failed," failed"]}),a.ineligible>0&&`, ${a.ineligible} ineligible`,"."]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(i,{icon:"circle-check",label:"Synced",value:t.synced,subValue:o?`Last push ${M(o,"
1ymd")}`:"Never synced",color:"green"}),e.jsx(i,{icon:"clock",label:"Pending",value:t.pending,subValue:"Waiting for next sync run",color:t.pending>0?"indigo":"gray"}),e.jsx(i,{icon:"triangle-exclamation",label:"Failed",value:t.failed,subValue:"Rejected by Google â retried each run",color:t.failed>0?"red":"green"}),e.jsx(i,{icon:"ban",label:"Ineligible",value:t.ineligible,subValue:"Missing image, shipping, or inactive",color:t.ineligible>0?"orange":"gray"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(i,{icon:"thumbs-up",label:"Approved on Google",value:r.approved,subValue:"Live on Google Shopping",color:"green"}),e.jsx(i,{icon:"hourglass-half",label:"Under Review",value:r.pending,subValue:"Google is still evaluating",color:r.pending>0?"indigo":"gray"}),e.jsx(i,{icon:"thumbs-down",label:"Disapproved",value:r.disapproved,subValue:"Rejected by Google review â see below",color:r.disapproved>0?"red":"green"})]}),e.jsxs(p,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-800",children:"Listed on Google"}),e.jsx("span",{className:"text-xs text-gray-400",children:"Review verdicts refresh on every sync"})]}),j.length?e.jsx("div",{className:"divide-y divide-gray-100",children:j.map(s=>e.jsxs("div",{className:"py-2.5",children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${s.issues.length?"cursor-pointer":""}`,onClick:()=>s.issues.length&&_(u===s.id?null:s.id),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm text-gray-800 font-medium truncate",children:s.name}),e.jsx("p",{className:"text-xs text-gray-400",children:s.store??"â"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.issues.length>0&&e.jsxs("span",{className:"text-xs text-gray-400",children:[s.issues.length," issue",s.issues.length!==1?"s":"",e.jsx("i",{className:`fas fa-chevron-${u===s.id?"up":"down"} ml-1`})]}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${G[s.review_status]??"bg-gray-100 text-gray-600"}`,children:s.review_status})]})]}),u===s.id&&e.jsx("ul",{className:"mt-2 ml-1 space-y-2",children:s.issues.map((l,E)=>e.jsxs("li",{className:"text-xs bg-red-50 rounded-lg p-2.5",children:[e.jsxs("p",{className:"text-red-700 font-medium",children:[l.description,l.attribute&&e.jsxs("span",{className:"text-red-400",children:[" ","(",l.attribute,")"]})]}),l.detail&&e.jsx("p",{className:"text-red-600 mt-0.5",children:l.detail}),l.resolution&&e.jsxs("p",{className:"text-gray-500 mt-0.5",children:["Fix: ",l.resolution]})]},E))})]},s.id))}):e.jsxs("div",{className:"flex flex-col text-gray-500 justify-center items-center h-32",children:[e.jsx("i",{className:"fas fa-info-circle text-gray-200 text-2xl mb-2"}),e.jsx("div",{className:"text-sm",children:"Nothing read back from Google yet â run a sync"})]})]}),b.length>0&&e.jsxs(p,{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-800 mb-1",children:"On Google, but not from this app"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"These offers exist in the Merchant Center account but don't match any local product â likely added manually via the Google console or by an older integration. The sync never touches them; remove them in Merchant Center directly if they're stale."}),e.jsx("div",{className:"divide-y divide-gray-100",children:b.map(s=>e.jsxs("div",{className:"py-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm text-gray-800 font-medium truncate",children:s.title||"(no title)"}),e.jsx("p",{className:"text-xs text-gray-400 break-all",children:s.offer_id})]}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium shrink-0 ${G[s.review]??"bg-gray-100 text-gray-600"}`,children:s.review})]},s.offer_id))})]}),e.jsxs(p,{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-800 mb-4",children:"Recent Failures"}),y.length?e.jsx("div",{className:"divide-y divide-gray-100",children:y.map(s=>e.jsxs("div",{className:"py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-gray-800 font-medium",children:s.name}),e.jsx("p",{className:"text-xs text-gray-400",children:s.store?.name??"â"})]}),e.jsx("p",{className:"text-xs text-red-600 mt-1 break-all",children:s.google_sync_error})]},s.id))}):e.jsxs("div",{className:"flex flex-col text-gray-500 justify-center items-center h-32",children:[e.jsx("i",{className:"fas fa-circle-check text-green-200 text-2xl mb-2"}),e.jsx("div",{className:"text-sm",children:"No sync failures"})]})]})]})})}export{q 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.