1import{j as e,bx as T,as as de,al as z,Q as me,I as ue,a8 as F,aB as V,bn as xe,t as W,ak as K,aP as H,b6 as pe}from"./ui-CQQ40jiu.js";import{r as t}from"./vendor-BlkMEHpz.js";import{B as A}from"./button-BbBEkwEI.js";import{I as h}from"./input-Bo1KXe1d.js";import{B as J}from"./badge-2CZja1NJ.js";import{g as he,b as fe}from"./index-1LJrDA3q.js";import"./supabase-BiuJTEsC.js";import"./forms-C-mJx-_F.js";const Y="catakana-guild:";function ke(){var q,D;const o=he(),{toast:d}=fe(),[c,f]=t.useState("search"),[g,N]=t.useState(""),[j,I]=t.useState(""),[y,m]=t.useState([]),[b,i]=t.useState(!1),[r,w]=t.useState(null),[l,Z]=t.useState(null),[B,x]=t.useState(""),[ee,R]=t.useState(!1),[n,se]=t.useState("xp"),[v,M]=t.useState("add"),[p,E]=t.useState(0),[O,Q]=t.useState(""),[P,te]=t.useState(""),[U,L]=t.useState(!1),[S,C]=t.useState(null),[$,ae]=t.useState([]),[k,G]=t.useState("");t.useState([]),t.useEffect(()=>{re()},[]);const re=async()=>{const{data:s}=await o.from("dictionary_items").select("item_code, item_name, item_type, rarity").order("item_name");s&&ae(s)},le=async s=>{if(s.length<2){m([]);return}i(!0);const{data:a}=await o.from("profiles").select("id, username, email, user_type, points").or(`username.ilike.%${s}%,email.ilike.%${s}%`).order("username").limit(15);m(a||[]),i(!1)},ne=async s=>{x(""),i(!0);const{data:a}=await o.from("profiles").select("id, username, email, user_type, points").eq("id",s).maybeSingle();i(!1),a?(_(a),R(!1)):x("Utilisateur introuvable")},X=async()=>{if(!j.trim())return;x(""),i(!0);const{data:s}=await o.from("profiles").select("id, username, email, user_type, points").ilike("email",j.trim()).maybeSingle();i(!1),s?_(s):x("Aucun compte trouvé avec cet email")},ce=s=>{let a="";if(s.startsWith(Y))a=s.replace(Y,"");else if(s.startsWith("catakana-combat:"))a=s.replace("catakana-combat:","");else{x("QR code non reconnu");return}ne(a)},_=async s=>{w(s),m([]),N(s.username),C(null);const{data:a}=await o.from("rpg_stats").select("user_id, coins, strength, magic, wisdom, rank").eq("user_id",s.id).maybeSingle();Z(a)},ie=async()=>{if(r){if(n!=="item"&&p<=0){d({title:"Montant invalide",variant:"destructive"});return}if(n==="item"&&!P){d({title:"Sélectionnez un objet",variant:"destructive"});return}L(!0),C(null);try{const{data:s,error:a}=await o.rpc("rpg_bank_operation",{p_user_id:r.id,p_operation:n==="item"?"add":v,p_type:n,p_amount:n==="item"?p||1:p,p_item_code:n==="item"?P:null,p_reason:O||null});if(a)throw a;const u=s;C(u),u.success?(d({title:u.message}),await _(r),E(0),Q("")):d({title:"Erreur",description:u.message,variant:"destructive"})}catch(s){C({success:!1,message:s.message}),d({title:"Erreur",description:s.message,variant:"destructive"})}finally{L(!1)}}},oe=t.useMemo(()=>{if(!k)return $.slice(0,20);const s=k.toLowerCase();return $.filter(a=>a.item_name.toLowerCase().includes(s)||a.item_code.toLowerCase().includes(s)).slice(0,20)},[$,k]);return e.jsxs("div",{className:"space-y-6 p-4 sm:p-6 overflow-auto max-h-full",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl sm:text-2xl font-bold flex items-center gap-2",children:[e.jsx(T,{className:"h-6 w-6 text-amber-500"}),"RPG Bank â Guilde"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Créditer ou soustraire XP, Pièces Catakana, ou ajouter des objets à un joueur"})]}),e.jsxs("div",{className:"border rounded-xl p-4 bg-card space-y-3",children:[e.jsxs("h3",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(de,{className:"h-4 w-4"})," Identifier un joueur"]}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{val:"search",label:"Recherche",icon:e.jsx(z,{className:"h-4 w-4"})},{val:"qr",label:"QR Code",icon:e.jsx(me,{className:"h-4 w-4"})},{val:"email",label:"Email",icon:e.jsx(ue,{className:"h-4 w-4"})}].map(s=>e.jsxs("button",{onClick:()=>{f(s.val),x(""),m([]),R(s.val==="qr")},className:`px-3 py-2 rounded-lg border text-sm font-medium flex items-center justify-center gap-1.5 transition-colors ${c===s.val?"border-purple-400 bg-purple-50 text-purple-700":"border-gray-200 text-gray-500 hover:border-gray-300"}`,children:[s.icon," ",s.label]},s.val))}),c==="search"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative",children:[e.jsx(z,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(h,{value:g,onChange:s=>{N(s.target.value),le(s.target.value),w(null)},placeholder:"Rechercher par nom ou email...",className:"pl-9"})]}),y.length>0&&e.jsx("div",{className:"border rounded-lg max-h-[200px] overflow-y-auto divide-y",children:y.map(s=>{var a,u;return e.jsxs("button",{onClick:()=>_(s),className:"w-full text-left px-3 py-2 hover:bg-muted/50 transition-colors flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-purple-500/20 flex items-center justify-center text-sm font-bold text-purple-600 shrink-0",children:((u=(a=s.username)==null?void 0:a[0])==null?void 0:u.toUpperCase())||"?"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:s.username}),e.jsxs("p",{className:"text-[11px] text-muted-foreground truncate",children:[s.email||"Pas d'email"," · ",s.user_t
1ype]})]}),e.jsxs(J,{variant:"outline",className:"text-[10px] shrink-0",children:[s.points," XP"]})]},s.id)})})]}),c==="qr"&&ee&&e.jsx(ge,{onScan:ce,onCancel:()=>R(!1)}),c==="email"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{value:j,onChange:s=>I(s.target.value),placeholder:"Entrez l'email du joueur...",type:"email",className:"flex-1",onKeyDown:s=>s.key==="Enter"&&X()}),e.jsx(A,{onClick:X,disabled:b,children:b?e.jsx(F,{className:"h-4 w-4 animate-spin"}):"Chercher"})]}),B&&e.jsxs("p",{className:"text-sm text-red-500 flex items-center gap-1",children:[e.jsx(V,{className:"h-3 w-3"})," ",B]}),b&&c==="search"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Recherche..."})]}),r&&e.jsxs("div",{className:"border rounded-xl p-4 bg-card space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 flex items-center justify-center text-white font-bold",children:((D=(q=r.username)==null?void 0:q[0])==null?void 0:D.toUpperCase())||"?"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold",children:r.username}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r.email})]})]}),e.jsxs("div",{className:"flex gap-4 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-bold text-purple-600",children:r.points}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"XP"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-bold text-amber-500",children:(l==null?void 0:l.coins)||0}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"PC"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-bold text-blue-500",children:(l==null?void 0:l.rank)||"F"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Rang"})]})]})]}),l&&e.jsxs("div",{className:"flex gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["STR ",l.strength]}),e.jsxs("span",{children:["MAG ",l.magic]}),e.jsxs("span",{children:["SAG ",l.wisdom]})]})]}),r&&e.jsxs("div",{className:"border rounded-xl p-4 bg-card space-y-4",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Opération"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{val:"xp",label:"XP",icon:e.jsx(xe,{className:"h-4 w-4"}),color:"purple"},{val:"coins",label:"Pièces",icon:e.jsx(T,{className:"h-4 w-4"}),color:"amber"},{val:"item",label:"Objet",icon:e.jsx(W,{className:"h-4 w-4"}),color:"blue"}].map(s=>e.jsxs("button",{onClick:()=>se(s.val),className:`px-3 py-2.5 rounded-lg border-2 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${n===s.val?`border-${s.color}-400 bg-${s.color}-50 text-${s.color}-700`:"border-gray-200 text-gray-500 hover:border-gray-300"}`,style:n===s.val?{borderColor:s.color==="purple"?"#a855f7":s.color==="amber"?"#f59e0b":"#3b82f6",background:s.color==="purple"?"#faf5ff":s.color==="amber"?"#fffbeb":"#eff6ff"}:{},children:[s.icon," ",s.label]},s.val))}),n!=="item"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex rounded-lg border overflow-hidden",children:[e.jsx("button",{onClick:()=>M("add"),className:`px-3 py-2 text-sm font-medium transition-colors ${v==="add"?"bg-green-500 text-white":"bg-white text-gray-500 hover:bg-gray-50"}`,children:e.jsx(K,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>M("remove"),className:`px-3 py-2 text-sm font-medium transition-colors ${v==="remove"?"bg-red-500 text-white":"bg-white text-gray-500 hover:bg-gray-50"}`,children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsx(h,{type:"number",value:p||"",onChange:s=>E(Math.max(0,parseInt(s.target.value)||0)),placeholder:"Montant",className:"flex-1",min:0})]}),n==="item"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{value:k,onChange:s=>G(s.target.value),placeholder:"Rechercher un objet..."}),e.jsx("div",{className:"border rounded-lg max-h-[180px] overflow-y-auto divide-y",children:oe.map(s=>e.jsxs("button",{onClick:()=>{te(s.item_code),G(s.item_name)},className:`w-full text-left px-3 py-2 text-sm hover:bg-muted/50 transition-colors flex items-center gap-2 ${P===s.item_code?"bg-purple-50 border-l-2 border-purple-500":""}`,children:[e.jsx("span",{className:"truncate flex-1",children:s.item_name}),s.rarity&&e.jsx(J,{variant:"outline",className:"text-[10px] shrink-0",children:s.rarity}),s.item_type&&e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:s.item_type})]},s.item_code))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Quantité :"}),e.jsx(h,{type:"number",value:p||1,onChange:s=>E(Math.max(1,parseInt(s.target.value)||1)),className:"w-20 h-7 text-sm",min:1})]})]}),e.jsx(h,{value:O,onChange:s=>Q(s.target.value),placeholder:"Raison (optionnel)"}),S&&e.jsxs("div",{className:`rounded-lg p-3 flex items-center gap-2 text-sm ${S.success?"bg-green-50 text-green-700 border border-green-200":"bg-red-50 text-red-700 border border-red-200"}`,children:[S.success?e.jsx(pe,{className:"h-4 w-4 shrink-0"}):e.jsx(V,{className:"h-4 w-4 shrink-0"}),S.message]}),e.jsxs(A,{onClick:ie,disabled:U,className:"w-full h-12 text-base",children:[U?e.jsx(F,{className:"h-5 w-5 animate-spin mr-2"}):n==="item"?e.jsx(W,{className:"h-5 w-5 mr-2"}):v==="add"?e.jsx(K,{className:"h-5 w-5 mr-2"}):e.jsx(H,{className:"h-5 w-5 mr-2"}),U?"Exécution...":n==="item"?"Ajouter l'objet":`${v==="add"?"Créditer":"Soustraire"} ${p} ${n==="xp"?"XP":"PC"}`]})]})]})}function ge({onScan:o,onCancel:d}){const c=t.useRef(null),f=t.useRef(null),g=t.useRef(null),[N,j]=t.useState(!1),[I,y]=t.useState(!1),m=t.useRef(!1);t.useEffect(()=>(b(),()=>i()),[]);const b=async()=>{try{const r=await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment",width:{ideal:640},height:{ideal:480}}});if(f.current=r,c.current&&(c.current.srcObject=r,await c.current.play()),j(!0),"BarcodeDetector"in window){const w=new window.BarcodeDetector({formats:["qr_code"]}
1);g.current=setInterval(async()=>{if(!(!c.current||m.current))try{const l=await w.detect(c.current);l.length>0&&l[0].rawValue&&(m.current=!0,i(),o(l[0].rawValue))}catch{}},200)}}catch{y(!0)}},i=()=>{g.current&&clearInterval(g.current),f.current&&f.current.getTracks().forEach(r=>r.stop())};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative rounded-lg overflow-hidden bg-black",children:[I?e.jsx("div",{className:"p-6 text-center text-gray-400 text-sm",children:"Caméra non disponible"}):e.jsx("video",{ref:c,muted:!0,playsInline:!0,className:"w-full max-h-[220px] object-cover"}),N&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:e.jsx("div",{className:"border-2 border-amber-400 rounded-lg w-[160px] h-[160px]"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Scannez le QR Code Guilde du joueur"}),e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{i(),d()},className:"w-full",children:"Annuler"})]})}export{ke 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.