1import{j as e}from"./vendor-radix-08a60bdd.js";import{u as s,r as a}from"./vendor-react-9016e4a2.js";import{N as t,y as r,x as d,B as l,A as i,C as c,E as o,F as n,L as x,I as m,Q as h,S as g}from"./index-06245da3.js";import{g as u,d as p,s as j,u as v,a as f}from"./addressService-7ed92d4c.js";import{T as N}from"./textarea-63378c77.js";import{D as y,a as b,b as w,c as k}from"./dropdown-menu-ae82a015.js";import{t as C,J as A,$ as _,a0 as D,a1 as O,a2 as P,a3 as S,a4 as F,a5 as H}from"./vendor-icons-f2656d21.js";import"./vendor-supabase-36eb0853.js";import"./vendor-capacitor-43d743f6.js";import"./vendor-motion-a26fe6c4.js";function L(){const L=s(),{user:z}=t(),{toast:K}=r(),{t:T}=d(),[W,$]=a.useState([]),[E,U]=a.useState(!0),[Y,B]=a.useState(!1),[I,J]=a.useState(null),[M,Q]=a.useState({title:"",address:"",details:"",gate_code:"",is_default:!1}),[R,q]=a.useState("Home"),G=e=>{const s=(a=e,a?.trim().toLocaleLowerCase("tr-TR").normalize("NFKD").replace(/[\u0300-\u036f]/g,"")||"");var a;return["ev","home"].includes(s)?"Home":["is","ofis","work","office"].includes(s)?"Work":"Other"},V=e=>{const s=G(e);return"Home"===s?T("home"):"Work"===s?T("work"):e};a.useEffect(()=>{z&&X()},[z]);const X=async()=>{try{U(!0);const e=await u(z.id);$(e||[])}catch(e){K({title:T("errorOccurred"),description:T("addressLoadFailed"),variant:"destructive"})}finally{U(!1)}};return e.jsxs("div",{className:"min-h-screen bg-gray-50 pb-24",children:[e.jsx("div",{className:"bg-white border-b sticky top-0 z-10",children:e.jsxs("div",{className:"max-w-md lg:max-w-2xl mx-auto px-4 h-16 flex items-center gap-3",children:[e.jsx(l,{variant:"ghost",size:"icon",className:"-ml-2 text-gray-500 hover:text-gray-900",onClick:()=>L(-1),children:e.jsx(C,{className:"h-6 w-6"})}),e.jsx("h1",{className:"text-xl font-bold text-gray-900",children:T("myAddresses")})]})}),e.jsx("div",{className:"max-w-md lg:max-w-2xl mx-auto px-4 py-6 lg:py-8 space-y-4",children:E?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-orange-500"})}):0===W.length?e.jsxs("div",{className:"text-center py-12 bg-white rounded-2xl border border-gray-100 shadow-sm",children:[e.jsx("div",{className:"h-16 w-16 bg-orange-50 rounded-full flex items-center justify-center mx-auto mb-4 text-orange-500",children:e.jsx(A,{className:"h-8 w-8"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900",children:T("noAddressesYet")}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 max-w-[200px] mx-auto",children:T("addDeliveryAddresses")})]}):W.map(s=>{const a=(e=>{const s=G(e);return"Home"===s?F:"Work"===s?H:A})(s.title);return e.jsx("div",{className:"bg-white rounded-2xl p-4 shadow-sm border border-gray-100 group relative",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-10 w-10 rounded-full flex items-center justify-center shrink-0 "+(s.is_default?"bg-orange-100 text-orange-600":"bg-gray-100 text-gray-600"),children:e.jsx(a,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1 min-w-0 pr-8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-gray-900",children:V(s.title)}),s.is_default&&e.jsx("span",{className:"bg-orange-100 text-orange-700 text-[10px] font-bold px-2 py-0.5 rounded-full",children:T("defaultAddress")})]}),e.jsx("p",{className:"text-sm text-gray-600 leading-snug break-words",children:s.address}),s.details&&e.jsxs("p",{className:"text-xs text-gray-400 mt-1",children:[s.details," ",s.gate_code&&`⢠${T("gateCodeLabel")} ${s.gate_code}`]})]}),e.jsx("div",{className:"absolute top-4 right-4",children:e.jsxs(y,{children:[e.jsx(b,{asChild:!0,children:e.jsx(l,{variant:"ghost",size:"icon",className:"h-8 w-8 text-gray-400 hover:text-gray-900",children:e.jsx(_,{className:"h-4 w-4"})})}),e.jsxs(w,{align:"end",children:[!s.is_default&&e.jsxs(k,{onClick:()=>(async e=>{try{await j(z.id,e),$(s=>s.map(s=>({...s,is_default:s.id===e}))),K({title:T("success"),description:T("defaultAddressUpdated")})}catch(s){K({title:T("errorOccurred"),description:T("operationFailed"),variant:"destructive"})}})(s.id),children:[e.jsx(D,{className:"h-4 w-4 mr-2"}
1)," ",T("setAsDefault")]}),e.jsxs(k,{onClick:()=>(e=>{J(e.id),Q({title:e.title,address:e.address,details:e.details||"",gate_code:e.gate_code||"",is_default:e.is_default}),q(G(e.title)),B(!0)})(s),children:[e.jsx(O,{className:"h-4 w-4 mr-2"})," ",T("edit")]}),e.jsxs(k,{onClick:()=>(async e=>{if(confirm(T("confirmDeleteAddress")))try{await p(e),$(s=>s.filter(s=>s.id!==e)),K({title:T("success"),description:T("addressDeleted")})}catch(s){K({title:T("errorOccurred"),description:T("deleteFailed"),variant:"destructive"})}})(s.id),className:"text-red-500 focus:text-red-500",children:[e.jsx(P,{className:"h-4 w-4 mr-2"})," ",T("delete")]})]})]})})]})},s.id)})}),e.jsx("div",{className:"fixed bottom-6 right-6 z-20",children:e.jsx(l,{onClick:()=>{J(null),Q({title:T("home"),address:"",details:"",gate_code:"",is_default:!1}),q("Home"),B(!0)},className:"h-14 w-14 rounded-full bg-orange-500 hover:bg-orange-600 shadow-lg flex items-center justify-center",children:e.jsx(S,{className:"h-6 w-6 text-white"})})}),e.jsx(i,{open:Y,onOpenChange:B,children:e.jsx(c,{className:"max-h-[85vh]",children:e.jsxs("div",{className:"mx-auto w-full max-w-sm flex flex-col max-h-[calc(85vh-2rem)] overflow-hidden",children:[e.jsx(o,{className:"shrink-0",children:e.jsx(n,{children:T(I?"editAddress":"addNewAddressTitle")})}),e.jsxs("div",{className:"p-4 space-y-6 overflow-y-auto flex-1",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(x,{children:T("addressType")}),e.jsx("div",{className:"flex gap-3",children:[{id:"Home",icon:F,label:T("home")},{id:"Work",icon:H,label:T("work")},{id:"Other",icon:A,label:T("otherType")}].map(s=>e.jsxs("button",{onClick:()=>{q(s.id),"Other"!==s.id?Q(e=>({...e,title:s.label})):Q(e=>({...e,title:""}))},className:"flex-1 flex flex-col items-center gap-2 p-3 rounded-xl border transition-all "+(R===s.id?"border-orange-500 bg-orange-50 text-orange-600":"border-gray-200 text-gray-500 hover:bg-gray-50"),children:[e.jsx(s.icon,{className:"h-5 w-5"}),e.jsx("span",{className:"text-xs font-medium",children:s.label})]},s.id))})]}),"Other"===R&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:T("addressLabel")}),e.jsx(m,{placeholder:T("addressLabelPlaceholder"),value:M.title,onChange:e=>Q(s=>({...s,title:e.target.value})),onKeyDown:e=>e.stopPropagation()})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:T("fullAddress")}),e.jsx("div",{className:"relative",children:e.jsx(N,{placeholder:T("fullAddressPlaceholder"),className:"min-h-[100px] resize-none",value:M.address,onChange:e=>Q(s=>({...s,address:e.target.value})),onKeyDown:e=>e.stopPropagation()})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:T("buildingApartment")}),e.jsx(m,{placeholder:T("buildingPlaceholder"),value:M.details,onChange:e=>Q(s=>({...s,details:e.target.value})),onKeyDown:e=>e.stopPropagation()})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:T("gateCode")}),e.jsx(m,{placeholder:T("gateCodePlaceholder"),value:M.gate_code,onChange:e=>Q(s=>({...s,gate_code:e.target.value})),onKeyDown:e=>e.stopPropagation()})]})]})]}),e.jsxs(h,{className:"pt-2 shrink-0",children:[e.jsx(l,{onClick:async()=>{if(!M.address)return void K({title:T("missingData"),description:T("enterAddress"),variant:"destructive"});let e=M.title;"Home"===R&&(e=T("home")),"Work"===R&&(e=T("work"));try{const s={...M,title:e};if(I){const e=await v(I,s);$(s=>s.map(s=>s.id===I?e:s)),K({title:T("success"),description:T("addressUpdated")})}else{const e=await f(z.id,s);$(s=>[e,...s]),K({title:T("success"),description:T("addressAdded")})}B(!1)}catch(s){K({title:T("errorOccurred"),description:T("saveFailed"),variant:"destructive"})}},className:"bg-orange-500 hover:bg-orange-600 h-12 text-lg",children:T("save")}),e.jsx(g,{asChild:!0,children:e.jsx(l,{variant:"outline",className:"h-12",children:T("cancelAction")})})]})]})})})]})}export{L 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.