PageSourceSearch

https://mohamedgrifesfb.lovable.app/assets/admin.produtos-QOOLd9YP.js

js mohamedgrifesfb.lovable.app collected 2026-10-03 03:33:44 UTC 9,163 bytes, 1 lines download raw bytes

1import{e as f,r as c,j as e,P as E,d as S,s as n,T as b,X as h,t as i,C as P}from"./index-q2pjMyd0.js";const T=[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]],A=f("camera",T);const M=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],D=f("pencil",M),$={id:"",nome:"",descricao:"",preco:"",preco_promocional:"",categoria_id:"",subcategoria_id:"",fotos:[],tamanhos:[],ativo:!0,esgotado:!1,destaque:!1};function L(){const[u,v]=c.useState([]),[m,j]=c.useState([]),[a,r]=c.useState(null),[N,p]=c.useState(!1),g=c.useRef(null),l=async()=>{const{data:o}=await n.from("produtos").select("id,nome,slug,preco,preco_promocional,fotos,ativo,esgotado,categoria_id").order("created_at",{ascending:!1});v(o??[]);const{data:s}=await n.from("categorias").select("id,nome,parent_id").order("ordem");j(s??[])};c.useEffect(()=>{l()},[]);const y=async o=>{if(!o||!o.length||!a)return;p(!0);const s=[];for(const d of Array.from(o)){const t=`${Date.now()}-${Math.random().toString(36).slice(2)}-${d.name}`,{error:x}=await n.storage.from("produtos").upload(t,d,{upsert:!1});if(x){i.error(x.message);continue}const{data:z}=n.storage.from("produtos").getPublicUrl(t);s.push(z.publicUrl)}r({...a,fotos:[...a.fotos,...s]}),p(!1)},_=async()=>{if(!a)return;if(!a.nome||!a.preco)return i.error("Nome e preço obrigatórios");const o={nome:a.nome,slug:P(a.nome)+"-"+Math.random().toString(36).slice(2,6),descricao:a.descricao||null,preco:Number(a.preco),preco_promocional:a.preco_promocional?Number(a.preco_promocional):null,categoria_id:a.categoria_id||null,subcategoria_id:a.subcategoria_id||null,fotos:a.fotos,tamanhos:a.tamanhos,ativo:a.ativo,esgotado:a.esgotado,destaque:a.destaque};if(a.id){delete o.slug;const{error:s}=await n.from("produtos").update(o).eq("id",a.id);if(s)return i.error(s.message)}else{const{error:s}=await n.from("produtos").insert(o);if(s)return i.error(s.message)}i.success("Produto salvo"),r(null),l()},k=async o=>{confirm("Excluir produto?")&&(await n.from("produtos").delete().eq("id",o),l())},C=m.filter(o=>!o.parent_id),w=m.filter(o=>o.parent_id===a?.categoria_id),q=()=>a&&r({...a,tamanhos:[...a.tamanhos,{tamanho:"",estoque:1}]});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h1",{className:"font-display text-3xl",children:"Produtos"}),e.jsxs("button",{onClick:()=>r({...$}),className:"px-4 py-2 rounded bg-gold text-gold-foreground font-bold text-sm inline-flex items-center gap-2",children:[e.jsx(E,{className:"size-4"})," Novo produto"]})]}),e.jsxs("div",{className:"grid gap-2",children:[u.map(o=>e.jsxs("div",{className:"bg-card border border-border rounded-lg p-3 flex items-center gap-3",children:[e.jsx("div",{className:"size-14 rounded bg-secondary overflow-hidden shrink-0",children:o.fotos?.[0]&&e.jsx("img",{src:o.fotos[0],className:"w-full h-full object-cover"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:o.nome}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[S(Number(o.preco))," ",o.esgotado&&"· ESGOTADO"," ",!o.ativo&&"· INATIVO"]})]}),e.jsx("button",{onClick:async()=>{const{data:s}=await n.from("produtos").select("*").eq("id",o.id).single();r({id:s.id,nome:s.nome,descricao:s.descricao??"",preco:String(s.preco),preco_promocional:s.preco_promocional?String(s.preco_promocional):"",categoria_id:s.categoria_id??"",subcategoria_id:s.subcategoria_id??"",fotos:s.fotos??[],tamanhos:s.tamanhos??[],ativo:s.ativo,esgotado:s.esgotado,destaque:s.destaque})},className:"p-2 hover:text-gold",children:e.jsx(D,{className:"size-4"})}),e.jsx("button",{onClick:()=>k(o.id),className:"p-2 text-destructive",children:e.jsx(b,{className:"size-4"})})]},o.id)),u.length===0&&e.jsx("p",{className:"text-muted-foreground",children:"Nenhum produto cadastrado."})]}),a&&e.jsx("div",{className:"fixed inset-0 z-50 bg-black/70 grid place-items-end md:place-items-center p-0 md:p-4 overflow-y-auto",children:e.jsxs("div",{className:"bg-background border border-border rounded-t-2xl md:rounded-2xl w-full max-w-2xl max-h-[95vh] overflow-y-auto",children:[e.jsxs("div",{className:"sticky top-0 bg-background border-b border-border p-4 flex items-center justify-between",children:[e.jsxs("h2",{className:"font-display text-xl",children:[a.id?"Editar":"Novo"," produto"]}),e.jsx("button",{onClick:()=>r(null),children:e.jsx(h,{className:"size-5"})})]}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx("input",{className:"w-full bg-input border border-border rounded px-3 py-2",placeholder:"Nome *",value:a.nome,onChange:o=>r({...a,nome:o.target.value})}),e.jsx("textarea",{className:"w-full bg-input border border-border rounded px-3 py-2",rows:3,placeholder:"Descrição",value:a.descricao,onChange:o=>r({...a,descricao:o.target.value})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{className:"bg-input border border-border rounded px-3 py-2",placeholder:"Preço *",type:"number",value:a.preco,onChange:o=>r({...a,preco:o.target.value})}),e.jsx("input",{className:"bg-input border border-border rounded px-3 py-2",placeholder:"Preço promocional",type:"number",value:a.preco_promocional,onCh
1ange:o=>r({...a,preco_promocional:o.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("select",{className:"bg-input border border-border rounded px-3 py-2",value:a.categoria_id,onChange:o=>r({...a,categoria_id:o.target.value,subcategoria_id:""}),children:[e.jsx("option",{value:"",children:"Categoria"}),C.map(o=>e.jsx("option",{value:o.id,children:o.nome},o.id))]}),e.jsxs("select",{className:"bg-input border border-border rounded px-3 py-2",value:a.subcategoria_id,onChange:o=>r({...a,subcategoria_id:o.target.value}),children:[e.jsx("option",{value:"",children:"Subcategoria"}),w.map(o=>e.jsx("option",{value:o.id,children:o.nome},o.id))]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"text-sm font-bold",children:"Fotos"}),e.jsxs("button",{onClick:()=>g.current?.click(),className:"px-3 py-1.5 rounded bg-gold text-gold-foreground text-xs font-bold inline-flex items-center gap-1",children:[e.jsx(A,{className:"size-3"})," ",N?"Enviando…":"Tirar/Enviar"]}),e.jsx("input",{ref:g,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:o=>y(o.target.files)})]}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:a.fotos.map((o,s)=>e.jsxs("div",{className:"relative aspect-square rounded overflow-hidden bg-secondary",children:[e.jsx("img",{src:o,className:"w-full h-full object-cover"}),e.jsx("button",{onClick:()=>r({...a,fotos:a.fotos.filter((d,t)=>t!==s)}),className:"absolute top-1 right-1 bg-destructive text-destructive-foreground size-5 rounded grid place-items-center",children:e.jsx(h,{className:"size-3"})})]},s))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"text-sm font-bold",children:"Tamanhos & estoque"}),e.jsx("button",{onClick:q,className:"text-xs text-gold",children:"+ adicionar"})]}),e.jsx("div",{className:"space-y-2",children:a.tamanhos.map((o,s)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:"flex-1 bg-input border border-border rounded px-3 py-2 text-sm",placeholder:"Tamanho (M, 40…)",value:o.tamanho,onChange:d=>{const t=[...a.tamanhos];t[s].tamanho=d.target.value,r({...a,tamanhos:t})}}),e.jsx("input",{className:"w-24 bg-input border border-border rounded px-3 py-2 text-sm",type:"number",placeholder:"Estoque",value:o.estoque,onChange:d=>{const t=[...a.tamanhos];t[s].estoque=Number(d.target.value),r({...a,tamanhos:t})}}),e.jsx("button",{onClick:()=>r({...a,tamanhos:a.tamanhos.filter((d,t)=>t!==s)}),className:"p-2 text-destructive",children:e.jsx(b,{className:"size-4"})})]},s))})]}),e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:a.ativo,onChange:o=>r({...a,ativo:o.target.checked})})," Ativo"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:a.esgotado,onChange:o=>r({...a,esgotado:o.target.checked})})," Esgotado"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:a.destaque,onChange:o=>r({...a,destaque:o.target.checked})})," Destaque"]})]})]}),e.jsxs("div",{className:"sticky bottom-0 bg-background border-t border-border p-4 flex gap-2",children:[e.jsx("button",{onClick:()=>r(null),className:"flex-1 py-2.5 rounded border border-border",children:"Cancelar"}),e.jsx("button",{onClick:_,className:"flex-1 py-2.5 rounded bg-gold text-gold-foreground font-bold",children:"Salvar"})]})]})})]})}export{L as component};

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.