import{u,j as e,H as g,L as m}from"./app-CAqQVdqj.js";import{A as p}from"./AuthenticatedLayout-CQEcc2iz.js";import{b as h,f as b}from"./utils-f31lc4sE.js";function v({reading:t}){const i=t.lease,{data:r,setData:d,put:c,processing:l,errors:a}=u({previous_reading:t.previous_reading||"",current_reading:t.current_reading||"",rate_per_unit:t.rate_per_unit||""}),n=(parseFloat(r.current_reading)||0)-(parseFloat(r.previous_reading)||0),o=n>0?n*(parseFloat(r.rate_per_unit)||0):0,x=s=>{s.preventDefault(),c(route("meter-readings.update",t.id))};return e.jsxs(p,{header:e.jsx("h2",{className:"text-xl font-semibold leading-tight text-gray-800",children:"Edit Meter Reading"}),children:[e.jsx(g,{title:"Edit Meter Reading"}),e.jsx("div",{className:"py-12",children:e.jsx("div",{className:"mx-auto max-w-2xl sm:px-6 lg:px-8",children:e.jsx("div",{className:"overflow-hidden bg-white shadow-sm sm:rounded-lg",children:e.jsxs("div",{className:"p-6 text-gray-900",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-lg font-medium",children:"Edit Meter Reading"}),e.jsx(m,{href:route("meter-readings.index"),className:"inline-flex items-center rounded-md bg-gray-200 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-300",children:"Back"})]}),e.jsx("div",{className:"rounded-lg border border-gray-200 bg-gray-50 p-4 mb-6",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Shop"}),e.jsxs("p",{className:"font-medium text-gray-900",children:["Shop ",i?.shop?.shop_number||"—"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Tenant"}),e.jsx("p",{className:"font-medium text-gray-900",children:i?.tenant?.name||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Month"}),e.jsx("p",{className:"font-medium text-gray-900",children:h(t.month)})]})]})}),e.jsxs("form",{onSubmit:x,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700",children:["Previous Reading ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"number",step:"0.01",min:"0",value:r.previous_reading,onChange:s=>d("previous_reading",s.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"}),a.previous_reading&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:a.previous_reading})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700",children:["Current Reading ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"number",step:"0.01",min:"0",value:r.current_reading,onChange:s=>d("current_reading",s.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"}),a.current_reading&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:a.current_reading})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700",children:["Rate Per Unit (PKR) ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"number",step:"0.01",min:"0",value:r.rate_per_unit,onChange:s=>d("rate_per_unit",s.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"}),a.rate_per_unit&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:a.rate_per_unit})]}),e.jsx("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Units Consumed"}),e.jsx("p",{className:"font-semibold text-gray-900",children:n>0?n.toFixed(2):"0.00"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Total Amount"}),e.jsx("p",{className:"font-bold text-blue-800",children:b(o)})]})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-4",children:[e.jsx(m,{href:route("meter-readings.index"),className:"text-sm text-gray-600 hover:text-gray-900",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:l,className:"inline-flex items-center rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:l?"Updating...":"Update Reading"})]})]})]})})})})]})}export{v as default};
