PageSourceSearch

https://www.assipro.it/assets/PolicyArchive-B-hLpzU8.js

js assipro.it collected 2026-10-09 22:01:08 UTC 39,553 bytes, 16 lines download raw bytes

1import{c as fe,x as Lt,u as Vt,r as i,j as e,H as Ft,t as Xe,K as z,B as m,U as et,V as tt,J as Rt,w as Ot,v as Mt,L as C,s as g}from"./index-CICw11vd.js";import{S as qt,a as Bt,b as Ut,c as Kt,d as Ht}from"./select-w4vmvI4y.js";import{d as Qt,a as Wt}from"./warrantyPdfDownload-BHuoYwfK.js";import{D as re,a as se,b as le,c as ie,d as ce,e as me}from"./dialog-CE6GwOR7.js";import{S as Gt}from"./scroll-area-D6gjEyk5.js";import{B as Zt}from"./badge-1WNqt-Es.js";import{u as Jt}from"./useSignedUrl-OuR4KZRJ.js";import{f as at}from"./priceCalculator-DFXcYo_f.js";import{g as E}from"./edgeFunctionError-jeGwGXO9.js";import{b as Yt,D as Xt}from"./DataPagination-CAykY_mh.js";import{u as ea}from"./usePaginatedQuery-BX0y8rSM.js";import{u as ta}from"./useDebouncedValue-DPZBhSoU.js";import{F as aa}from"./filter-D9GF51kM.js";import{A as ra}from"./arrow-up-down-CQHt8ZNq.js";import{S as rt}from"./search-BgkZWp6j.js";import{T as st}from"./truck-DKP8TFon.js";import{C as sa}from"./calendar-D3TjxJun.js";import{T as xe}from"./trash-2-BKVaupAe.js";import{P as be}from"./pencil-BdQrQhzc.js";import{T as la}from"./triangle-alert-onpyktyk.js";import"./index-BdQq_4o_.js";import"./Combination-DA-2_4ls.js";import"./index-BhhNPFZJ.js";/**
2 * @license lucide-react v0.469.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const he=fe("ArrowRightLeft",[["path",{d:"m16 3 4 4-4 4",key:"1x1c3m"}],["path",{d:"M20 7H4",key:"zbl0bi"}],["path",{d:"m8 21-4-4 4-4",key:"h9nckh"}],["path",{d:"M4 17h16",key:"g4d7ey"}]]);/**
7 * @license lucide-react v0.469.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const ia=fe("CreditCard",[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}]]);/**
12 * @license lucide-react v0.469.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const na=fe("Split",[["path",{d:"M16 3h5v5",key:"1806ms"}],["path",{d:"M8 3H3v5",key:"15dfkv"}],["path",{d:"M12 22v-8.3a4 4 0 0 0-1.172-2.872L3 3",key:"1qrqzj"}],["path",{d:"m15 9 6-6",key:"ko1vev"}]]),oa={active:{label:"Attiva",className:"bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-200 dark:border-emerald-500/30"},approved:{label:"Approvata",className:"bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-200 dark:border-emerald-500/30"},claimed:{label:"Con sinistro",className:"bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-500/30"},pending:{label:"In attesa",className:"bg-amber-50 dark:bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-200 dark:border-amber-500/30"},in_review:{label:"In revisione",className:"bg-amber-50 dark:bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-200 dark:border-amber-500/30"},expired:{label:"Scaduta",className:"bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-300 border-slate-200 dark:border-slate-700"},rejected:{label:"Rifiutata",className:"bg-red-50 dark:bg-red-500/10 text-red-700 dark:text-red-300 border-red-200 dark:border-red-500/30"},cancelled:{label:"Annullata",className:"bg-red-50 dark:bg-red-500/10 text-red-700 dark:text-red-300 border-red-200 dark:border-red-500/30"}},lt=["rejected","cancelled"],it="id, warranty_number, status, created_at, customer_id, vehicle_id, dealer_id, tire_brand, tire_size, warranty_duration_months, tire_configuration, rear_tire_brand, rear_tire_size, km_montaggio, km_percorsi_annui, rim_size, dot_photo_url, size_photo_url, receipt_photo_url, tire_photos, warranty_type, price_paid, plan, customers(first_name, last_name, email, phone_number), vehicles(license_plate, brand, model, deleted_at), tire_dealers:dealer_id(business_name, city)",nt="id, reference_number, status, created_at, customer_id, dealer_id, vehicle_id, license_plate, battery_brand, warranty_duration_years, plan, price_paid, receipt_url, customers(first_name, last_name, email, phone_number), vehicles(brand, model, deleted_at), tire_dealers:dealer_id(business_name, city)",ue=I=>(I||[]).map(x=>({...x,_type:"tire",_duration_months:x.warranty_duration_months||12})),pe=[{value:"created_at_desc",label:"Più recenti",column:"created_at",ascending:!1},{value:"created_at_asc",label:"Meno recenti",column:"created_at",ascending:!0},{value:"price_paid_desc",label:"Prezzo più alto",column:"price_paid",ascending:!1},{value:"price_paid_asc",label:"Prezzo più basso",column:"price_paid",ascending:!0},{value:"customer_name_asc",label:"Cliente (A-Z)",column:"customers(last_name)",ascending:!0},{value:"customer_name_desc",label:"Cliente (Z-A)",column:"customers(last_name)",ascending:!1}],ge=I=>(I||[]).map(x=>{var c,$,B;return{...x,_type:"battery",warranty_number:x.reference_number,warranty_type:"battery",_duration_months:(x.warranty_duration_years||2)*12,vehicles:{license_plate:x.license_plate,brand:((c=x.vehicles)==null?void 0:c.brand)||"",model:(($=x.vehicles)==null?void 0:$.model)||"",deleted_at:((B=x.vehicles)==null?void 0:B.deleted_at)||null}}}),Ea=()=>{var qe,Be,Ue,Ke,He,Qe,We,Ge,Ze;const[I]=Lt(),x=I.get("search")||"",{toast:c}=Vt(),[$,B]=i.useState(x),U=ta($),[D,ot]=i.useState(!1),[j,dt]=i.useState("ALL"),[K,ct]=i.useState("created_at_desc"),[ke,H]=i.useState(null),[mt,xt]=i.useState(null),[bt,Q]=i.useState(!1),[N,A]=i.useState(null),[y,_e]=i.useState(null),[ve,we]=i.useState(!1),[W,je]=i.useState(!1),[_,G]=i.useState(null),[v,Ne]=i.useState(""),[w,Z]=i.useState(null),[ye,J]=i.useState(null),[Se,Ce]=i.useState(!1),[Y,De]=i.useState(!1),[u,X]=i.useState(null),[ht,Pe]=i.useState(""),[Te,ne]=i.useState([]),[ut,ze]=i.useState(!1),[f,L]=i.useState(null),[V,F]=i.useState(null),[Ee,Ie]=i.useState(!1),[ee,$e]=i.useState(!1),k=pe.find(t=>t.value===K)||pe[0],Ae=(t,a)=>{var b,p,d,o;const{column:s,ascending:l}=k;if(s==="customers(last_name)"){const h=`${((b=t.customers)==null?void 0:b.last_name)||""} ${((p=t.customers)==null?void 0:p.first_name)||""}`.trim().toLowerCase(),T=`${((d=a.customers)==null?void 0:d.last_name)||""} ${((o=a.customers)==null?void 0:o.first_name)||""}`.trim().toLowerCase();return l?h.localeCompare(T):T.localeCompare(h)}const n=s==="price_paid"?t.price_paid||0:new Date(t.created_at).getTime(),S=s==="price_paid"?a.price_paid||0:new Date(a.created_at).getTime();return l?n-S:S-n},{page:Le,pageSize:Ve,totalCount:pt,totalPages:gt,from:oe,to:R,setPage:ft,setPageSize:kt,
16setTotalCount:_t}=Yt({resetKey:`${U}|${j}|${D}|${K}`}),Fe=t=>{let a=g.from("warranties_search").select(it,{count:"exact"}).order(k.column,{ascending:k.ascending});return t&&(a=a.or(`warranty_number.ilike.%${t}%,search_first_name.ilike.%${t}%,search_last_name.ilike.%${t}%,search_license_plate.ilike.%${t}%`)),{query:a}},Re=t=>{let a=g.from("battery_warranties_search").select(nt,{count:"exact"}).order(k.column,{ascending:k.ascending});return t&&(a=a.or(`reference_number.ilike.%${t}%,license_plate.ilike.%${t}%,search_first_name.ilike.%${t}%,search_last_name.ilike.%${t}%`)),{query:a}},{rows:te,loading:vt,error:Oe,refetch:de}=ea({queryKey:["admin_archive",Le,Ve,U,j,D,K],queryFn:async()=>{const t=U?U.replace(/[%,()]/g,""):"";if(D){const[b,p]=await Promise.all([g.from("warranties").select(it).order(k.column,{ascending:k.ascending}),g.from("battery_warranties").select(nt).order(k.column,{ascending:k.ascending})]);if(b.error)throw b.error;if(p.error)throw p.error;let d=[...ue(b.data),...ge(p.data)];return j!=="ALL"&&(d=d.filter(o=>o._type===j)),d=d.filter(o=>{var O,M,q,Je,Ye;const h=t.toLowerCase();return(!h||(((M=(O=o.vehicles)==null?void 0:O.license_plate)==null?void 0:M.toLowerCase())||"").includes(h)||`${((q=o.customers)==null?void 0:q.first_name)||""} ${((Je=o.customers)==null?void 0:Je.last_name)||""}`.toLowerCase().includes(h)||(((Ye=o.warranty_number)==null?void 0:Ye.toLowerCase())||"").includes(h))&&!lt.includes(o.status)&&Me(o.created_at,o._duration_months)}).sort(Ae),{rows:d.slice(oe,R+1),total:d.length}}if(j!=="ALL"){const b=j==="tire",{query:p}=b?Fe(t):Re(t),{data:d,error:o,count:h}=await p.range(oe,R);if(o)throw o;return{rows:b?ue(d):ge(d),total:h||0}}const[{query:a},{query:s}]=[Fe(t),Re(t)],[l,n]=await Promise.all([a.range(0,R),s.range(0,R)]);if(l.error)throw l.error;if(n.error)throw n.error;return{rows:[...ue(l.data),...ge(n.data)].sort(Ae).slice(oe,R+1),total:(l.count||0)+(n.count||0)}},setTotalCount:_t}),ae=(t,a)=>{if(!t)return null;const s=new Date(t);return s.setMonth(s.getMonth()+(a||12)),s},Me=(t,a)=>{const s=ae(t,a);if(!s)return!1;const l=new Date,n=new Date;return n.setDate(l.getDate()+30),s>l&&s<=n},wt=(t,a)=>{const s=ae(t,a);return s&&s<new Date},jt=async t=>{H(t.id);try{await Wt(t.id,`Polizza_${t.warranty_number}.pdf`)}catch(a){console.error("download PDF failed",a),c({variant:"destructive",title:"Errore PDF",description:a.message||"Impossibile generare il PDF"})}finally{H(null)}},Nt=async t=>{H(t.id);try{await Qt(t.id,`Polizza_${t.warranty_number}.pdf`)}catch(a){console.error("download PDF failed",a),c({variant:"destructive",title:"Errore PDF",description:a.message||"Impossibile generare il PDF"})}finally{H(null)}},yt=t=>t._type==="battery"?Nt(t):jt(t),St=async(t,a)=>{A({id:t,license_plate:a}),_e(null),we(!0);try{const{data:s,error:l}=await g.functions.invoke("delete-vehicle",{body:{vehicle_id:t,dry_run:!0}});if(l)throw new Error(await E(l));if(!(s!=null&&s.success))throw new Error((s==null?void 0:s.error)||"Impossibile calcolare l'impatto");_e(s.counts)}catch(s){c({variant:"destructive",title:"Errore",description:s.message||"Impossibile calcolare cosa verrebbe toccato"}),A(null)}finally{we(!1)}},Ct=async()=>{if(N){je(!0);try{const{data:t,error:a}=await g.functions.invoke("delete-vehicle",{body:{vehicle_id:N.id}});if(a)throw new Error(await E(a));if(!(t!=null&&t.success))throw new Error((t==null?void 0:t.error)||"Impossibile eliminare il veicolo");c({title:"Veicolo eliminato",description:`Targa ${N.license_plate||"-"}: eliminazione a cascata completata.`}),A(null),Q(!1),de()}catch(t){c({variant:"destructive",title:"Errore",description:t.message||"Impossibile eliminare il veicolo"})}finally{je(!1)}}},Dt=(t,a)=>{G({id:t,license_plate:a}),Ne(""),Z(null),J(null)},Pt=async()=>{if(!(!_||!v.trim())){Ce(!0),Z(null),J(null);try{const{data:t,error:a}=await g.functions.invoke("correct-vehicle-plate",{body:{vehicle_id:_.id,new_license_plate:v,dry_run:!0}});if(a)throw new Error(await E(a));if(!(t!=null&&t.success))throw new Error((t==null?void 0:t.error)||"Targa non valida");Z({license_plate:t.new_license_plate,forInput:v})}catch(t){J(t.message||"Impossibile verificare la targa")}finally{Ce(!1)}}},Tt=async()=>
16{if(!(!_||!w||w.forInput!==v)){De(!0);try{const{data:t,error:a}=await g.functions.invoke("correct-vehicle-plate",{body:{vehicle_id:_.id,new_license_plate:w.license_plate}});if(a)throw new Error(await E(a));if(!(t!=null&&t.success))throw new Error((t==null?void 0:t.error)||"Impossibile correggere la targa");c({title:"Targa corretta",description:`Nuova targa: ${t.license_plate}`}),G(null),de()}catch(t){c({variant:"destructive",title:"Errore",description:t.message||"Impossibile correggere la targa"})}finally{De(!1)}}},zt=(t,a,s)=>{X({id:t,license_plate:a,customer_id:s}),Pe(""),ne([]),L(null),F(null)},Et=async t=>{Pe(t),L(null),F(null);const a=t.trim();if(a.length<2){ne([]);return}ze(!0);try{const{data:s,error:l}=await g.from("customers").select("id, first_name, last_name, company_name, email, phone_number").is("deleted_at",null).is("suspended_at",null).neq("id",(u==null?void 0:u.customer_id)||"").or(`first_name.ilike.%${a}%,last_name.ilike.%${a}%,company_name.ilike.%${a}%,email.ilike.%${a}%,phone_number.ilike.%${a}%`).limit(10);if(l)throw l;ne(s||[])}catch(s){c({variant:"destructive",title:"Errore",description:s.message||"Ricerca cliente fallita"})}finally{ze(!1)}},It=async t=>{L(t),F(null),Ie(!0);try{const{data:a,error:s}=await g.functions.invoke("transfer-vehicle-ownership",{body:{vehicle_id:u.id,new_customer_id:t.id,dry_run:!0}});if(s)throw new Error(await E(s));if(!(a!=null&&a.success))throw new Error((a==null?void 0:a.error)||"Impossibile calcolare l'impatto");F(a)}catch(a){c({variant:"destructive",title:"Errore",description:a.message||"Impossibile calcolare l'impatto"}),L(null)}finally{Ie(!1)}},$t=async()=>{if(!(!u||!f||!V)){$e(!0);try{const{data:t,error:a}=await g.functions.invoke("transfer-vehicle-ownership",{body:{vehicle_id:u.id,new_customer_id:f.id}});if(a)throw new Error(await E(a));if(!(t!=null&&t.success))throw new Error((t==null?void 0:t.error)||"Impossibile trasferire la proprietà");const s=f.company_name||`${f.first_name} ${f.last_name}`;c({title:"Proprietà trasferita",description:`Veicolo ${u.license_plate||"-"} trasferito a ${s}.`}),X(null),Q(!1),de()}catch(t){c({variant:"destructive",title:"Errore",description:t.message||"Impossibile trasferire la proprietà"})}finally{$e(!1)}}},r=te.find(t=>t.id===mt),P=Jt([r==null?void 0:r.dot_photo_url,r==null?void 0:r.size_photo_url,r==null?void 0:r.receipt_photo_url,r==null?void 0:r.receipt_url,...Object.values((r==null?void 0:r.tire_photos)||{}).map(t=>t==null?void 0:t.photo_url)]),At=t=>{xt(t.id),Q(!0)};return Oe?e.jsxs("div",{className:"text-center text-red-500 py-12",children:["Errore nel caricamento: ",Oe.message]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(Ft,{children:e.jsx("title",{children:"Archivio Polizze | Admin"})}),e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center mb-8 gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-slate-900 dark:text-white flex items-center gap-2",children:[e.jsx(Xe,{className:"text-purple-500"})," Archivio Polizze"]}),e.jsx("p",{className:"text-slate-600 dark:text-slate-400 mt-1",children:"Consulta e gestisci tutte le garanzie attivate"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 w-full md:w-auto",children:[e.jsx("div",{className:"flex bg-slate-100 dark:bg-slate-900 rounded-lg p-1 border border-slate-200 dark:border-slate-700",children:[{key:"ALL",label:"Tutte"},{key:"tire",label:"Pneumatici"},{key:"battery",label:"Batterie"}].map(t=>e.jsx("button",{onClick:()=>dt(t.key),className:z("px-3 py-1.5 text-xs font-medium rounded-md transition-colors",j===t.key?"bg-white dark:bg-slate-800 text-slate-900 dark:text-white shadow-sm":"text-slate-600 dark:text-slate-400 hover:text-slate-900 dark:hover:text-white"),children:t.label},t.key))}),e.jsxs(m,{variant:D?"default":"outline",onClick:()=>ot(!D),className:z("gap-2 border-slate-200 dark:border-slate-700 rounded-lg",D?"bg-orange-500 hover:bg-orange-600 text-white border-transparent":"text-slate-700 dark:text-slate-300 hover:text-slate-900 dark:hover:text-white hover:bg-slate-100 dar
16k:hover:bg-slate-800"),children:[e.jsx(aa,{className:"w-4 h-4"}),"In Scadenza (30gg)"]}),e.jsxs(qt,{value:K,onValueChange:ct,children:[e.jsxs(Bt,{className:"w-full sm:w-[180px] bg-white dark:bg-slate-800 border-slate-200 dark:border-slate-700 text-slate-900 dark:text-white rounded-lg gap-2",children:[e.jsx(ra,{className:"w-4 h-4 text-slate-400 shrink-0"}),e.jsx(Ut,{placeholder:"Ordina per"})]}),e.jsx(Kt,{className:"bg-white dark:bg-slate-900 border-slate-200 dark:border-slate-800 text-slate-900 dark:text-white",children:pe.map(t=>e.jsx(Ht,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"relative w-full md:w-64",children:[e.jsx(rt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{placeholder:"Cerca per targa, nome, polizza...",value:$,onChange:t=>B(t.target.value),className:"w-full px-4 py-2 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg text-slate-900 dark:text-white placeholder-slate-400 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 transition pl-10"})]})]})]}),vt?e.jsx("div",{className:"text-center text-slate-500 dark:text-slate-400 py-12",children:"Caricamento archivio..."}):e.jsxs("div",{className:"grid gap-4",children:[te.map(t=>{var o,h,T,O,M,q;const a=lt.includes(t.status),s=oa[t.status],l=!a&&Me(t.created_at,t._duration_months),n=!a&&wt(t.created_at,t._duration_months),S=a?null:ae(t.created_at,t._duration_months),b=t.tire_configuration==="differentiated",p=t.price_paid||0,d=t._type==="battery";return e.jsx("div",{className:z("bg-white dark:bg-slate-900/50 rounded-xl p-4 border transition-all shadow-sm hover:shadow-md",l?"border-orange-500/50 hover:border-orange-500":"border-slate-200 dark:border-slate-800 hover:border-slate-300 dark:hover:border-slate-700",n?"opacity-75":""),children:e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-center gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-600 dark:text-green-400 font-mono font-bold",children:t.warranty_number}),e.jsx("span",{className:"text-xs bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400 px-2 py-0.5 rounded border border-slate-200 dark:border-slate-700",children:new Date(t.created_at).toLocaleDateString("it-IT")}),b&&e.jsxs("span",{className:"text-xs flex items-center gap-1 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300 px-2 py-0.5 rounded border border-purple-200 dark:border-purple-500/30",children:[e.jsx(na,{className:"w-3 h-3"})," Mista"]}),e.jsx("span",{className:z("text-[10px] font-bold uppercase px-2 py-0.5 rounded border",d?"bg-yellow-100 dark:bg-yellow-500/10 text-yellow-800 dark:text-yellow-300 border-yellow-300 dark:border-yellow-500/30":"bg-emerald-100 dark:bg-emerald-500/10 text-emerald-800 dark:text-emerald-300 border-emerald-300 dark:border-emerald-500/30"),children:d?"Batteria":"Pneumatici"}),t.status&&e.jsx("span",{className:z("text-[10px] font-bold uppercase px-2 py-0.5 rounded border",(s==null?void 0:s.className)||"bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-300 border-slate-200 dark:border-slate-700"),children:(s==null?void 0:s.label)||t.status})]}),e.jsxs("div",{className:"flex items-center gap-2 text-slate-900 dark:text-white font-medium",children:[e.jsx(et,{className:"w-4 h-4 text-slate-400 dark:text-slate-500"}),(o=t.customers)==null?void 0:o.first_name," ",(h=t.customers)==null?void 0:h.last_name]}),e.jsxs("div",{className:"flex items-center gap-2 text-slate-600 dark:text-slate-400 text-sm",children:[e.jsx(st,{className:"w-4 h-4 text-slate-400 dark:text-slate-500"}),(T=t.vehicles)==null?void 0:T.brand," ",(O=t.vehicles)==null?void 0:O.model,e.jsx("span",{className:"bg-slate-100 dark:bg-slate-950 px-1.5 rounded font-mono text-slate-700 dark:text-slate-300 border border-slate-200 dark:border-slate-800",children:(M=t.vehicles)==null?void 0:M.license_plate})]}),((q=t.tire_dealers)==null?void 0:q.business_name)&&e.jsxs("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:["Rivenditore: ",e.jsx("span",{className:"text-slate-700 dark:text-slate-300 font-medium",children:t.tire_dealers.business_name})]})]}),e.jsx("div",{className:"flex flex-col justify-center text-sm text-slate-600 dar
16k:text-slate-300",children:d?e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 mr-2",children:"Batteria:"}),t.battery_brand||"-"]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 mr-2",children:"Ant:"}),t.tire_brand]}),b&&e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 mr-2",children:"Post:"}),t.rear_tire_brand]})]})}),e.jsxs("div",{className:"flex flex-col md:flex-row items-center gap-4 mt-2 md:mt-0",children:[e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-slate-500 text-xs uppercase tracking-wider",children:"Scadenza"}),e.jsxs("div",{className:z("flex items-center gap-1 font-bold px-2 py-1 rounded text-sm",l?"bg-orange-50 dark:bg-orange-500/20 text-orange-600 dark:text-orange-400 border border-orange-200 dark:border-orange-500/30":n?"bg-red-50 dark:bg-red-500/10 text-red-600 dark:text-red-500 border border-red-200 dark:border-red-500/20":"bg-slate-100 dark:bg-slate-800 text-slate-900 dark:text-white border border-slate-200 dark:border-slate-700"),children:[e.jsx(sa,{className:"w-4 h-4"}),a?"—":(S==null?void 0:S.toLocaleDateString("it-IT"))||"N/D"]})]}),e.jsxs("div",{className:"text-xs text-slate-500 flex items-center justify-end gap-2 mt-1",children:[p>0&&e.jsx("span",{className:"font-mono text-green-600 dark:text-green-400 mr-2",children:at(p)}),e.jsxs("span",{children:[t._duration_months," Mesi"]}),e.jsx("span",{className:`px-2 rounded text-slate-900 font-bold text-[10px] uppercase ${t.warranty_type==="gold"?"bg-yellow-400":"bg-slate-200 dark:bg-slate-300"}`,children:t.warranty_type})]})]}),e.jsxs(m,{size:"sm",onClick:()=>At(t),className:"bg-white dark:bg-slate-800 hover:bg-slate-50 dark:hover:bg-slate-700 text-slate-700 dark:text-white border border-slate-200 dark:border-slate-600 rounded-lg shadow-sm",children:[e.jsx(tt,{className:"w-4 h-4 mr-2"})," Dettagli"]})]})]})},t.id)}),te.length===0&&e.jsxs("div",{className:"bg-white dark:bg-slate-900/50 p-12 rounded-xl border border-slate-200 dark:border-slate-800 text-center text-slate-500 flex flex-col items-center",children:[e.jsx(Xe,{className:"w-12 h-12 mb-4 opacity-20 text-slate-400"}),e.jsx("p",{children:"Nessuna polizza trovata con questi criteri."})]}),te.length>0&&e.jsx(Xt,{page:Le,pageSize:Ve,totalCount:pt,totalPages:gt,onPageChange:ft,onPageSizeChange:kt,className:"pt-2"})]}),e.jsx(re,{open:bt,onOpenChange:Q,children:e.jsx(se,{className:"bg-white dark:bg-slate-950 border-slate-200 dark:border-slate-800 text-slate-900 dark:text-white max-w-4xl h-[90vh] flex flex-col p-0 overflow-hidden",children:r&&e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"p-6 border-b border-slate-200 dark:border-slate-800 bg-slate-50 dark:bg-slate-900/50",children:e.jsxs("div",{className:"flex justify-between items-start pr-8",children:[e.jsxs("div",{children:[e.jsxs(ie,{className:"text-2xl font-bold flex items-center gap-3",children:[r.warranty_number,e.jsx(Zt,{variant:r.warranty_type==="gold"?"warning":"secondary",className:r.warranty_type==="gold"?"bg-yellow-400 text-slate-900 hover:bg-yellow-500":"bg-slate-200 text-slate-900 hover:bg-slate-300",children:r.warranty_type.toUpperCase()})]}),e.jsxs("p",{className:"text-slate-500 dark:text-slate-400 mt-1 flex items-center gap-2",children:["Attivata il ",new Date(r.created_at).toLocaleDateString("it-IT"),e.jsx("span",{className:"text-slate-400 dark:text-slate-600",children:"•"}),"Scadenza: ",(qe=ae(r.created_at,r._duration_months))==null?void 0:qe.toLocaleDateString("it-IT")]})]}),e.jsxs(m,{onClick:()=>yt(r),disabled:ke===r.id,variant:"outline",className:"border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800 text-green-600 dark:text-green-400 rounded-lg",children:[e.jsx(Rt,{className:"w-4 h-4 mr-2"})," ",ke===r.id?"Generazione...":"Scarica PDF"]})]})}),e.jsx(Gt,{className:"flex-1 p-6",children:e.jsxs("div",{className:"grid md:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-slate-50 dark:bg-slate-900 p-5 rounded-xl border border-slate-200 dark:border-slate-800",children:[e.jsxs("h3",{className:"text-slate-500 dark:text-slate-400 uppercase text-xs font-bold mb-4 flex items-center gap-2",children:[e.jsx(et,{className:"w-4 h-4"})," Dati Cliente"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between border-b border-slate-200 dark:border-slate-800 pb-2",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400 text-sm",children:"Nome Completo"}),e.jsxs("span",{className:"font-medium text-slate-900 dark:text-white",children:[(Be=r.customers)==null?void 0:Be.first_name," ",(Ue=r.customers)==null?void 0:Ue.last_name]})]}),e.jsxs("div",{className:"flex justify-between border-b border-slate-200 dark:border-slate-800 pb-2",children:[e.jsxs("span",{className:"text-slate-500 dark:text-slate-400 text-sm flex items-center gap-2",children:[e.jsx(Ot,{className:"w-3 h-3"})," Email"]}),e.jsx("span",{className:"font-medium text-slate-900 dark:text-white",children:(Ke
16=r.customers)==null?void 0:Ke.email})]}),e.jsxs("div",{className:"flex justify-between pb-2",children:[e.jsxs("span",{className:"text-slate-500 dark:text-slate-400 text-sm flex items-center gap-2",children:[e.jsx(Mt,{className:"w-3 h-3"})," Telefono"]}),e.jsx("span",{className:"font-medium text-slate-900 dark:text-white",children:((He=r.customers)==null?void 0:He.phone_number)||"-"})]})]})]}),e.jsxs("div",{className:"bg-slate-50 dark:bg-slate-900 p-5 rounded-xl border border-slate-200 dark:border-slate-800",children:[e.jsxs("h3",{className:"text-slate-500 dark:text-slate-400 uppercase text-xs font-bold mb-4 flex items-center gap-2",children:[e.jsx(st,{className:"w-4 h-4"})," Veicolo"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between border-b border-slate-200 dark:border-slate-800 pb-2",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400 text-sm",children:"Targa"}),e.jsx("span",{className:"font-mono bg-slate-200 dark:bg-white text-slate-900 px-2 rounded font-bold",children:(Qe=r.vehicles)==null?void 0:Qe.license_plate})]}),e.jsxs("div",{className:"flex justify-between border-b border-slate-200 dark:border-slate-800 pb-2",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400 text-sm",children:"Marca / Modello"}),e.jsxs("span",{className:"font-medium text-right text-slate-900 dark:text-white",children:[(We=r.vehicles)==null?void 0:We.brand," ",(Ge=r.vehicles)==null?void 0:Ge.model]})]}),e.jsxs("div",{className:"flex justify-between border-b border-slate-200 dark:border-slate-800 pb-2",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400 text-sm",children:"Km al Montaggio"}),e.jsxs("span",{className:"font-medium text-slate-900 dark:text-white",children:[r.km_montaggio||"-"," km"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400 text-sm",children:"Km Annui Stimati"}),e.jsxs("span",{className:"font-medium text-slate-900 dark:text-white",children:[r.km_percorsi_annui||"-"," km"]})]})]}),r.vehicle_id&&((Ze=r.vehicles)!=null&&Ze.deleted_at?e.jsxs("p",{className:"mt-4 text-xs text-slate-500 dark:text-slate-400 flex items-center gap-1.5",children:[e.jsx(xe,{className:"w-3.5 h-3.5"})," Veicolo eliminato"]}):e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs(m,{onClick:()=>{var t;return zt(r.vehicle_id,(t=r.vehicles)==null?void 0:t.license_plate,r.customer_id)},variant:"outline",size:"sm",className:"w-full border-blue-200 dark:border-blue-900 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-500/10",children:[e.jsx(he,{className:"w-4 h-4 mr-2"})," Trasferisci proprietà"]}),e.jsxs(m,{onClick:()=>{var t;return Dt(r.vehicle_id,(t=r.vehicles)==null?void 0:t.license_plate)},variant:"outline",size:"sm",className:"w-full border-slate-200 dark:border-slate-700 text-slate-700 dark:text-slate-300 hover:bg-slate-50 dark:hover:bg-slate-800",children:[e.jsx(be,{className:"w-4 h-4 mr-2"})," Correggi targa"]}),e.jsxs(m,{onClick:()=>{var t;return St(r.vehicle_id,(t=r.vehicles)==null?void 0:t.license_plate)},variant:"outline",size:"sm",className:"w-full border-red-200 dark:border-red-900 text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10",children:[e.jsx(xe,{className:"w-4 h-4 mr-2"})," Elimina veicolo"]})]}))]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-slate-50 dark:bg-slate-900 p-5 rounded-xl border border-slate-200 dark:border-slate-800",children:[e.jsxs("h3",{className:"text-slate-500 dark:text-slate-400 uppercase text-xs font-bold mb-4 flex items-center gap-2",children:[e.jsx(ia,{className:"w-4 h-4"})," Dettagli Polizza"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center border-b border-slate-200 dark:border-slate-800 pb-3",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400 text-sm",children:"Importo Pagato"}),e.jsx("span",{className:"font-bold text-green-600 dark:text-green-400 text-lg",children:at(r.price_paid||0)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-slate-500 mb-1",children:r.tire_configuration==="identical"?"Tutti i Pneumatici":"Asse Anteriore"}),e.jsxs("div",{className:"flex justify-between items-center bg-white dark:bg-slate-950 p-3 rounded-lg border border-slate-200 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-slate-900 dark:text-white",children:r.tire_brand}),e.jsx("div",{className:"text-sm text-slate-500 dark:text-slate-400",children:r.tire_size})]}
16),e.jsxs("div",{className:"text-xs bg-slate-100 dark:bg-slate-800 text-slate-700 dark:text-slate-300 px-2 py-1 rounded",children:["R",r.rim_size,'"']})]})]}),r.tire_configuration==="differentiated"&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-slate-500 mb-1",children:"Asse Posteriore"}),e.jsx("div",{className:"flex justify-between items-center bg-white dark:bg-slate-950 p-3 rounded-lg border border-slate-200 dark:border-slate-800",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-slate-900 dark:text-white",children:r.rear_tire_brand}),e.jsx("div",{className:"text-sm text-slate-500 dark:text-slate-400",children:r.rear_tire_size})]})})]})]})]}),e.jsxs("div",{className:"bg-slate-50 dark:bg-slate-900 p-5 rounded-xl border border-slate-200 dark:border-slate-800",children:[e.jsxs("h3",{className:"text-slate-500 dark:text-slate-400 uppercase text-xs font-bold mb-4 flex items-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"})," Documentazione Fotografica"]}),(()=>{const t=r.tire_photos||{},a=[{key:"fl",label:"Anteriore Sinistro",icon:"↖"},{key:"fr",label:"Anteriore Destro",icon:"↗"},{key:"rl",label:"Posteriore Sinistro",icon:"↙"},{key:"rr",label:"Posteriore Destro",icon:"↘"}],s=a.some(l=>{var n;return(n=t[l.key])==null?void 0:n.photo_url});return e.jsxs("div",{className:"space-y-4",children:[s?e.jsx("div",{className:"grid grid-cols-2 gap-3",children:a.map(l=>{const n=t[l.key]||{};return e.jsxs("div",{className:"bg-white dark:bg-slate-950 border border-slate-200 dark:border-slate-800 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-2 py-1 bg-slate-100 dark:bg-slate-900 border-b border-slate-200 dark:border-slate-800",children:[e.jsxs("span",{className:"text-xs font-semibold text-slate-700 dark:text-slate-300 flex items-center gap-1",children:[e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:l.icon})," ",l.label]}),e.jsxs("span",{className:"text-[10px] font-mono bg-slate-200 dark:bg-slate-800 text-slate-800 dark:text-slate-200 px-1.5 py-0.5 rounded",children:["DOT ",n.dot||"—"]})]}),n.photo_url?e.jsx("a",{href:P(n.photo_url),target:"_blank",rel:"noopener noreferrer",className:"block aspect-video",children:e.jsx("img",{src:P(n.photo_url),alt:l.label,className:"w-full h-full object-cover hover:opacity-80 transition-opacity"})}):e.jsx("div",{className:"aspect-video flex items-center justify-center text-slate-400 text-xs bg-slate-100 dark:bg-slate-900",children:"Nessuna foto"})]},l.key)})}):r.dot_photo_url?e.jsx("a",{href:P(r.dot_photo_url),target:"_blank",rel:"noopener noreferrer",className:"group relative block aspect-video bg-slate-200 dark:bg-slate-950 rounded-lg overflow-hidden border border-slate-200 dark:border-slate-800",children:e.jsx("img",{src:P(r.dot_photo_url),alt:"DOT",className:"w-full h-full object-cover"})}):e.jsx("p",{className:"text-sm text-slate-500 italic",children:"Nessuna foto pneumatico caricata."}),r.receipt_photo_url&&e.jsxs("a",{href:P(r.receipt_photo_url),target:"_blank",rel:"noopener noreferrer",className:"group relative block aspect-video bg-slate-200 dark:bg-slate-950 rounded-lg overflow-hidden border border-slate-200 dark:border-slate-800",children:[e.jsx("div",{className:"absolute top-2 right-2 bg-green-500 text-white text-[10px] font-bold px-2 py-1 rounded z-10",children:"SCONTRINO"}),e.jsx("img",{src:P(r.receipt_photo_url),alt:"Scontrino",className:"w-full h-full object-cover group-hover:opacity-75 transition-opacity"})]})]})})()]})]})]})})]})})}),e.jsx(re,{open:!!N,onOpenChange:t=>!t&&!W&&A(null),children:e.jsxs(se,{className:"bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 text-slate-900 dark:text-white",children:[e.jsxs(le,{children:[e.jsxs(ie,{className:"flex items-center gap-2",children:[e.jsx(la,{className:"w-5 h-5 text-red-500"})," Conferma eliminazione veicolo"]}),e.jsxs(ce,{className:"text-slate-700 dark:text-slate-300",children:["Stai per eliminare il veicolo ",e.jsx("strong",{children:(N==null?void 0:N.license_plate)||"-"}),".",ve?e.jsxs("span",{className:"flex items-center gap-2 mt-3",children:[e.jsx(C,{className:"w-4 h-4 animate-spin"})," Calcolo impatto in corso..."]}):y&&e.jsxs("span",{className:"block mt-3",children:["Verranno eliminate ",e.jsxs("strong",{children:[y.warranties," garanzie gomme"]})," e"," ",e.jsxs("strong",{children:[y.batteryWarranties," garanzie batteria"]}),", con"," ",e.jsxs("strong",{children:[y.claims," sinistri"]})," collegati.",y.b2bCodesReset>0&&e.jsxs(e.Fragment,{children:[" ",y.b2bCodesReset," codice/i B2B usati su queste garanzie torneranno disponibili."]}),e.jsx("br",{}),"L'eliminazione è recuperabile solo da un intervento diretto sul database."]})]})]}),e.jsxs(me,{className:"mt-4",children:[e.jsx(m,{variant:"ghost",onClick:()=>
16A(null),disabled:W,className:"hover:bg-slate-100 dark:hover:bg-slate-800 text-slate-700 dark:text-slate-300 border border-slate-200 dark:border-slate-700",children:"Annulla"}),e.jsxs(m,{variant:"destructive",onClick:Ct,disabled:W||ve||!y,className:"bg-red-600 hover:bg-red-700 text-white",children:[W?e.jsx(C,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(xe,{className:"w-4 h-4 mr-2"}),"Elimina Definitivamente"]})]})]})}),e.jsx(re,{open:!!_,onOpenChange:t=>!t&&!Y&&G(null),children:e.jsxs(se,{className:"bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 text-slate-900 dark:text-white",children:[e.jsxs(le,{children:[e.jsxs(ie,{className:"flex items-center gap-2",children:[e.jsx(be,{className:"w-5 h-5 text-blue-500"})," Correggi targa"]}),e.jsxs(ce,{className:"text-slate-700 dark:text-slate-300",children:["Targa attuale: ",e.jsx("strong",{className:"font-mono",children:(_==null?void 0:_.license_plate)||"-"})]})]}),e.jsxs("div",{className:"space-y-3 mt-2",children:[e.jsx("input",{placeholder:"Nuova targa",value:v,onChange:t=>{Ne(t.target.value),Z(null),J(null)},className:"w-full px-4 py-2 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg text-slate-900 dark:text-white placeholder-slate-400 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 transition font-mono uppercase"}),e.jsxs(m,{onClick:Pt,disabled:!v.trim()||Se,variant:"outline",size:"sm",className:"w-full border-slate-200 dark:border-slate-700",children:[Se?e.jsx(C,{className:"w-4 h-4 animate-spin mr-2"}):null," Verifica"]}),ye&&e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:ye}),w&&w.forInput===v&&e.jsxs("p",{className:"text-sm text-green-600 dark:text-green-400",children:["Nuova targa: ",e.jsx("strong",{className:"font-mono",children:w.license_plate})]})]}),e.jsxs(me,{className:"mt-4",children:[e.jsx(m,{variant:"ghost",onClick:()=>G(null),disabled:Y,className:"hover:bg-slate-100 dark:hover:bg-slate-800 text-slate-700 dark:text-slate-300 border border-slate-200 dark:border-slate-700",children:"Annulla"}),e.jsxs(m,{onClick:Tt,disabled:Y||!w||w.forInput!==v,className:"bg-blue-600 hover:bg-blue-700 text-white",children:[Y?e.jsx(C,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(be,{className:"w-4 h-4 mr-2"}),"Conferma correzione"]})]})]})}),e.jsx(re,{open:!!u,onOpenChange:t=>!t&&!ee&&X(null),children:e.jsxs(se,{className:"bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 text-slate-900 dark:text-white max-w-lg",children:[e.jsxs(le,{children:[e.jsxs(ie,{className:"flex items-center gap-2",children:[e.jsx(he,{className:"w-5 h-5 text-blue-500"})," Trasferisci proprietà veicolo"]}),e.jsxs(ce,{className:"text-slate-700 dark:text-slate-300",children:["Veicolo ",e.jsx("strong",{className:"font-mono",children:(u==null?void 0:u.license_plate)||"-"}),". La garanzia mantiene il suo termine originale: cambia solo l'intestatario."]})]}),e.jsxs("div",{className:"space-y-3 mt-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(rt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{placeholder:"Cerca il nuovo proprietario per nome, email o telefono...",value:ht,onChange:t=>Et(t.target.value),className:"w-full px-4 py-2 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg text-slate-900 dark:text-white placeholder-slate-400 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 transition pl-10"})]}),ut&&e.jsxs("p",{className:"text-sm text-slate-500 flex items-center gap-2",children:[e.jsx(C,{className:"w-4 h-4 animate-spin"})," Ricerca..."]}),!f&&Te.length>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1 border border-slate-200 dark:border-slate-800 rounded-lg p-1",children:Te.map(t=>e.jsxs("button",{onClick:()=>It(t),className:"w-full text-left px-3 py-2 rounded-md hover:bg-slate-100 dark:hover:bg-slate-800 text-sm",children:[e.jsx("div",{className:"font-medium text-slate-900 dark:text-white",children:t.company_name||`${t.first_name} ${t.last_name}`}),e.jsxs("div",{className:"text-xs text-slate-500",children:[t.email,t.ph
16one_number?` • ${t.phone_number}`:""]})]},t.id))}),f&&e.jsxs("div",{className:"bg-slate-50 dark:bg-slate-950 border border-slate-200 dark:border-slate-800 rounded-lg p-3 space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium text-slate-900 dark:text-white",children:["Nuovo proprietario: ",f.company_name||`${f.first_name} ${f.last_name}`]}),e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>{L(null),F(null)},children:"Cambia"})]}),Ee?e.jsxs("span",{className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(C,{className:"w-4 h-4 animate-spin"})," Calcolo impatto in corso..."]}):V&&e.jsxs("p",{className:"text-sm text-slate-600 dark:text-slate-300",children:["Verranno spostate ",e.jsxs("strong",{children:[V.counts.warranties," garanzie gomme"]})," e"," ",e.jsxs("strong",{children:[V.counts.batteryWarranties," garanzie batteria"]}),". Prezzo, stato e scadenza restano invariati."]})]})]}),e.jsxs(me,{className:"mt-4",children:[e.jsx(m,{variant:"ghost",onClick:()=>X(null),disabled:ee,className:"hover:bg-slate-100 dark:hover:bg-slate-800 text-slate-700 dark:text-slate-300 border border-slate-200 dark:border-slate-700",children:"Annulla"}),e.jsxs(m,{onClick:$t,disabled:ee||Ee||!V,className:"bg-blue-600 hover:bg-blue-700 text-white",children:[ee?e.jsx(C,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(he,{className:"w-4 h-4 mr-2"}),"Conferma trasferimento"]})]})]})})]})};export{Ea 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.