1import{D as Fe,r as d,l as C,E as b,j as e,X as T,a as x,C as je,e as fe,v as Re,I as Ne,L as ye,G as ze,w as we,Q as k,V as p}from"./index-DorzRKSB.js";import{P as Me}from"./plus-DB-RpGXE.js";import{S as Ee}from"./search-FhDosdEl.js";import{U as Ke}from"./user-plus-CBb3f7_W.js";import{A as m,a as V}from"./archive-D5agOgLg.js";import{E as Qe}from"./external-link-Dv91CmtD.js";import{P as Le}from"./percent-LoRSnl2q.js";function Xe(){var Z,_,ee,se,ae,re,te,ie,ne,le,de,ce,oe,me,ue,xe,he,ge;const t=Fe(),[R,v]=d.useState(null),[j,D]=d.useState(50),[h,G]=d.useState(""),[i,P]=d.useState("active"),[S,A]=d.useState(null),[X,I]=d.useState(!1),[f,q]=d.useState(null),[O,W]=d.useState(!0),[H,N]=d.useState(!1),[u,z]=d.useState("new"),[r,c]=d.useState({publisherId:"",publisherName:"",email:"",password:"",companyName:"",contactName:"",phone:"",vatNumber:"",revenueSharePublisher:"50",userId:""}),[J,M]=d.useState(""),{data:F,isLoading:Ce}=C({queryKey:["admin-publishers"],queryFn:()=>k.listPublishers().then(s=>s.data)}),{data:E,isLoading:ke}=C({queryKey:["archived-publishers"],queryFn:()=>p.listArchivedPublishers({limit:200}).then(s=>s.data),enabled:i==="archived"}),{data:K}=C({queryKey:["archive-stats"],queryFn:()=>p.getArchiveStats().then(s=>s.data)}),Q=b({mutationFn:({publisherId:s,revenueShare:a})=>k.updateRevenueShare(s,a/100),onSuccess:()=>{t.invalidateQueries({queryKey:["admin-publishers"]}),v(null)}}),Y=b({mutationFn:({publisherId:s,active:a})=>k.updatePublisher(s,{active:a}),onSuccess:()=>{t.invalidateQueries({queryKey:["admin-publishers"]})}}),y=b({mutationFn:s=>p.archivePublisher(s,"Manual archive from admin"),onSuccess:()=>{t.invalidateQueries({queryKey:["admin-publishers"]}),t.invalidateQueries({queryKey:["archived-publishers"]}),t.invalidateQueries({queryKey:["archive-stats"]}),A(null)}}),g=b({mutationFn:({id:s,restoreSites:a})=>p.unarchivePublisher(s,a),onSuccess:()=>{t.invalidateQueries({queryKey:["admin-publishers"]}),t.invalidateQueries({queryKey:["archived-publishers"]}),t.invalidateQueries({queryKey:["archive-stats"]}),q(null)}}),o=b({mutationFn:s=>p.bulkArchiveInactive(s),onSuccess:s=>{s.data.dryRun||(t.invalidateQueries({queryKey:["admin-publishers"]}),t.invalidateQueries({queryKey:["archived-publishers"]}),t.invalidateQueries({queryKey:["archive-stats"]}),I(!1))}}),{data:Pe}=C({queryKey:["admin-users-no-publisher"],queryFn:()=>k.listUsers({publisherStatus:"none"}).then(s=>{var a;return((a=s.data)==null?void 0:a.users)||[]}),enabled:H&&u==="existing"}),L=b({mutationFn:s=>k.createPublisher(s),onSuccess:()=>{t.invalidateQueries({queryKey:["admin-publishers"]}),t.invalidateQueries({queryKey:["admin-users"]}),N(!1),c({publisherId:"",publisherName:"",email:"",password:"",companyName:"",contactName:"",phone:"",vatNumber:"",revenueSharePublisher:"50",userId:""}),M("")},onError:s=>{var a,n;M(((n=(a=s==null?void 0:s.response)==null?void 0:a.data)==null?void 0:n.error)||"Errore durante la creazione")}}),{data:l}=C({queryKey:["bulk-archive-preview"],queryFn:()=>p.bulkArchiveInactive(!0).then(s=>s.data),enabled:X});if(Ce)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"animate-spin h-8 w-8 border-4 border-primary border-t-transparent rounded-full"})});const Se=s=>{v(s),D(Math.round(s.revenueSharePublisher*100))},$=(F||[]).filter(s=>{var n,w,be,pe,ve;if(i==="active"&&!s.active||i==="inactive"&&s.active||i==="archived")return!1;if(!h.trim())return!0;const a=h.toLowerCase();return((n=s.publisherName)==null?void 0:n.toLowerCase().includes(a))||((w=s.publisherId)==null?void 0:w.toLowerCase().includes(a))||((pe=(be=s.user)==null?void 0:be.email)==null?void 0:pe.toLowerCase().includes(a))||((ve=s.sites)==null?void 0:ve.some(qe=>qe.domain.toLowerCase().includes(a)))}),B=((E==null?void 0:E.publishers)||[]).filter(s=>{var n,w;if(!h.trim())return!0;const a=h.toLowerCase();return((n=s.publisherName)==null?void 0:n.toLowerCase().includes(a))||((w=s.publisherId)==null?void 0:w.toLowerCase().includes(a))}),Ae=(F||[]).filter(s=>s.active).length,U=(F||[]).filter(s=>!s.active).length,Ie=(K==null?void 0:K.archivedPublishers)||0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Gestione Publisher"}),e.jsxs("p",{className:"text-muted-foreground",children:[i==="archived"?B.length:$.length," publisher"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>{N(!0),M(""),z("new")},className:"flex items-center gap-2 px-4 py-2 bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 transition-colors text-sm font-medium",children:[e.jsx(Me,{className:"h-4 w-4"}),"Nuovo Publisher"]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ee,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx("input",{type:"text",placeholder:"Cerca publisher, email, dominio...",value:h,onChange:s=>G(s.target.value),className:"pl-10 pr-4 py-2 border rounded-lg w-full sm:w-80 bg-background"}),h&&e.jsx("button",{onClick:()=>G(""),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:e.jsx(T,{className:"h-4 w-4"})})]})]})]}),H&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 z-40",onClick:()=>N(!1)}),e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-background border rounded-xl shadow-xl max-w-lg w-full max-h-[90vh] overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2",children:[e.jsx(Ke,{className:"h-5 w-5"}),"Nuovo Publisher"]}),e.jsx("button",{onClick:()=>N(!1),className:"text-muted-foreground hover:text-foreground",children:e.jsx(T,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{onClick:()=>z("new"),className:`px-3 py-1.5 rounded text-sm font-medium ${u==="new"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:"Nuovo utente"}),e.jsx("button",{onClick:()=>z("existing"),className:`px-3 py-1.5 rounded text-sm font-medium ${u==="existing"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:"Utente esistente"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Publisher ID *"}),e.jsx("input",{type:"text",value:r.publisherId,onChange:s=>c(a=>({...a,publisherId:s.target.value})),placeholder:"es. PUB001",className:"w-full px-3 py-2 border rounded-lg bg-background text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Nome Publisher *"}),e.jsx("input",{type:"text",value:r.publisherName,onChange:s=>c(a=>({...a,publisherName:s.target.value})),placeholder:"es. Acme Media Srl",className:"w-full px-3 py-2 border rounded-lg bg-background text-sm"})]})]}),u==="existing"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Seleziona utente *"}),e.jsxs("select",{value:r.userId,onChange:s=>c(a=>({...a,userId:s.target.value})),className:"w-full px-3 py-2 border rounded-lg bg-background text-sm",children:[e.jsx("option",{value:"",children:"-- Seleziona un utente senza publisher --"}),(Pe||[]).map(s=>e.jsxs("option",{value:s.id,children:[s.email," ",s.companyName?`(${s.companyName})`:""]},s.id))]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Email *"}),e.jsx("input",{type:"email",value:r.email,onChange:s=>c(a=>({...a,email:s.target.value})),placeholder:"[email protected]",className:"w-full px-3 py-2 border rounded-lg bg-background text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Password *"}),e.jsx("input",{type:"password",value:r.password,onChange:s=>c(a=>({...a,password:s.target.value})),placeholder:"Min. 8 caratteri",className:"w-full px-3 py-2 border rounded-lg bg-background text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Ragione Sociale"}),e.jsx("input",{type:"text",value:r.companyName,onChange:s=>c(a=>({...a,companyName:s.target.value})),className:"w-full px-3 py-2 border rounded-lg bg-background text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Referente"}),e.jsx("input",{type:"text",value:r.contactName,onChange:s=>c(a=>({...a,contactName:s.target.value})),className:"w-full px-3 py-2 border rounded-lg bg-background text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Telefono"}),e.jsx("input",{type:"text",value:r.phone,onChange:s=>c(a=>({...a,phone:s.target.value})),className:"w-full px-3 py-2 border rounded-lg bg-background text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"P.IVA"}),e.jsx("input",{type:"text",value:r.vatNumber,onChange:s=>c(a=>({...a,vatNumber:s.target.value})),className:"w-full px-3 py-2 border rounded-lg bg-background text-sm"})]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1",children:["Revenue Share Publisher: ",r.revenueSharePublisher,"%"]}),e.jsx("input",{type:"range",min:"0",max:"100",step:"5",value:r.revenueSharePublisher,onCh
1ange:s=>c(a=>({...a,revenueSharePublisher:s.target.value})),className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0% (tutto piattaforma)"}),e.jsx("span",{children:"100% (tutto publisher)"})]})]}),J&&e.jsx("div",{className:"p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700 dark:bg-red-900/20 dark:border-red-800 dark:text-red-400",children:J}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx("button",{onClick:()=>N(!1),className:"px-4 py-2 border rounded-lg text-sm hover:bg-accent",children:"Annulla"}),e.jsxs("button",{onClick:()=>{const s={publisherId:r.publisherId,publisherName:r.publisherName,revenueSharePublisher:parseInt(r.revenueSharePublisher)/100};u==="existing"?s.userId=r.userId:(s.email=r.email,s.password=r.password,r.companyName&&(s.companyName=r.companyName),r.contactName&&(s.contactName=r.contactName),r.phone&&(s.phone=r.phone),r.vatNumber&&(s.vatNumber=r.vatNumber)),L.mutate(s)},disabled:L.isPending||!r.publisherId||!r.publisherName||u==="new"&&(!r.email||!r.password)||u==="existing"&&!r.userId,className:"px-4 py-2 bg-primary text-primary-foreground rounded-lg text-sm hover:bg-primary/90 disabled:opacity-50 flex items-center gap-2",children:[L.isPending&&e.jsx(x,{className:"h-4 w-4 animate-spin"}),"Crea Publisher"]})]})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>P("active"),className:`px-4 py-2 rounded-lg text-sm font-medium transition-colors flex items-center gap-2 ${i==="active"?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-muted text-muted-foreground hover:bg-accent"}`,children:[e.jsx(je,{className:"h-4 w-4"}),"Attivi (",Ae,")"]}),e.jsxs("button",{onClick:()=>P("inactive"),className:`px-4 py-2 rounded-lg text-sm font-medium transition-colors flex items-center gap-2 ${i==="inactive"?"bg-gray-200 text-gray-700 dark:bg-gray-700 dark:text-gray-300":"bg-muted text-muted-foreground hover:bg-accent"}`,children:[e.jsx(fe,{className:"h-4 w-4"}),"Inattivi (",U,")"]}),e.jsxs("button",{onClick:()=>P("archived"),className:`px-4 py-2 rounded-lg text-sm font-medium transition-colors flex items-center gap-2 ${i==="archived"?"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400":"bg-muted text-muted-foreground hover:bg-accent"}`,children:[e.jsx(m,{className:"h-4 w-4"}),"Archiviati (",Ie,")"]}),e.jsxs("button",{onClick:()=>P("all"),className:`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${i==="all"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"}`,children:["Tutti (",(F||[]).length,")"]}),i==="inactive"&&U>0&&e.jsxs("button",{onClick:()=>I(!0),className:"ml-auto px-4 py-2 rounded-lg text-sm font-medium bg-orange-500 text-white hover:bg-orange-600 flex items-center gap-2",children:[e.jsx(m,{className:"h-4 w-4"}),"Archivia Tutti Inattivi (",U,")"]})]}),i==="archived"&&e.jsx("div",{className:"grid gap-4",children:ke?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(x,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):B.length===0?e.jsxs("div",{className:"bg-card border rounded-lg p-12 text-center",children:[e.jsx(m,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h2",{className:"text-lg font-semibold mb-2",children:"Nessun publisher archiviato"}),e.jsx("p",{className:"text-muted-foreground",children:"L'archivio e vuoto."})]}):B.map(s=>e.jsxs("div",{className:"bg-card border border-orange-200 rounded-lg p-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-12 w-12 bg-orange-100 rounded-lg flex items-center justify-center",children:e.jsx(m,{className:"h-6 w-6 text-orange-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:s.publisherName}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:s.publisherId}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Archiv
1iato il ",Re(s.archivedAt),s.archivedBy&&` da ${s.archivedBy}`]})]})]}),e.jsxs("button",{onClick:()=>{q(s),W(!0)},disabled:g.isPending,className:"px-3 py-2 text-sm bg-green-50 text-green-700 hover:bg-green-100 rounded-lg flex items-center gap-2",children:[e.jsx(V,{className:"h-4 w-4"}),"Ripristina"]})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{children:[s.siteCount," siti al momento dell'archiviazione"]}),s.archivedSitesCount>0&&e.jsxs("span",{className:"text-orange-600",children:[s.archivedSitesCount," siti archiviati"]}),s.archiveReason&&e.jsxs("span",{children:["Motivo: ",s.archiveReason]})]})]},s.id))}),i!=="archived"&&e.jsxs("div",{className:"grid gap-4",children:[$.map(s=>{var a;return e.jsxs("div",{className:"bg-card border rounded-lg p-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-12 w-12 bg-primary/10 rounded-lg flex items-center justify-center",children:e.jsx(Ne,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:s.publisherName}),e.jsx(ye,{to:`/admin/publishers/${s.id}`,className:"text-muted-foreground hover:text-primary",children:e.jsx(Qe,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:(a=s.user)==null?void 0:a.email}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:s.publisherId})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!s.active&&e.jsxs("button",{onClick:()=>A(s),className:"text-xs px-3 py-1 rounded-full flex items-center gap-1 text-orange-600 bg-orange-50 hover:bg-orange-100",title:"Archivia publisher e tutti i siti",children:[e.jsx(m,{className:"h-3 w-3"}),"Archivia"]}),e.jsx("button",{onClick:()=>Y.mutate({publisherId:s.id,active:!s.active}),disabled:Y.isPending,className:`text-xs px-3 py-1 rounded-full flex items-center gap-1 transition-colors ${s.active?"bg-green-50 text-green-600 hover:bg-green-100":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:s.active?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"h-3 w-3"}),"Attivo"]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"h-3 w-3"}),"Inattivo"]})})]})]}),s.sites&&s.sites.length>0&&e.jsxs("div",{className:"mt-4 pt-4 border-t",children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-2",children:["Siti (",s.sites.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.sites.map(n=>e.jsxs(ye,{to:`/admin/sites/${n.id}`,className:`text-xs px-2 py-1 rounded-full hover:opacity-80 transition-opacity ${n.status==="active"?"bg-green-50 text-green-700":"bg-gray-100 text-gray-600"}`,children:[e.jsx(ze,{className:"h-3 w-3 inline mr-1"}),n.domain]},n.id))})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Rev. Share Publisher:"})," ",e.jsxs("span",{className:"font-semibold text-green-600",children:[(s.revenueSharePublisher*100).toFixed(0),"%"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Piattaforma:"})," ",e.jsxs("span",{className:"font-medium",children:[(s.revenueSharePlatform*100).toFixed(0),"%"]})]})]}),e.jsxs("button",{onClick:()=>Se(s),className:"text-sm text-primary hover:underline flex items-center gap-1",children:[e.jsx(Le,{className:"h-4 w-4"}),"Modifica Rev. Share"]})]})]},s.id)}),$.length===0&&e.jsxs("div",{className:"bg-card border rounded-lg p-12 text-center",children:[e.jsx(Ne,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h2",{className:"text-lg font-semibold mb-2",children:"Nessun publisher"}),e.jsx("p",{className:"text-muted-foreground",children:i==="inactive"?"Nessun publisher inattivo.":"Non ci sono publisher registrati."})]})]}),R&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 z-40",onClick:()=>v(null)}),e.jsx("div",{className:"fixed inset-0 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:"bg-card border rounded-lg shadow-lg w-full max-w-md",children:e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Modifica Revenue Share"}),e.jsx("button",{onClick:()=>v(null),className:"p-2 hover:bg-accent rounded-md",children:e.jsx(T,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Publisher"}),e.jsx("p",{className:"font-medium",children:R.publisherName})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"Revenue Share Publisher"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("input",{type:"range",min:"0",max:"100",step:"1",value:j,onChange:s=>D(Number(s.target.value)),className:"flex-1"}),e.jsx("div",{className:"w-20 text-center",children:e.jsxs("span",{className:"text-2xl font-bold text-green-600",children:[j,"%"]})})]}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mt-1",children:[e.jsx("span",{children:"0%"}),e.jsx("span",{children:"100%"})]})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-4",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Riepilogo"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Publisher riceve:"}),e.jsxs("span",{className:"font-semibold text-green-600",children:[j,"%"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Piattaforma riceve:"}),e.jsxs("span",{className:"font-medium",children:[100-j,"%"]})]})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>v(null),className:"flex-1 px-4 py-2 border rounded-md hover:bg-accent",children:"Annulla"}),e.jsxs("button",{onClick:()=>Q.mutate({publisherId:R.id,revenueShare:j}),disabled:Q.isPending,className:"flex-1 px-4 py-2 bg-primary text-primary-foreground rounded-md flex items-center justify-center gap-2",children:[Q.isPending&&e.jsx(x,{className:"h-4 w-4 animate-spin"}),"Salva"]})]})]})]})})})]}),S&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 z-40",onClick:()=>A(null)}),e.jsx("div",{className:"fixed inset-0 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:"bg-card border rounded-lg shadow-lg w-full max-w-md",children:e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"h-12 w-12 bg-orange-100 rounded-full flex items-center justify-center",children:e.jsx(m,{className:"h-6 w-6 text-orange-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Archivia Publisher"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:S.publisherName})]})]}),e.jsx("div",{className:"p-4 bg-orange-50 border border-orange-200 rounded-md mb-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(we,{className:"h-5 w-5 text-orange-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-orange-800",children:[e.jsx("p",{className:"font-medium",children:"Verranno archiviati:"}),e.jsxs("ul",{className:"mt-1 list-disc list-inside",children:[e.jsx("li",{children:"Il publisher e tutte le sue configurazioni"}),e.jsxs("li",{children:[((Z=S.sites)==null?void 0:Z.length)||0," siti con tutte le relative configurazioni"]})]}),e.jsx("p",{className:"mt-2",children:"I dati saranno conservati nell'archivio e potranno essere ripristinati."})]})]})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>A(null),className:"flex-1 px-4 py-2 border rounded-md hover:bg-accent",children:"Annulla"}),e.jsxs("button",{onClick:()=>y.mutate(S.id),disabled:y.isPending,className:"flex-1 px-4 py-2 bg-orange-500 text-white rounded-md flex items-center justify-center gap-2 hover:bg-orange-600",children:[y.isPending?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsx(m,{className:"h-4 w-4"}
1),"Archivia"]})]}),y.isError&&e.jsx("div",{className:"mt-3 p-3 bg-red-50 border border-red-200 rounded-md text-sm text-red-700",children:String(((se=(ee=(_=y.error)==null?void 0:_.response)==null?void 0:ee.data)==null?void 0:se.error)||"Errore durante l'archiviazione")})]})})})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 z-40",onClick:()=>q(null)}),e.jsx("div",{className:"fixed inset-0 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:"bg-card border rounded-lg shadow-lg w-full max-w-md",children:e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"h-12 w-12 bg-green-100 rounded-full flex items-center justify-center",children:e.jsx(V,{className:"h-6 w-6 text-green-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Ripristina Publisher"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:f.publisherName})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"p-4 bg-blue-50 border border-blue-200 rounded-md text-sm text-blue-800",children:e.jsxs("p",{children:["Il publisher sara ripristinato con stato ",e.jsx("strong",{children:"inattivo"}),". Dovrai attivarlo manualmente."]})}),f.archivedSitesCount>0&&e.jsxs("label",{className:"flex items-center gap-3 p-3 border rounded-md cursor-pointer hover:bg-accent",children:[e.jsx("input",{type:"checkbox",checked:O,onChange:s=>W(s.target.checked),className:"rounded"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",children:["Ripristina anche i siti (",f.archivedSitesCount,")"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'I siti saranno ripristinati con stato "sospeso"'})]})]})]}),e.jsxs("div",{className:"flex gap-3 mt-4",children:[e.jsx("button",{onClick:()=>q(null),className:"flex-1 px-4 py-2 border rounded-md hover:bg-accent",children:"Annulla"}),e.jsxs("button",{onClick:()=>g.mutate({id:f.id,restoreSites:O}),disabled:g.isPending,className:"flex-1 px-4 py-2 bg-green-600 text-white rounded-md flex items-center justify-center gap-2 hover:bg-green-700",children:[g.isPending?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsx(V,{className:"h-4 w-4"}),"Ripristina"]})]}),g.isError&&e.jsx("div",{className:"mt-3 p-3 bg-red-50 border border-red-200 rounded-md text-sm text-red-700",children:String(((te=(re=(ae=g.error)==null?void 0:ae.response)==null?void 0:re.data)==null?void 0:te.error)||"Errore durante il ripristino")})]})})})]}),X&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 z-40",onClick:()=>I(!1)}),e.jsx("div",{className:"fixed inset-0 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:"bg-card border rounded-lg shadow-lg w-full max-w-lg",children:e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"h-12 w-12 bg-orange-100 rounded-full flex items-center justify-center",children:e.jsx(m,{className:"h-6 w-6 text-orange-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Archivia Tutti i Publisher Inattivi"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l?`${l.total} publisher da archiviare`:"Caricamento anteprima..."})]})]}),l?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-4 bg-orange-50 border border-orange-200 rounded-md mb-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(we,{className:"h-5 w-5 text-orange-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-orange-800",children:[e.jsxs("p",{className:"font-medium",children:["Verranno archiviati ",l.total," publisher:"]}),e.jsxs("p",{className:"mt-1",children:["Totale siti coinvolti: ",l.archivedPublishers.reduce((s,a)=>s+a.sitesArchived,0)]}),e.jsx("p",{className:"mt-2",children:"Ogni publisher viene archiviato in una transazione separata. In caso di errore su uno, gli altri non saranno compromessi."})]})]})}),e.jsxs("div",{className:"max-h-48 overflow-y-auto mb-4 text-sm",children:[l.archivedPublishers.slice(0,10).map(s=>e.jsxs("div",{className:"flex items-center justify-between py-1 border-b last:border-0",children:[e.jsx("span",{children:s.publisherName}),e.jsxs("span",{className:"text-muted-foreground",children:[s.sitesArchived," siti"]})]},s.id)),l.archivedPublishers.length>10&&e.jsxs("p",{className:"text-muted-foreground text-center py-2",children:["...e altri ",l.archivedPublishers.length-10]})]})]}):e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(x,{className:"h-6 w-6 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>I(!1),className:"flex-1 px-4 py-2 border rounded-md hover:bg-accent",children:"Annulla"}),e.jsxs("button",{onClick:()=>o.mutate(!1),disabled:o.isPending||!l,className:"flex-1 px-4 py-2 bg-orange-500 text-white rounded-md flex items-center justify-center gap-2 hover:bg-orange-600 disabled:opacity-50",children:[o.isPending?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsx(m,{className:"h-4 w-4"}
1),"Archivia ",(l==null?void 0:l.total)||0," Publisher"]})]}),o.isSuccess&&!((ne=(ie=o.data)==null?void 0:ie.data)!=null&&ne.dryRun)&&e.jsxs("div",{className:"mt-3 p-3 bg-green-50 border border-green-200 rounded-md text-sm text-green-700",children:["Archiviati ",(de=(le=o.data)==null?void 0:le.data)==null?void 0:de.archived," publisher.",(((oe=(ce=o.data)==null?void 0:ce.data)==null?void 0:oe.failed)||0)>0&&e.jsxs("span",{className:"text-red-600 ml-2",children:[(ue=(me=o.data)==null?void 0:me.data)==null?void 0:ue.failed," falliti."]})]}),o.isError&&e.jsx("div",{className:"mt-3 p-3 bg-red-50 border border-red-200 rounded-md text-sm text-red-700",children:String(((ge=(he=(xe=o.error)==null?void 0:xe.response)==null?void 0:he.data)==null?void 0:ge.error)||"Errore durante l'archiviazione bulk")})]})})})]})]})}export{Xe as AdminPublishersPage};
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.