PageSourceSearch

https://faf.co.ao/assets/Checkout-NYq5T5Bx.js

js faf.co.ao collected 2026-10-02 19:10:10 UTC 7,588 bytes, 1 lines download raw bytes

1import{y as E,r as N,z as F,j as e}from"./vendor-react-core-_0sZDOLQ.js";import{B as y,c as v,b}from"./index-j07E1qHv.js";import{I as c}from"./input-rti45mgP.js";import{L as i}from"./label-7HT5__eZ.js";import{T as P}from"./textarea-CHKzP3UK.js";import{C as d,b as h,c as p,a as m}from"./card-DHmBnTdH.js";import{R as k,a as I}from"./radio-group-Cr2lmstz.js";import{t as j}from"./index-CDqomOa1.js";import{f as L}from"./publicProducts-BGVf2oJm.js";import{e as O,_ as A,am as M,aN as R,aO as T}from"./vendor-lucide-Ddz0eB7N.js";import{m as $}from"./vendor-framer-motion-C1oRD-X5.js";import"./vendor-radix-CFmJ1img.js";import"./vendor-utils-BRu4i-LD.js";import"./vendor-supabase-Ca6cp8v2.js";function se(){const u=E(),[o,w]=N.useState([]),[_,C]=N.useState(!1),{register:t,handleSubmit:q,formState:{errors:l}}=F();N.useEffect(()=>{const s=localStorage.getItem("faf_cart");if(s)try{const r=L(JSON.parse(s));w(r),localStorage.setItem("faf_cart",JSON.stringify(r))}catch{localStorage.removeItem("faf_cart")}},[]);const x=o.reduce((s,r)=>s+r.price*r.quantity,0),z=async s=>{if(o.length===0){j.error("Carrinho vazio");return}C(!0);try{const r=`FAF-${Date.now()}`,S=await b.entities.Order.create({order_number:r,customer_name:s.name,customer_email:s.email,customer_phone:s.phone,items:o.map(a=>({product_id:a.id,product_name:a.name,quantity:a.quantity,size:a.size,price:a.price})),total_amount:x,status:"pending",payment_method:s.payment_method,shipping_address:{street:s.street,city:s.city,province:s.province,postal_code:s.postal_code},notes:s.notes});let n=null;try{n=await b.functions.invoke("multicaixaGenerateReference",{type:"order",entityId:S.id,amount:x,description:`Encomenda ${r}`})}catch(a){console.error("Não foi possível gerar a referência Multicaixa.",a)}await Promise.allSettled(o.map(a=>{const f=Number(a.stock??a.stock_quantity??0);return!a.id||f<=0?Promise.resolve():b.entities.Product.update(a.id,{stock:Math.max(0,f-a.quantity),stock_quantity:Math.max(0,f-a.quantity)})})),localStorage.removeItem("faf_cart");const g=(n==null?void 0:n.data)??n;g!=null&&g.success?j.success("Encomenda criada! Referência de pagamento gerada."):j.warning("Encomenda criada, mas a referência de pagamento está temporariamente indisponível."),u(v(`OrderConfirmation?id=${S.id}`))}catch(r){j.error("Erro ao criar encomenda"),console.error(r)}finally{C(!1)}};return o.length===0?e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(O,{className:"w-20 h-20 text-gray-300 mx-auto mb-4"}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-2",children:"Carrinho vazio"}),e.jsx("p",{className:"text-gray-600 mb-6",children:"Adicione produtos antes de finalizar"}),e.jsx(y,{onClick:()=>u(v("Shop")),className:"bg-red-600 hover:bg-red-700",children:"Ir para a Loja"})]})}):e.jsx("main",{className:"min-h-screen bg-gray-50 py-12",children:e.jsxs("div",{className:"container mx-auto px-4",children:[e.jsxs(y,{variant:"ghost",onClick:()=>u(v("Shop")),className:"mb-6",children:[e.jsx(A,{className:"w-4 h-4 mr-2"}),"Voltar à Loja"]}),e.jsxs($.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"max-w-6xl mx-auto",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 mb-8",children:"Finalizar Compra"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("form",{onSubmit:q(z),className:"space-y-6",children:[e.jsxs(d,{children:[e.jsx(h,{children:e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(M,{className:"w-5 h-5"}),"Dados Pessoais"]})}),e.jsxs(m,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(i,{htmlFor:"name",children:"Nome Completo *"}),e.jsx(c,{id:"name",...t("name",{required:!0}),className:l.name?"border-red-500":""})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(i,{htmlFor:"email",children:"Email *"}),e.jsx(c,{id:"email",type:"email",...t("email",{required:!0}),className:l.email?"border-red-500":""})]}),e.jsxs("div",{children:[e.jsx(i,{htmlFor:"phone",children:"Telefone *"}),e.jsx(c,{id:"phone",...t("phone",{required:!0}),className:l.phone?"border-red-500":""})]})]})]})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(R,{className:"w-5 h-5"}),"Morada de Entrega"]})}),e.jsxs(m,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(i,{htmlFor:"street",children:"Rua *"}),e.jsx(c,{id:"street",...t("street",{required:!0}),className:l.street?"border-red-500":""})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(i,{htmlFor:"city",children:"Cidade *"}),e.jsx(c,{id:"city",...t("city",{required:!0}),className:l.city?"border-red-500":""})]}),e.jsxs("div",{children:[e.jsx(i,{htmlFor:"province",children:"Província *"}),e.jsx(c,{id:"province",...t("province",{required:!0}),className:l.province?"border-red-500":""})]}),e.jsxs("div",{children:[e.jsx(i,{htmlFor:"postal_code",children:"Código Postal"}),e.jsx(c,{id:"postal_code",...t("postal_code")})]})]})]})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(T,{className:"w-5 h-5"}),"Método de Pagamento"]})}),e.jsx(m,{children:e.jsx(k,{defaultValue:"multicaixa",...t("payment_method"),children:e.jsxs("div",{className:"flex items-center space-x-2 border p-4 rounded-lg",children:[e.jsx(I,{value:"multicaixa",id:"multicaixa"}),e.jsxs(i,{htmlFor:"multicaixa",className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-semibold",children:"Multicaixa Express"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Pagamento por referência"})]})]})})})]}),e.jsx(d,{children:e.jsxs(m,{className:"pt-6",children:[e.jsx(i,{htmlFor:"notes",children:"Observações (opcional)"}),e.jsx(P,{id:"notes",...t("notes"),placeholder:"Instruções especiais de entrega...",rows:3})]})}),e.jsx(y,{type:"submit",disabled:_,className:"w-full bg-red-600 hover:bg-red-700",size:"lg",children:_?"A processar...":"Confirmar Encomenda"})]})}),e.jsx("div",{children:e.jsxs(d,{className:"sticky top-24",children:[e.jsx(h,{children:e.jsx(p,{children:"Resumo da Encomenda"})}),e.jsxs(m,{className:"space-y-4",children:[e.jsx("div",{className:"space-y-3",children:o.map(s=>e.jsxs("div",{className:"flex gap-3 text-sm",children:[e.jsx("div",{className:"w-16 h-16 bg-gray-100 rounded flex-shrink-0",children:s.image_url&&e.jsx("img",{src:s.image_url,alt:s.name,loading:"lazy",className:"w-full h-full object-cover rounded"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-semibold text-gray-900",children:s.name}),e.jsxs("p",{className:"text-gray-600",children:[s.size," • Qty: ",s.quantity]}),e.jsxs("p",{className:"font-bold text-red-600",children:[(s.price*s.quantity).toLocaleStr
1ing("pt-AO")," Kz"]})]})]},`${s.id}-${s.size}`))}),e.jsxs("div",{className:"border-t pt-4 space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:"Subtotal"}),e.jsxs("span",{children:[x.toLocaleString("pt-AO")," Kz"]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:"Entrega"}),e.jsx("span",{children:"Grátis"})]}),e.jsxs("div",{className:"flex justify-between text-lg font-bold pt-2 border-t",children:[e.jsx("span",{children:"Total"}),e.jsxs("span",{className:"text-red-600",children:[x.toLocaleString("pt-AO")," Kz"]})]})]})]})]})})]})]})]})})}export{se 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.