1import{u as q,r as a,j as e,P as A,T as I,C as O,K as X,X as _}from"./index-YNl15AGx.js";import{getBusinessVehicles as $,deleteBusinessVehicle as G,updateBusinessVehicle as H,addBusinessVehicle as J}from"./parkingService-CMiK1hr_.js";import{T as Q}from"./trash-2-C0uQVSTv.js";function W({vehicle:o,onSave:r,onClose:g,t:l}){const w=X(!0),h=!!o,[d,C]=a.useState({registrationNumber:(o==null?void 0:o.registrationNumber)||"",note:(o==null?void 0:o.note)||""}),[y,f]=a.useState(!1),[m,N]=a.useState("");a.useEffect(()=>{function s(n){n.key==="Escape"&&g()}return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[g]);function i(s,n){C(c=>({...c,[s]:n}))}async function x(){var n;const s=d.registrationNumber.trim().toUpperCase();if(!s){N(l("vehicles.form.error.required"));return}f(!0);try{const c={registrationNumber:s,note:d.note.trim(),id:(n=o==null?void 0:o.id)==null?void 0:n.uuid};h?await H(c):await J(c),r()}catch(c){N(l("vehicles.form.error.save"))}finally{f(!1)}}const j="border border-gray-300 rounded-mobill-sm px-3 py-1.5 text-sm w-full focus:border-mobill-primary";return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 !mt-0",onClick:s=>{s.target===s.currentTarget&&g()},children:e.jsxs("div",{ref:w,role:"dialog","aria-modal":"true","aria-labelledby":"vehicle-dialog-title",className:"bg-white rounded-mobill-sm shadow-xl w-full max-w-md mx-4 p-6 relative",children:[e.jsx("button",{onClick:g,className:"absolute top-4 right-4 text-gray-400 hover:text-gray-600 transition-colors","aria-label":l("common.close"),children:e.jsx(_,{size:20})}),e.jsx("h3",{id:"vehicle-dialog-title",className:"text-xl font-bold font-sans mb-4",children:l(h?"vehicles.form.title.edit":"vehicles.form.title.new")}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-gray-500 mb-1",children:[l("vehicles.sort-type.options.regnbr")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:d.registrationNumber,disabled:h,maxLength:12,onChange:s=>i("registrationNumber",s.target.value.toUpperCase()),placeholder:l("my-cars-widget.car-number.placeholder"),className:j+(h?" bg-gray-50 text-gray-500":"")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-gray-500 mb-1",children:l("vehicles.sort-type.options.note")}),e.jsx("input",{type:"text",value:d.note,maxLength:50,onChange:s=>i("note",s.target.value),placeholder:l("vehicles.form.note.placeholder"),className:j})]})]}),m&&e.jsx("p",{role:"alert",className:"text-red-500 text-xs mt-3",children:m}),e.jsxs("div",{className:"mt-5 flex gap-2 justify-end",children:[e.jsx("button",{onClick:g,className:"border border-gray-300 text-gray-600 text-sm font-semibold px-4 py-1.5 rounded-mobill-sm hover:bg-gray-50 transition-colors",children:l("common.cancel")}),e.jsx("button",{onClick:x,disabled:y,className:"bg-mobill-primary text-white text-sm font-semibold px-5 py-1.5 rounded-mobill-sm hover:bg-mobill-primary/90 transition-colors disabled:opacity-50",children:y?"...":l("common.save")})]})]})})}function te({lang:o="sv"}){const{t:r}=q(o),[g,l]=a.useState([]),[w,h]=a.useState(!0),[d,C]=a.useState("registrationNumber"),[y,f]=a.useState(!1),[m,N]=a.useState(10),[i,x]=a.useState(1),[j,s]=a.useState(null),[n,c]=a.useState(null),[k,E]=a.useState(!1),[D,v]=a.useState("");a.useEffect(()=>{V()},[]);async function V(){h(!0);try{const t=await $();l(t||[])}catch(t){l([])}finally{h(!1)}}async function L(){E(!0),v("");try{await G(n),l(t=>t.filter(b=>b.registrationNumber!==n.registrationNumber)),c(null)}catch(t){v(r("error.generic"))}finally{E(!1)}}function M(t){d===t?f(b=>!b):(C(t),f(!1)),x(1)}const z=[...g].sort((t,b)=>{var T,F;const u=(T=t[d])!=null?T:"",K=(F=b[d])!=null?F:"",P=String(u).localeCompare(String(K));return y?-P:P}),S=z.length,p=Math.max(1,Math.ceil(S/m)),B=z.slice((i-1)*m,i*m),R=[{field:"registrationNumber",label:r("vehicles.sort-type.options.regnbr")},{field:"note",label:r("vehicles.sort-type.options.note")}];function U({field:t}){return d!==t?null:y?e.jsx(I,{size:13,className:"inline ml-1"}):e.jsx(O,{size:13,className:"inline ml-1"})}return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-6",children:[e.jsx("div",{className:"lg:col-span-12 min-w-0",children:e.jsxs("div",{className:"bg-white rounded-mobill-sm border border-black/10 shadow-sm p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsx("h2",{className:"text-xl font-bold font-sans",children:r("vehicles.title")}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("label",{className:"text-xs text-gray-500 whitespace-nowrap",children:[r("vehicles.items-per-page.label"),":",e.jsx("select",{value:m,onChange:t=>{N(Number(t.target.value)),x(1)},className:"ml-2 border border-gray-300 rounded-mobill-sm px-2 py-1 text-sm focus:outline-none focus:border-mobill-primary",children:[10,20,30,50,100].map(t=>e.jsx("option",{value:t,children:t},t))})]}),e.jsxs("button",{onClick:()=>s({}),className:"flex items-center gap-1.5 bg-mobill-primary text-white text-sm font-semibold px-4 py-2 rounded-mobill-sm hover:bg-mobill-primary/90 transition-colors whitespace-nowrap",children:[e.jsx(A,{size:15}),r("vehicles.btn.add-new-vehicle")]})]})]}),w?e.jsx("p",{className:"text-sm text-gray-400",children:r("common.loading")}):g.length===0?e.jsx("div",{className:"bg-blue-50 border border-blue-200 rounded-mobill-sm px-4 py-3 text-sm text-blue-700",children:r("vehicles.msg.no-vehicles")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200",children:[R.map(t=>e.jsxs("th",{onClick:()=>M(t.field),className:"py-2 px-2 text-left text-xs font-semibold text-gray-500 cursor-pointer select-none whitespace-nowrap hover:text-mobill-primary",children:[t.label,e.jsx(U,{field:t.field})]},t.field)),e.jsx("th",{className:"py-2 px-2 text-right text-xs font-semibold text-gray-500",children:r("vehicles.table.action")})]})}),e.jsx("tbody",{children:B.map((t,b)=>e.jsxs("tr",{className:"border-b border-gray-100 hover:bg-gray-50 cursor-pointer",onClick:()=>s({vehicle:t}),children:[e.jsx("td",{className:"py-2 px-2 font-medium",children:t.registrationNumber||"-"}),e.jsx("td",{className:"py-2 px-2 text-gray-600",children:t.note||"-"}),e.jsx("td",{className:"py-2 px-2 text-right",children:e.jsx("button",{onClick:u=>{u.stopPropagation(),c(t)},className:"text-gray-400 hover:text-red-500 transition-colors p-1","aria-label":r("vehicles.table.action"),children:e.jsx(Q,{size:16})})})]},t.registrationNumber||b))})]})}),p>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4 text-sm",children:[e.jsxs("span",{className:"text-gray-500 text-xs",children:[(i-1)*m+1,"â",Math.min(i*m,S)," / ",S]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>x(1),disabled:i===1,className:"px-2 py-1 rounded border border-gray-200 text-xs disabled:opacity-40 hover:bg-gray-50",children:"«"}),e.jsx("button",{onClick:()=>x(t=>t-1),disabled:i===1,className:"px-2 py-1 rounded border border-gray-200 text-xs disabled:opacity-40 hover:bg-gray-50",children:"â¹"}),Array.from({length:Math.min(p,7)},(t,b)=>{const u=Math.max(1,Math.min(i-3,p-6))+b;return u<=p?e.jsx("button",{onClick:()=>x(u),className:"px-2.5 py-1 rounded border text-xs ".concat(u===i?"bg-mobill-primary text-white border-mobill-primary":"border-gray-200 hover:bg-gray-50"),children:u},u):null}),e.jsx("button",{onClick:()=>x(t=>t+1),disabled:i===p,className:"px-2 py-1 rounded border border-gray-200 text-xs disabled:opacity-40 hover:bg-gray-50",children:"âº"}),e.jsx("button",{onClick:()=>x(p),disabled:i===p,className:"px-2 py-1 rounded border border-gray-200 text-xs disabled:opacity-40 hover:bg-gray-50",children:"»"})]})]})]})]})}),j&&e.jsx(W,{vehicle:j.vehicle,t:r,onClose:()=>s(null),onSave:()=>{s(null),V()}}),n&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 !mt-0",onClick:t=>{t.target===t.currentTarget&&(c(null),v(""))},children:e.jsxs("div",{className:"bg-white rounded-mobill-sm shadow-xl w-full max-w-sm mx-4 p-6",children:[e.jsx("h3",{className:"text-lg font-bold font-sans mb-2",children:r("vehicles.deleti
1on-dialog.title")}),e.jsxs("p",{className:"text-sm text-gray-600 mb-5",children:[r("vehicles.deletion-dialog.msg").replace("{{vehicle}}",n.registrationNumber),"?"]}),D&&e.jsx("p",{className:"text-red-500 text-xs mb-3",role:"alert",children:D}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>{c(null),v("")},disabled:k,className:"border border-gray-300 text-gray-600 text-sm font-semibold px-4 py-1.5 rounded-mobill-sm hover:bg-gray-50 transition-colors disabled:opacity-50",children:r("common.cancel")}),e.jsx("button",{onClick:L,disabled:k,className:"bg-red-500 text-white text-sm font-semibold px-5 py-1.5 rounded-mobill-sm hover:bg-red-600 transition-colors disabled:opacity-50",children:k?"...":r("common.yes")})]})]})})]})}export{te 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.