58ca4e68db
- Go backend API with full CRUD for all modules (CRM, Sales, Finance, HR, Legal, Marketing, Support, Purchase, Inventory, Projects, Automation, Analytics) - Rust analytics service with parallel report generation - C runtime with POSIX shared memory IPC - PostgreSQL schema with 30+ tables, full migrations - Redis cache, sessions, pub/sub - Kafka event streaming with Zookeeper - WebSocket hub for real-time updates - Automation engine with cron jobs, workflows, event triggers - JWT authentication, multi-tenant from start - Docker Compose with all services - Nginx reverse proxy with rate limiting - Integration tests passing - Feature gap analysis against Fortnox/Odoo/Visma Refs: BOC-001
54 lines
78 KiB
JavaScript
54 lines
78 KiB
JavaScript
import{o as H,p as le,r as v,a8 as Be,w as T,z as K,j as e,x as I,y as P,v as L,ao as ce,ap as de,aq as ue,ar as me,a as fe,M as mt,af as ft,L as gt,q as Ie,c as Yt,e as Wt,as as Zt,P as ze,d as $t,at as en,H as tn,au as nn,av as sn,s as ht,I as pt,aw as V,C as rn,a1 as an,b as we,B as je,ax as on}from"./index-oAPVDf-r.js";import{S as X,D as ln,a as cn,b as dn,c as Ze,u as un,f as Ne,d as $e,M as ve,e as et,P as tt,g as mn}from"./dropdown-menu-CBJEO_Gg.js";import{B as Q}from"./badge-Qwi4CUXx.js";import{d as fn,T as nt}from"./differenceInDays-CJS5VaxB.js";import{G as xt}from"./gift-lxeNwCUB.js";import{C as gn}from"./circle-check-D3hjqUcb.js";import{C as se}from"./clock-DRtqJZUo.js";import{S as st,F as hn,C as pn,H as xn}from"./star-C6FiGbGr.js";import{Q as yn}from"./qr-code-BIBWO21n.js";import{f as _,s as Y,e as yt,d as bt}from"./sv-BZPVJm6C.js";import{A as wt}from"./index-B-MEeiYV.js";import{C as bn}from"./check-CG8zylH4.js";import{H as jt}from"./heart-BjLemQnU.js";import{L as wn}from"./leaf-DHbwTQEy.js";import{G as jn}from"./graduation-cap-Bk5l1TQx.js";import{C as De}from"./chevron-down-QDDHZwZg.js";import{E as Nn}from"./external-link-C86N9iPS.js";import{S as vn}from"./scroll-area-B0CEXZGH.js";import{I as kn}from"./info-BT66tWy0.js";import{F as rt}from"./file-text-CyDVAB5w.js";import{D as Cn}from"./download-B0vydl5E.js";import{S as Sn}from"./send-DsElwFaU.js";import{C as En}from"./calendar-Bof-SGwp.js";import{B as An}from"./building-2-w77rCUKE.js";import{T as Mn}from"./trending-up-Be0ZnpBQ.js";import{C as Tn}from"./circle-alert-C1Hs9zwh.js";import"./index-DGH-oZ97.js";import"./chevron-right-B9rMgght.js";import"./circle-030W8joh.js";/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const at=H("Banknote",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M6 12h.01M18 12h.01",key:"113zkx"}]]);/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const _n=H("CircleArrowDown",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 8v8",key:"napkw2"}],["path",{d:"m8 12 4 4 4-4",key:"k98ssh"}]]);/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const Bn=H("CircleArrowUp",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 12-4-4-4 4",key:"177agl"}],["path",{d:"M12 16V8",key:"1sbj14"}]]);/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const In=H("Droplets",[["path",{d:"M7 16.3c2.2 0 4-1.83 4-4.05 0-1.16-.57-2.26-1.71-3.19S7.29 6.75 7 5.3c-.29 1.45-1.14 2.84-2.29 3.76S3 11.1 3 12.25c0 2.22 1.8 4.05 4 4.05z",key:"1ptgy4"}],["path",{d:"M12.56 6.6A10.97 10.97 0 0 0 14 3.02c.5 2.5 2 4.9 4 6.5s3 3.5 3 5.5a6.98 6.98 0 0 1-11.91 4.97",key:"1sl1rz"}]]);/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const Dn=H("Facebook",[["path",{d:"M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z",key:"1jg4f8"}]]);/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const ot=H("Medal",[["path",{d:"M7.21 15 2.66 7.14a2 2 0 0 1 .13-2.2L4.4 2.8A2 2 0 0 1 6 2h12a2 2 0 0 1 1.6.8l1.6 2.14a2 2 0 0 1 .14 2.2L16.79 15",key:"143lza"}],["path",{d:"M11 12 5.12 2.2",key:"qhuxz6"}],["path",{d:"m13 12 5.88-9.8",key:"hbye0f"}],["path",{d:"M8 7h8",key:"i86dvs"}],["circle",{cx:"12",cy:"17",r:"5",key:"qbz8iq"}],["path",{d:"M12 18v-2h-.5",key:"fawc4q"}]]);/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const Nt=H("Receipt",[["path",{d:"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z",key:"q3az6g"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 17.5v-11",key:"1jc1ny"}]]);/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const Pn=H("Stethoscope",[["path",{d:"M11 2v2",key:"1539x4"}],["path",{d:"M5 2v2",key:"1yf1q8"}],["path",{d:"M5 3H4a2 2 0 0 0-2 2v4a6 6 0 0 0 12 0V5a2 2 0 0 0-2-2h-1",key:"rb5t3r"}],["path",{d:"M8 15a6 6 0 0 0 12 0v-3",key:"x18d4x"}],["circle",{cx:"20",cy:"10",r:"2",key:"ts1r5v"}]]);/**
|
||
* @license lucide-react v0.462.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const Rn=H("Utensils",[["path",{d:"M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2",key:"cjf0a3"}],["path",{d:"M7 2v20",key:"1473qp"}],["path",{d:"M21 15V2a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3Zm0 0v7",key:"j28e5"}]]),ke="https://api.quixzoom.com/api/qz",it=.15;function Ln(){const{user:t}=le(),[n,a]=v.useState([]),[s,o]=v.useState([]),[r,i]=v.useState(!0);return v.useEffect(()=>{if(!t){i(!1);return}async function d(){i(!0);const x=Be.getToken();if(!x){i(!1);return}try{const p=await fetch(`${ke}/payouts/history`,{headers:{Authorization:`Bearer ${x}`}});if(p.ok){const b=await p.json();a(b.payouts||[])}}catch(p){console.error("[usePayouts] fetchPayouts error:",p)}i(!1)}async function g(){try{const x=await fetch(`${ke}/payouts/currencies`);if(x.ok){const p=await x.json();o(p.currencies||[])}}catch(x){console.error("[usePayouts] fetchCurrencies error:",x)}}d(),g()},[t]),{payouts:n,isLoading:r,calculatePayout:d=>{const g=Math.round(d*it),x=d-g;return{taxAmount:g,netAmount:x}},requestPayout:async(d,g="SEK")=>{var p;if(!t)return T.error("Du måste vara inloggad"),!1;const x=Be.getToken();if(!x)return T.error("Ingen giltig session — logga in igen"),!1;if(d<100)return T.error("Minsta utbetalning är 100 credits"),!1;try{const b=await fetch(`${ke}/payouts/request`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${x}`},body:JSON.stringify({amount_credits:d,currency:g})}),j=await b.json();if(!b.ok)return b.status===400&&((p=j.error)!=null&&p.includes("Stripe Connect"))?(T.error("Utbetalningar kräver ett verifierat konto",{description:"Slutför onboarding via Inställningar → Utbetalningar för att aktivera Stripe Connect.",duration:6e3}),!1):(T.error(j.error||"Kunde inte skapa utbetalningsförfrågan"),!1);const h={id:j.payout_id||`tmp-${Date.now()}`,amount:d*100,tax_amount:(j.fee_credits||0)*100,net_amount:(j.net_credits||0)*100,status:j.status||"pending",reference:void 0,processed_at:null,created_at:new Date().toISOString()};a(m=>[h,...m]);const y=j.mode==="mock"?" (sandbox-läge)":"";return T.success(`Utbetalning initierad${y}`,{description:`${j.net_credits||0} credits → ${j.amount||""} ${j.currency||g} skickas till ditt konto.`}),!0}catch(b){return console.error("[usePayouts] requestPayout error:",b),T.error("Nätverksfel — försök igen"),!1}},TAX_RATE:it,currencies:s}}var $={},Fn=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},vt={},D={};let Ke;const Hn=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];D.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17};D.getSymbolTotalCodewords=function(n){return Hn[n]};D.getBCHDigit=function(t){let n=0;for(;t!==0;)n++,t>>>=1;return n};D.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');Ke=n};D.isKanjiModeEnabled=function(){return typeof Ke<"u"};D.toSJIS=function(n){return Ke(n)};var ge={};(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function n(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+a)}}t.isValid=function(s){return s&&typeof s.bit<"u"&&s.bit>=0&&s.bit<4},t.from=function(s,o){if(t.isValid(s))return s;try{return n(s)}catch{return o}}})(ge);function kt(){this.buffer=[],this.length=0}kt.prototype={get:function(t){const n=Math.floor(t/8);return(this.buffer[n]>>>7-t%8&1)===1},put:function(t,n){for(let a=0;a<n;a++)this.putBit((t>>>n-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),t&&(this.buffer[n]|=128>>>this.length%8),this.length++}};var Un=kt;function ee(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}ee.prototype.set=function(t,n,a,s){const o=t*this.size+n;this.data[o]=a,s&&(this.reservedBit[o]=!0)};ee.prototype.get=function(t,n){return this.data[t*this.size+n]};ee.prototype.xor=function(t,n,a){this.data[t*this.size+n]^=a};ee.prototype.isReserved=function(t,n){return this.reservedBit[t*this.size+n]};var zn=ee,Ct={};(function(t){const n=D.getSymbolSize;t.getRowColCoords=function(s){if(s===1)return[];const o=Math.floor(s/7)+2,r=n(s),i=r===145?26:Math.ceil((r-13)/(2*o-2))*2,l=[r-7];for(let c=1;c<o-1;c++)l[c]=l[c-1]-i;return l.push(6),l.reverse()},t.getPositions=function(s){const o=[],r=t.getRowColCoords(s),i=r.length;for(let l=0;l<i;l++)for(let c=0;c<i;c++)l===0&&c===0||l===0&&c===i-1||l===i-1&&c===0||o.push([r[l],r[c]]);return o}})(Ct);var St={};const Kn=D.getSymbolSize,lt=7;St.getPositions=function(n){const a=Kn(n);return[[0,0],[a-lt,0],[0,a-lt]]};var Et={};(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const n={N1:3,N2:3,N3:40,N4:10};t.isValid=function(o){return o!=null&&o!==""&&!isNaN(o)&&o>=0&&o<=7},t.from=function(o){return t.isValid(o)?parseInt(o,10):void 0},t.getPenaltyN1=function(o){const r=o.size;let i=0,l=0,c=0,f=null,d=null;for(let g=0;g<r;g++){l=c=0,f=d=null;for(let x=0;x<r;x++){let p=o.get(g,x);p===f?l++:(l>=5&&(i+=n.N1+(l-5)),f=p,l=1),p=o.get(x,g),p===d?c++:(c>=5&&(i+=n.N1+(c-5)),d=p,c=1)}l>=5&&(i+=n.N1+(l-5)),c>=5&&(i+=n.N1+(c-5))}return i},t.getPenaltyN2=function(o){const r=o.size;let i=0;for(let l=0;l<r-1;l++)for(let c=0;c<r-1;c++){const f=o.get(l,c)+o.get(l,c+1)+o.get(l+1,c)+o.get(l+1,c+1);(f===4||f===0)&&i++}return i*n.N2},t.getPenaltyN3=function(o){const r=o.size;let i=0,l=0,c=0;for(let f=0;f<r;f++){l=c=0;for(let d=0;d<r;d++)l=l<<1&2047|o.get(f,d),d>=10&&(l===1488||l===93)&&i++,c=c<<1&2047|o.get(d,f),d>=10&&(c===1488||c===93)&&i++}return i*n.N3},t.getPenaltyN4=function(o){let r=0;const i=o.data.length;for(let c=0;c<i;c++)r+=o.data[c];return Math.abs(Math.ceil(r*100/i/5)-10)*n.N4};function a(s,o,r){switch(s){case t.Patterns.PATTERN000:return(o+r)%2===0;case t.Patterns.PATTERN001:return o%2===0;case t.Patterns.PATTERN010:return r%3===0;case t.Patterns.PATTERN011:return(o+r)%3===0;case t.Patterns.PATTERN100:return(Math.floor(o/2)+Math.floor(r/3))%2===0;case t.Patterns.PATTERN101:return o*r%2+o*r%3===0;case t.Patterns.PATTERN110:return(o*r%2+o*r%3)%2===0;case t.Patterns.PATTERN111:return(o*r%3+(o+r)%2)%2===0;default:throw new Error("bad maskPattern:"+s)}}t.applyMask=function(o,r){const i=r.size;for(let l=0;l<i;l++)for(let c=0;c<i;c++)r.isReserved(c,l)||r.xor(c,l,a(o,c,l))},t.getBestMask=function(o,r){const i=Object.keys(t.Patterns).length;let l=0,c=1/0;for(let f=0;f<i;f++){r(f),t.applyMask(f,o);const d=t.getPenaltyN1(o)+t.getPenaltyN2(o)+t.getPenaltyN3(o)+t.getPenaltyN4(o);t.applyMask(f,o),d<c&&(c=d,l=f)}return l}})(Et);var he={};const U=ge,te=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],ne=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];he.getBlocksCount=function(n,a){switch(a){case U.L:return te[(n-1)*4+0];case U.M:return te[(n-1)*4+1];case U.Q:return te[(n-1)*4+2];case U.H:return te[(n-1)*4+3];default:return}};he.getTotalCodewordsCount=function(n,a){switch(a){case U.L:return ne[(n-1)*4+0];case U.M:return ne[(n-1)*4+1];case U.Q:return ne[(n-1)*4+2];case U.H:return ne[(n-1)*4+3];default:return}};var At={},pe={};const W=new Uint8Array(512),oe=new Uint8Array(256);(function(){let n=1;for(let a=0;a<255;a++)W[a]=n,oe[n]=a,n<<=1,n&256&&(n^=285);for(let a=255;a<512;a++)W[a]=W[a-255]})();pe.log=function(n){if(n<1)throw new Error("log("+n+")");return oe[n]};pe.exp=function(n){return W[n]};pe.mul=function(n,a){return n===0||a===0?0:W[oe[n]+oe[a]]};(function(t){const n=pe;t.mul=function(s,o){const r=new Uint8Array(s.length+o.length-1);for(let i=0;i<s.length;i++)for(let l=0;l<o.length;l++)r[i+l]^=n.mul(s[i],o[l]);return r},t.mod=function(s,o){let r=new Uint8Array(s);for(;r.length-o.length>=0;){const i=r[0];for(let c=0;c<o.length;c++)r[c]^=n.mul(o[c],i);let l=0;for(;l<r.length&&r[l]===0;)l++;r=r.slice(l)}return r},t.generateECPolynomial=function(s){let o=new Uint8Array([1]);for(let r=0;r<s;r++)o=t.mul(o,new Uint8Array([1,n.exp(r)]));return o}})(At);const Mt=At;function Ve(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}Ve.prototype.initialize=function(n){this.degree=n,this.genPoly=Mt.generateECPolynomial(this.degree)};Ve.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const a=new Uint8Array(n.length+this.degree);a.set(n);const s=Mt.mod(a,this.genPoly),o=this.degree-s.length;if(o>0){const r=new Uint8Array(this.degree);return r.set(s,o),r}return s};var Vn=Ve,Tt={},z={},Oe={};Oe.isValid=function(n){return!isNaN(n)&&n>=1&&n<=40};var F={};const _t="[0-9]+",On="[A-Z $%*+\\-./:]+";let Z="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Z=Z.replace(/u/g,"\\u");const qn="(?:(?![A-Z0-9 $%*+\\-./:]|"+Z+`)(?:.|[\r
|
||
]))+`;F.KANJI=new RegExp(Z,"g");F.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");F.BYTE=new RegExp(qn,"g");F.NUMERIC=new RegExp(_t,"g");F.ALPHANUMERIC=new RegExp(On,"g");const Gn=new RegExp("^"+Z+"$"),Jn=new RegExp("^"+_t+"$"),Xn=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");F.testKanji=function(n){return Gn.test(n)};F.testNumeric=function(n){return Jn.test(n)};F.testAlphanumeric=function(n){return Xn.test(n)};(function(t){const n=Oe,a=F;t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(r,i){if(!r.ccBits)throw new Error("Invalid mode: "+r);if(!n.isValid(i))throw new Error("Invalid version: "+i);return i>=1&&i<10?r.ccBits[0]:i<27?r.ccBits[1]:r.ccBits[2]},t.getBestModeForData=function(r){return a.testNumeric(r)?t.NUMERIC:a.testAlphanumeric(r)?t.ALPHANUMERIC:a.testKanji(r)?t.KANJI:t.BYTE},t.toString=function(r){if(r&&r.id)return r.id;throw new Error("Invalid mode")},t.isValid=function(r){return r&&r.bit&&r.ccBits};function s(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+o)}}t.from=function(r,i){if(t.isValid(r))return r;try{return s(r)}catch{return i}}})(z);(function(t){const n=D,a=he,s=ge,o=z,r=Oe,i=7973,l=n.getBCHDigit(i);function c(x,p,b){for(let j=1;j<=40;j++)if(p<=t.getCapacity(j,b,x))return j}function f(x,p){return o.getCharCountIndicator(x,p)+4}function d(x,p){let b=0;return x.forEach(function(j){const h=f(j.mode,p);b+=h+j.getBitsLength()}),b}function g(x,p){for(let b=1;b<=40;b++)if(d(x,b)<=t.getCapacity(b,p,o.MIXED))return b}t.from=function(p,b){return r.isValid(p)?parseInt(p,10):b},t.getCapacity=function(p,b,j){if(!r.isValid(p))throw new Error("Invalid QR Code version");typeof j>"u"&&(j=o.BYTE);const h=n.getSymbolTotalCodewords(p),y=a.getTotalCodewordsCount(p,b),m=(h-y)*8;if(j===o.MIXED)return m;const u=m-f(j,p);switch(j){case o.NUMERIC:return Math.floor(u/10*3);case o.ALPHANUMERIC:return Math.floor(u/11*2);case o.KANJI:return Math.floor(u/13);case o.BYTE:default:return Math.floor(u/8)}},t.getBestVersionForData=function(p,b){let j;const h=s.from(b,s.M);if(Array.isArray(p)){if(p.length>1)return g(p,h);if(p.length===0)return 1;j=p[0]}else j=p;return c(j.mode,j.getLength(),h)},t.getEncodedBits=function(p){if(!r.isValid(p)||p<7)throw new Error("Invalid QR Code version");let b=p<<12;for(;n.getBCHDigit(b)-l>=0;)b^=i<<n.getBCHDigit(b)-l;return p<<12|b}})(Tt);var Bt={};const Pe=D,It=1335,Qn=21522,ct=Pe.getBCHDigit(It);Bt.getEncodedBits=function(n,a){const s=n.bit<<3|a;let o=s<<10;for(;Pe.getBCHDigit(o)-ct>=0;)o^=It<<Pe.getBCHDigit(o)-ct;return(s<<10|o)^Qn};var Dt={};const Yn=z;function O(t){this.mode=Yn.NUMERIC,this.data=t.toString()}O.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)};O.prototype.getLength=function(){return this.data.length};O.prototype.getBitsLength=function(){return O.getBitsLength(this.data.length)};O.prototype.write=function(n){let a,s,o;for(a=0;a+3<=this.data.length;a+=3)s=this.data.substr(a,3),o=parseInt(s,10),n.put(o,10);const r=this.data.length-a;r>0&&(s=this.data.substr(a),o=parseInt(s,10),n.put(o,r*3+1))};var Wn=O;const Zn=z,Ce=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function q(t){this.mode=Zn.ALPHANUMERIC,this.data=t}q.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)};q.prototype.getLength=function(){return this.data.length};q.prototype.getBitsLength=function(){return q.getBitsLength(this.data.length)};q.prototype.write=function(n){let a;for(a=0;a+2<=this.data.length;a+=2){let s=Ce.indexOf(this.data[a])*45;s+=Ce.indexOf(this.data[a+1]),n.put(s,11)}this.data.length%2&&n.put(Ce.indexOf(this.data[a]),6)};var $n=q;const es=z;function G(t){this.mode=es.BYTE,typeof t=="string"?this.data=new TextEncoder().encode(t):this.data=new Uint8Array(t)}G.getBitsLength=function(n){return n*8};G.prototype.getLength=function(){return this.data.length};G.prototype.getBitsLength=function(){return G.getBitsLength(this.data.length)};G.prototype.write=function(t){for(let n=0,a=this.data.length;n<a;n++)t.put(this.data[n],8)};var ts=G;const ns=z,ss=D;function J(t){this.mode=ns.KANJI,this.data=t}J.getBitsLength=function(n){return n*13};J.prototype.getLength=function(){return this.data.length};J.prototype.getBitsLength=function(){return J.getBitsLength(this.data.length)};J.prototype.write=function(t){let n;for(n=0;n<this.data.length;n++){let a=ss.toSJIS(this.data[n]);if(a>=33088&&a<=40956)a-=33088;else if(a>=57408&&a<=60351)a-=49472;else throw new Error("Invalid SJIS character: "+this.data[n]+`
|
||
Make sure your charset is UTF-8`);a=(a>>>8&255)*192+(a&255),t.put(a,13)}};var rs=J,Pt={exports:{}};(function(t){var n={single_source_shortest_paths:function(a,s,o){var r={},i={};i[s]=0;var l=n.PriorityQueue.make();l.push(s,0);for(var c,f,d,g,x,p,b,j,h;!l.empty();){c=l.pop(),f=c.value,g=c.cost,x=a[f]||{};for(d in x)x.hasOwnProperty(d)&&(p=x[d],b=g+p,j=i[d],h=typeof i[d]>"u",(h||j>b)&&(i[d]=b,l.push(d,b),r[d]=f))}if(typeof o<"u"&&typeof i[o]>"u"){var y=["Could not find a path from ",s," to ",o,"."].join("");throw new Error(y)}return r},extract_shortest_path_from_predecessor_list:function(a,s){for(var o=[],r=s;r;)o.push(r),a[r],r=a[r];return o.reverse(),o},find_path:function(a,s,o){var r=n.single_source_shortest_paths(a,s,o);return n.extract_shortest_path_from_predecessor_list(r,o)},PriorityQueue:{make:function(a){var s=n.PriorityQueue,o={},r;a=a||{};for(r in s)s.hasOwnProperty(r)&&(o[r]=s[r]);return o.queue=[],o.sorter=a.sorter||s.default_sorter,o},default_sorter:function(a,s){return a.cost-s.cost},push:function(a,s){var o={value:a,cost:s};this.queue.push(o),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=n})(Pt);var as=Pt.exports;(function(t){const n=z,a=Wn,s=$n,o=ts,r=rs,i=F,l=D,c=as;function f(y){return unescape(encodeURIComponent(y)).length}function d(y,m,u){const w=[];let C;for(;(C=y.exec(u))!==null;)w.push({data:C[0],index:C.index,mode:m,length:C[0].length});return w}function g(y){const m=d(i.NUMERIC,n.NUMERIC,y),u=d(i.ALPHANUMERIC,n.ALPHANUMERIC,y);let w,C;return l.isKanjiModeEnabled()?(w=d(i.BYTE,n.BYTE,y),C=d(i.KANJI,n.KANJI,y)):(w=d(i.BYTE_KANJI,n.BYTE,y),C=[]),m.concat(u,w,C).sort(function(S,M){return S.index-M.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function x(y,m){switch(m){case n.NUMERIC:return a.getBitsLength(y);case n.ALPHANUMERIC:return s.getBitsLength(y);case n.KANJI:return r.getBitsLength(y);case n.BYTE:return o.getBitsLength(y)}}function p(y){return y.reduce(function(m,u){const w=m.length-1>=0?m[m.length-1]:null;return w&&w.mode===u.mode?(m[m.length-1].data+=u.data,m):(m.push(u),m)},[])}function b(y){const m=[];for(let u=0;u<y.length;u++){const w=y[u];switch(w.mode){case n.NUMERIC:m.push([w,{data:w.data,mode:n.ALPHANUMERIC,length:w.length},{data:w.data,mode:n.BYTE,length:w.length}]);break;case n.ALPHANUMERIC:m.push([w,{data:w.data,mode:n.BYTE,length:w.length}]);break;case n.KANJI:m.push([w,{data:w.data,mode:n.BYTE,length:f(w.data)}]);break;case n.BYTE:m.push([{data:w.data,mode:n.BYTE,length:f(w.data)}])}}return m}function j(y,m){const u={},w={start:{}};let C=["start"];for(let k=0;k<y.length;k++){const S=y[k],M=[];for(let N=0;N<S.length;N++){const A=S[N],E=""+k+N;M.push(E),u[E]={node:A,lastCount:0},w[E]={};for(let R=0;R<C.length;R++){const B=C[R];u[B]&&u[B].node.mode===A.mode?(w[B][E]=x(u[B].lastCount+A.length,A.mode)-x(u[B].lastCount,A.mode),u[B].lastCount+=A.length):(u[B]&&(u[B].lastCount=A.length),w[B][E]=x(A.length,A.mode)+4+n.getCharCountIndicator(A.mode,m))}}C=M}for(let k=0;k<C.length;k++)w[C[k]].end=0;return{map:w,table:u}}function h(y,m){let u;const w=n.getBestModeForData(y);if(u=n.from(m,w),u!==n.BYTE&&u.bit<w.bit)throw new Error('"'+y+'" cannot be encoded with mode '+n.toString(u)+`.
|
||
Suggested mode is: `+n.toString(w));switch(u===n.KANJI&&!l.isKanjiModeEnabled()&&(u=n.BYTE),u){case n.NUMERIC:return new a(y);case n.ALPHANUMERIC:return new s(y);case n.KANJI:return new r(y);case n.BYTE:return new o(y)}}t.fromArray=function(m){return m.reduce(function(u,w){return typeof w=="string"?u.push(h(w,null)):w.data&&u.push(h(w.data,w.mode)),u},[])},t.fromString=function(m,u){const w=g(m,l.isKanjiModeEnabled()),C=b(w),k=j(C,u),S=c.find_path(k.map,"start","end"),M=[];for(let N=1;N<S.length-1;N++)M.push(k.table[S[N]].node);return t.fromArray(p(M))},t.rawSplit=function(m){return t.fromArray(g(m,l.isKanjiModeEnabled()))}})(Dt);const xe=D,Se=ge,os=Un,is=zn,ls=Ct,cs=St,Re=Et,Le=he,ds=Vn,ie=Tt,us=Bt,ms=z,Ee=Dt;function fs(t,n){const a=t.size,s=cs.getPositions(n);for(let o=0;o<s.length;o++){const r=s[o][0],i=s[o][1];for(let l=-1;l<=7;l++)if(!(r+l<=-1||a<=r+l))for(let c=-1;c<=7;c++)i+c<=-1||a<=i+c||(l>=0&&l<=6&&(c===0||c===6)||c>=0&&c<=6&&(l===0||l===6)||l>=2&&l<=4&&c>=2&&c<=4?t.set(r+l,i+c,!0,!0):t.set(r+l,i+c,!1,!0))}}function gs(t){const n=t.size;for(let a=8;a<n-8;a++){const s=a%2===0;t.set(a,6,s,!0),t.set(6,a,s,!0)}}function hs(t,n){const a=ls.getPositions(n);for(let s=0;s<a.length;s++){const o=a[s][0],r=a[s][1];for(let i=-2;i<=2;i++)for(let l=-2;l<=2;l++)i===-2||i===2||l===-2||l===2||i===0&&l===0?t.set(o+i,r+l,!0,!0):t.set(o+i,r+l,!1,!0)}}function ps(t,n){const a=t.size,s=ie.getEncodedBits(n);let o,r,i;for(let l=0;l<18;l++)o=Math.floor(l/3),r=l%3+a-8-3,i=(s>>l&1)===1,t.set(o,r,i,!0),t.set(r,o,i,!0)}function Ae(t,n,a){const s=t.size,o=us.getEncodedBits(n,a);let r,i;for(r=0;r<15;r++)i=(o>>r&1)===1,r<6?t.set(r,8,i,!0):r<8?t.set(r+1,8,i,!0):t.set(s-15+r,8,i,!0),r<8?t.set(8,s-r-1,i,!0):r<9?t.set(8,15-r-1+1,i,!0):t.set(8,15-r-1,i,!0);t.set(s-8,8,1,!0)}function xs(t,n){const a=t.size;let s=-1,o=a-1,r=7,i=0;for(let l=a-1;l>0;l-=2)for(l===6&&l--;;){for(let c=0;c<2;c++)if(!t.isReserved(o,l-c)){let f=!1;i<n.length&&(f=(n[i]>>>r&1)===1),t.set(o,l-c,f),r--,r===-1&&(i++,r=7)}if(o+=s,o<0||a<=o){o-=s,s=-s;break}}}function ys(t,n,a){const s=new os;a.forEach(function(c){s.put(c.mode.bit,4),s.put(c.getLength(),ms.getCharCountIndicator(c.mode,t)),c.write(s)});const o=xe.getSymbolTotalCodewords(t),r=Le.getTotalCodewordsCount(t,n),i=(o-r)*8;for(s.getLengthInBits()+4<=i&&s.put(0,4);s.getLengthInBits()%8!==0;)s.putBit(0);const l=(i-s.getLengthInBits())/8;for(let c=0;c<l;c++)s.put(c%2?17:236,8);return bs(s,t,n)}function bs(t,n,a){const s=xe.getSymbolTotalCodewords(n),o=Le.getTotalCodewordsCount(n,a),r=s-o,i=Le.getBlocksCount(n,a),l=s%i,c=i-l,f=Math.floor(s/i),d=Math.floor(r/i),g=d+1,x=f-d,p=new ds(x);let b=0;const j=new Array(i),h=new Array(i);let y=0;const m=new Uint8Array(t.buffer);for(let S=0;S<i;S++){const M=S<c?d:g;j[S]=m.slice(b,b+M),h[S]=p.encode(j[S]),b+=M,y=Math.max(y,M)}const u=new Uint8Array(s);let w=0,C,k;for(C=0;C<y;C++)for(k=0;k<i;k++)C<j[k].length&&(u[w++]=j[k][C]);for(C=0;C<x;C++)for(k=0;k<i;k++)u[w++]=h[k][C];return u}function ws(t,n,a,s){let o;if(Array.isArray(t))o=Ee.fromArray(t);else if(typeof t=="string"){let f=n;if(!f){const d=Ee.rawSplit(t);f=ie.getBestVersionForData(d,a)}o=Ee.fromString(t,f||40)}else throw new Error("Invalid data");const r=ie.getBestVersionForData(o,a);if(!r)throw new Error("The amount of data is too big to be stored in a QR Code");if(!n)n=r;else if(n<r)throw new Error(`
|
||
The chosen QR Code version cannot contain this amount of data.
|
||
Minimum version required to store current data is: `+r+`.
|
||
`);const i=ys(n,a,o),l=xe.getSymbolSize(n),c=new is(l);return fs(c,n),gs(c),hs(c,n),Ae(c,a,0),n>=7&&ps(c,n),xs(c,i),isNaN(s)&&(s=Re.getBestMask(c,Ae.bind(null,c,a))),Re.applyMask(s,c),Ae(c,a,s),{modules:c,version:n,errorCorrectionLevel:a,maskPattern:s,segments:o}}vt.create=function(n,a){if(typeof n>"u"||n==="")throw new Error("No input text");let s=Se.M,o,r;return typeof a<"u"&&(s=Se.from(a.errorCorrectionLevel,Se.M),o=ie.from(a.version),r=Re.from(a.maskPattern),a.toSJISFunc&&xe.setToSJISFunction(a.toSJISFunc)),ws(n,o,s,r)};var Rt={},qe={};(function(t){function n(a){if(typeof a=="number"&&(a=a.toString()),typeof a!="string")throw new Error("Color should be defined as hex string");let s=a.slice().replace("#","").split("");if(s.length<3||s.length===5||s.length>8)throw new Error("Invalid hex color: "+a);(s.length===3||s.length===4)&&(s=Array.prototype.concat.apply([],s.map(function(r){return[r,r]}))),s.length===6&&s.push("F","F");const o=parseInt(s.join(""),16);return{r:o>>24&255,g:o>>16&255,b:o>>8&255,a:o&255,hex:"#"+s.slice(0,6).join("")}}t.getOptions=function(s){s||(s={}),s.color||(s.color={});const o=typeof s.margin>"u"||s.margin===null||s.margin<0?4:s.margin,r=s.width&&s.width>=21?s.width:void 0,i=s.scale||4;return{width:r,scale:r?4:i,margin:o,color:{dark:n(s.color.dark||"#000000ff"),light:n(s.color.light||"#ffffffff")},type:s.type,rendererOpts:s.rendererOpts||{}}},t.getScale=function(s,o){return o.width&&o.width>=s+o.margin*2?o.width/(s+o.margin*2):o.scale},t.getImageWidth=function(s,o){const r=t.getScale(s,o);return Math.floor((s+o.margin*2)*r)},t.qrToImageData=function(s,o,r){const i=o.modules.size,l=o.modules.data,c=t.getScale(i,r),f=Math.floor((i+r.margin*2)*c),d=r.margin*c,g=[r.color.light,r.color.dark];for(let x=0;x<f;x++)for(let p=0;p<f;p++){let b=(x*f+p)*4,j=r.color.light;if(x>=d&&p>=d&&x<f-d&&p<f-d){const h=Math.floor((x-d)/c),y=Math.floor((p-d)/c);j=g[l[h*i+y]?1:0]}s[b++]=j.r,s[b++]=j.g,s[b++]=j.b,s[b]=j.a}}})(qe);(function(t){const n=qe;function a(o,r,i){o.clearRect(0,0,r.width,r.height),r.style||(r.style={}),r.height=i,r.width=i,r.style.height=i+"px",r.style.width=i+"px"}function s(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(r,i,l){let c=l,f=i;typeof c>"u"&&(!i||!i.getContext)&&(c=i,i=void 0),i||(f=s()),c=n.getOptions(c);const d=n.getImageWidth(r.modules.size,c),g=f.getContext("2d"),x=g.createImageData(d,d);return n.qrToImageData(x.data,r,c),a(g,f,d),g.putImageData(x,0,0),f},t.renderToDataURL=function(r,i,l){let c=l;typeof c>"u"&&(!i||!i.getContext)&&(c=i,i=void 0),c||(c={});const f=t.render(r,i,c),d=c.type||"image/png",g=c.rendererOpts||{};return f.toDataURL(d,g.quality)}})(Rt);var Lt={};const js=qe;function dt(t,n){const a=t.a/255,s=n+'="'+t.hex+'"';return a<1?s+" "+n+'-opacity="'+a.toFixed(2).slice(1)+'"':s}function Me(t,n,a){let s=t+n;return typeof a<"u"&&(s+=" "+a),s}function Ns(t,n,a){let s="",o=0,r=!1,i=0;for(let l=0;l<t.length;l++){const c=Math.floor(l%n),f=Math.floor(l/n);!c&&!r&&(r=!0),t[l]?(i++,l>0&&c>0&&t[l-1]||(s+=r?Me("M",c+a,.5+f+a):Me("m",o,0),o=0,r=!1),c+1<n&&t[l+1]||(s+=Me("h",i),i=0)):o++}return s}Lt.render=function(n,a,s){const o=js.getOptions(a),r=n.modules.size,i=n.modules.data,l=r+o.margin*2,c=o.color.light.a?"<path "+dt(o.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",f="<path "+dt(o.color.dark,"stroke")+' d="'+Ns(i,r,o.margin)+'"/>',d='viewBox="0 0 '+l+" "+l+'"',x='<svg xmlns="http://www.w3.org/2000/svg" '+(o.width?'width="'+o.width+'" height="'+o.width+'" ':"")+d+' shape-rendering="crispEdges">'+c+f+`</svg>
|
||
`;return typeof s=="function"&&s(null,x),x};const vs=Fn,Fe=vt,Ft=Rt,ks=Lt;function Ge(t,n,a,s,o){const r=[].slice.call(arguments,1),i=r.length,l=typeof r[i-1]=="function";if(!l&&!vs())throw new Error("Callback required as last argument");if(l){if(i<2)throw new Error("Too few arguments provided");i===2?(o=a,a=n,n=s=void 0):i===3&&(n.getContext&&typeof o>"u"?(o=s,s=void 0):(o=s,s=a,a=n,n=void 0))}else{if(i<1)throw new Error("Too few arguments provided");return i===1?(a=n,n=s=void 0):i===2&&!n.getContext&&(s=a,a=n,n=void 0),new Promise(function(c,f){try{const d=Fe.create(a,s);c(t(d,n,s))}catch(d){f(d)}})}try{const c=Fe.create(a,s);o(null,t(c,n,s))}catch(c){o(c)}}$.create=Fe.create;$.toCanvas=Ge.bind(null,Ft.render);$.toDataURL=Ge.bind(null,Ft.renderToDataURL);$.toString=Ge.bind(null,function(t,n,a){return ks.render(t,a)});function Ht(){const{user:t}=le(),[n,a]=v.useState([]),[s,o]=v.useState(!0),r=v.useCallback(async()=>{if(!t){o(!1);return}o(!0);try{const{data:d,error:g}=await K.from("vouchers").select("*").eq("user_id",t.id).order("issued_at",{ascending:!1});if(g)throw g;a(d||[])}catch(d){console.error("[useVouchers]",d)}finally{o(!1)}},[t]);v.useEffect(()=>{r()},[r]);const i=v.useCallback(async d=>{const g=JSON.stringify({id:d.id,code:d.code,title:d.title,brand:d.orderer_brand,expires:d.expires_at});return $.toDataURL(g,{width:256,margin:2})},[]),l=n.filter(d=>d.status==="active"&&new Date(d.expires_at)>new Date),c=n.filter(d=>d.status==="redeemed"||d.status==="expired"),f=l.filter(d=>(new Date(d.expires_at).getTime()-Date.now())/864e5<=7);return{vouchers:n,activeVouchers:l,usedVouchers:c,expiresWithin7Days:f,isLoading:s,fetchVouchers:r,getQRDataUrl:i}}function ut({voucher:t}){const[n,a]=v.useState(!1),[s,o]=v.useState(null),[r,i]=v.useState(!1),{getQRDataUrl:l}=Ht(),c=fn(new Date(t.expires_at),new Date),f=c<=7&&t.status==="active",d=t.status==="expired"||new Date(t.expires_at)<new Date,g=t.status==="redeemed",x=async()=>{i(!0);const b=await l(t);o(b),i(!1),a(!0)},p=g||d?"bg-muted":f?"border-amber-500/50 bg-amber-500/5":"border-primary/30 bg-primary/5";return e.jsxs(e.Fragment,{children:[e.jsx(I,{className:`overflow-hidden ${p}`,children:e.jsxs(P,{className:"p-0",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.orderer_logo_url?e.jsx("img",{src:t.orderer_logo_url,alt:t.orderer_brand||"",className:"w-10 h-10 rounded-lg object-contain bg-white p-1"}):e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(xt,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",children:t.orderer_brand||"QuiXzoom Reward"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.reward_type==="points"?"Poäng":"Värdekupong"})]})]}),g&&e.jsxs(Q,{variant:"secondary",children:[e.jsx(gn,{className:"w-3 h-3 mr-1"}),"Inlöst"]}),d&&!g&&e.jsx(Q,{variant:"secondary",children:"Utgången"}),!g&&!d&&f&&e.jsxs(Q,{className:"bg-amber-500 text-white",children:[e.jsx(se,{className:"w-3 h-3 mr-1"}),c,"d kvar"]}),!g&&!d&&!f&&e.jsxs(Q,{variant:"outline",className:"border-green-500 text-green-600",children:[c,"d kvar"]})]}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:`font-semibold ${g||d?"text-muted-foreground":""}`,children:t.title}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:t.description})]}),t.value_nominal&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(st,{className:"w-4 h-4 text-amber-500"}),e.jsxs("span",{className:"font-bold text-lg",children:[t.value_nominal," kr"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"nominellt värde"})]}),t.points&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(st,{className:"w-4 h-4 text-primary"}),e.jsxs("span",{className:"font-bold text-lg",children:[t.points," poäng"]})]}),t.redemption_instructions&&e.jsxs("p",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-2",children:["💡 ",t.redemption_instructions]}),!g&&!d&&e.jsxs(L,{onClick:x,disabled:r,className:"w-full",size:"sm",children:[e.jsx(yn,{className:"w-4 h-4 mr-2"}),r?"Genererar QR...":"Visa QR-kod för inlösning"]}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:g?`Inlöst ${_(new Date(t.redeemed_at),"d MMM yyyy",{locale:Y})}`:`Utgår ${_(new Date(t.expires_at),"d MMM yyyy",{locale:Y})}`})]})]})}),e.jsx(ce,{open:n,onOpenChange:a,children:e.jsxs(de,{className:"max-w-sm",children:[e.jsx(ue,{children:e.jsx(me,{children:"Visa för kassan"})}),e.jsxs("div",{className:"flex flex-col items-center gap-4 py-4",children:[s&&e.jsx("img",{src:s,alt:"QR-kod",className:"w-64 h-64 rounded-xl"}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-semibold",children:t.title}),t.orderer_brand&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.orderer_brand})]}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:["Kod: ",e.jsx("span",{className:"font-mono",children:t.code}),e.jsx("br",{}),"Giltigt t.o.m. ",_(new Date(t.expires_at),"d MMMM yyyy",{locale:Y})]})]})]})})]})}const Cs="https://api.quixzoom.com/api/qz";async function Ss(t="month",n="world",a=15){try{const s=new URLSearchParams({period:t,scope:n,limit:String(a)}),o=await fetch(`${Cs}/missions/leaderboard?${s.toString()}`);return o.ok?(await o.json()).leaderboard??[]:(console.warn("[leaderboard-api] fetch failed:",o.status),[])}catch(s){return console.error("[leaderboard-api] error:",s),[]}}function Es(t){return t>=1e6?`${(t/1e6).toFixed(1)}M kr`:t>=1e3?`${Math.round(t/1e3)}k kr`:`${t.toLocaleString("sv-SE")} kr`}function Te({className:t="",userCity:n}){var m;const{t:a}=fe(),[s,o]=v.useState("month"),[r,i]=v.useState("world"),[l,c]=v.useState([]),[f,d]=v.useState(!0),[g,x]=v.useState(!0);v.useEffect(()=>{let u=!1;return d(!0),Ss(s,r,15).then(w=>{u||(c(w),x(w.length>0),d(!1))}),()=>{u=!0}},[s,r]);const p=[{value:"all",label:a("leaderboard.total","Totalt")},{value:"year",label:a("time.year","Senaste året")},{value:"month",label:a("leaderboard.thisMonth","Denna månad")},{value:"today",label:a("common.today","Idag")}],b=[{value:"nearby",label:a("map.nearYou","Nära dig"),icon:mt},{value:"country",label:a("location.sweden","Sverige"),icon:hn},{value:"world",label:a("location.world","Världen"),icon:ft}],j=u=>u===1?e.jsx(pn,{className:"w-5 h-5 text-yellow-500"}):u===2?e.jsx(ot,{className:"w-5 h-5 text-gray-400"}):u===3?e.jsx(ot,{className:"w-5 h-5 text-amber-600"}):e.jsxs("span",{className:"w-5 h-5 flex items-center justify-center text-sm font-bold text-muted-foreground",children:["#",u]}),h=u=>u===1?"bg-gradient-to-r from-yellow-500/20 via-amber-500/10 to-transparent border-yellow-500/40":u===2?"bg-gradient-to-r from-gray-400/20 via-gray-300/10 to-transparent border-gray-400/40":u===3?"bg-gradient-to-r from-amber-600/20 via-orange-500/10 to-transparent border-amber-600/40":"bg-card/50 border-border/50",y=((m=b.find(u=>u.value===r))==null?void 0:m.label)??a("location.world","Världen");return e.jsxs("div",{className:t,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(nt,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a("leaderboard.title","Topplista")}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Top 15 – ",y]})]})]}),e.jsx("div",{className:"flex gap-1 mb-3 p-1 bg-muted/50 rounded-lg",children:b.map(u=>{const w=u.icon;return e.jsxs(L,{variant:r===u.value?"default":"ghost",size:"sm",onClick:()=>i(u.value),className:"flex-1 text-xs gap-1",children:[e.jsx(w,{className:"w-3 h-3"}),u.label]},u.value)})}),e.jsx("div",{className:"flex gap-2 mb-4 overflow-x-auto pb-1 -mx-4 px-4 scrollbar-hide",children:p.map(u=>e.jsx(L,{variant:s===u.value?"secondary":"ghost",size:"sm",onClick:()=>o(u.value),className:"text-xs px-3 flex-shrink-0",children:u.label},u.value))}),f?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(gt,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):g?e.jsx("div",{className:"space-y-2 max-h-[500px] overflow-y-auto pr-1",children:e.jsx(wt,{mode:"popLayout",children:l.map((u,w)=>e.jsx(Ie.div,{initial:{opacity:0,x:-20,scale:.95},animate:{opacity:1,x:0,scale:1},exit:{opacity:0,x:20,scale:.95},transition:{delay:w*.015,type:"spring",stiffness:400,damping:30},layout:!0,children:e.jsx(I,{className:`p-3 border ${h(u.rank)} backdrop-blur-sm`,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center ${u.rank<=3?"bg-background/80":"bg-muted/50"}`,children:j(u.rank)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm text-foreground truncate",children:u.nickname}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:e.jsx("span",{children:[u.gender==="male"?a("gender.male","Man"):u.gender==="female"?a("gender.female","Kvinna"):null,u.age?String(u.age):null,u.city].filter(Boolean).join(", ")})})]}),e.jsx("div",{className:"text-right flex-shrink-0",children:e.jsx("p",{className:`font-bold text-sm ${u.rank===1?"text-yellow-500":u.rank===2?"text-gray-400":u.rank===3?"text-amber-600":"text-primary"}`,children:Es(u.total_earned)})})]})})},`${r}-${s}-${u.user_id}-${u.rank}`))})}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(nt,{className:"w-10 h-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm font-medium",children:"Inga data ännu"}),e.jsx("p",{className:"text-xs mt-1",children:"Bli först på topplistan — slutför ditt första uppdrag!"})]})]})}var ye="Collapsible",[As]=Wt(ye),[Ms,Je]=As(ye),Ut=v.forwardRef((t,n)=>{const{__scopeCollapsible:a,open:s,defaultOpen:o,disabled:r,onOpenChange:i,...l}=t,[c,f]=Yt({prop:s,defaultProp:o??!1,onChange:i,caller:ye});return e.jsx(Ms,{scope:a,disabled:r,contentId:Zt(),open:c,onOpenToggle:v.useCallback(()=>f(d=>!d),[f]),children:e.jsx(ze.div,{"data-state":Qe(c),"data-disabled":r?"":void 0,...l,ref:n})})});Ut.displayName=ye;var zt="CollapsibleTrigger",Kt=v.forwardRef((t,n)=>{const{__scopeCollapsible:a,...s}=t,o=Je(zt,a);return e.jsx(ze.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Qe(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...s,ref:n,onClick:$t(t.onClick,o.onOpenToggle)})});Kt.displayName=zt;var Xe="CollapsibleContent",Vt=v.forwardRef((t,n)=>{const{forceMount:a,...s}=t,o=Je(Xe,t.__scopeCollapsible);return e.jsx(en,{present:a||o.open,children:({present:r})=>e.jsx(Ts,{...s,ref:n,present:r})})});Vt.displayName=Xe;var Ts=v.forwardRef((t,n)=>{const{__scopeCollapsible:a,present:s,children:o,...r}=t,i=Je(Xe,a),[l,c]=v.useState(s),f=v.useRef(null),d=tn(n,f),g=v.useRef(0),x=g.current,p=v.useRef(0),b=p.current,j=i.open||l,h=v.useRef(j),y=v.useRef(void 0);return v.useEffect(()=>{const m=requestAnimationFrame(()=>h.current=!1);return()=>cancelAnimationFrame(m)},[]),nn(()=>{const m=f.current;if(m){y.current=y.current||{transitionDuration:m.style.transitionDuration,animationName:m.style.animationName},m.style.transitionDuration="0s",m.style.animationName="none";const u=m.getBoundingClientRect();g.current=u.height,p.current=u.width,h.current||(m.style.transitionDuration=y.current.transitionDuration,m.style.animationName=y.current.animationName),c(s)}},[i.open,s]),e.jsx(ze.div,{"data-state":Qe(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!j,...r,ref:d,style:{"--radix-collapsible-content-height":x?`${x}px`:void 0,"--radix-collapsible-content-width":b?`${b}px`:void 0,...t.style},children:j&&o})});function Qe(t){return t?"open":"closed"}var _s=Ut;const Ot=_s,qt=Kt,Gt=Vt,Bs=[{id:"unicef",name:"UNICEF",description:"Räddar barn världen över",mission:"Arbetar för barns rättigheter i över 190 länder. Varje krona hjälper barn få tillgång till utbildning, rent vatten och sjukvård.",icon:jt,color:"#00AEEF",gradient:"from-cyan-500 to-blue-500",impact:"100 kr = vaccin till 10 barn",website:"https://unicef.se"},{id:"doctors-without-borders",name:"Läkare Utan Gränser",description:"Medicinsk hjälp i kriszoner",mission:"Ger livräddande medicinsk vård till människor i nöd, oavsett var de befinner sig eller vilka de är.",icon:Pn,color:"#ED1C24",gradient:"from-red-500 to-rose-600",impact:"250 kr = medicin för en familj",website:"https://lakareutangranser.se"},{id:"wwf",name:"WWF",description:"Skyddar naturen och djurlivet",mission:"Kämpar för att bevara biologisk mångfald och skydda utrotningshotade arter runt om i världen.",icon:wn,color:"#000000",gradient:"from-green-600 to-emerald-500",impact:"150 kr = skyddar 1 hektar regnskog",website:"https://wwf.se"},{id:"wateraid",name:"WaterAid",description:"Rent vatten till alla",mission:"Arbetar för att alla människor ska ha tillgång till rent vatten, sanitet och hygien. Vatten är grunden för allt.",icon:In,color:"#0099CC",gradient:"from-blue-500 to-cyan-400",impact:"200 kr = rent vatten i en månad",website:"https://wateraid.org"},{id:"plan",name:"Plan International",description:"Utbildning för flickor",mission:"Kämpar för barns rättigheter och flickors lika möjligheter till utbildning och framtid.",icon:jn,color:"#009FE3",gradient:"from-blue-400 to-indigo-500",impact:"300 kr = skolmaterial för ett barn",website:"https://plansverige.org"},{id:"stadsmission",name:"Stadsmissionen",description:"Hjälper utsatta i Sverige",mission:"Ger stöd till människor i hemlöshet och utsatthet. Ingen ska behöva vara hungrig eller frysa.",icon:xn,color:"#E31937",gradient:"from-red-500 to-orange-500",impact:"100 kr = en varm måltid",website:"https://stadsmissionen.se"},{id:"wfp",name:"World Food Programme",description:"Bekämpar hunger globalt",mission:"FN:s livsmedelsprogram räddar liv genom att leverera mat till de mest utsatta i världen.",icon:Rn,color:"#2A93FC",gradient:"from-blue-500 to-sky-400",impact:"50 kr = mat till en familj i en dag",website:"https://wfp.org"},{id:"hand-in-hand",name:"Hand in Hand",description:"Skapar jobb för att utrota fattigdom",mission:"Hjälper människor i fattigdom att starta egna företag och försörja sig själva och sina familjer.",icon:ft,color:"#F7941D",gradient:"from-orange-500 to-amber-500",impact:"500 kr = en mikroentreprenör får stöd",website:"https://handinhand.se"}];function Is({availableBalance:t,onDonate:n}){const{t:a}=fe(),[s,o]=v.useState(null),[r,i]=v.useState({}),[l,c]=v.useState(!1),[f,d]=v.useState(!1),[g,x]=v.useState(null),p=()=>{if(!g)return;const h=`Jag har just donerat ${g.amount} kr till ${g.charity.name} via Roxvault! 💚 Tillsammans kan vi göra skillnad.`,y=g.charity.website||"https://roxvault.app",m=`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(y)}"e=${encodeURIComponent(h)}`;window.open(m,"_blank","width=600,height=400"),T.success(a("charity.thanksForSharing")),d(!1)},b=async h=>{const y=parseInt(r[h.id])||0;if(y<10){T.error(a("charity.minDonation"));return}if(y>t){T.error(a("charity.notEnoughCredits"));return}c(!0),n?await n(h.id,y)&&(T.success(a("charity.thanksDonation",{amount:y,name:h.name})),x({charity:h,amount:y}),d(!0),o(null),i(u=>({...u,[h.id]:""}))):(await new Promise(m=>setTimeout(m,1e3)),T.success(a("charity.thanksDonation",{amount:y,name:h.name})),x({charity:h,amount:y}),d(!0),o(null),i(m=>({...m,[h.id]:""}))),c(!1)},j=[50,100,250,500];return e.jsxs(e.Fragment,{children:[e.jsx(ce,{open:f,onOpenChange:d,children:e.jsxs(de,{className:"sm:max-w-md",children:[e.jsxs(ue,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(bn,{className:"w-5 h-5 text-green-500"}),a("charity.donationComplete")]}),e.jsx(sn,{children:a("charity.donatedTo",{amount:g==null?void 0:g.amount,name:g==null?void 0:g.charity.name})})]}),e.jsxs("div",{className:"space-y-4 pt-4",children:[g&&e.jsxs("div",{className:"p-4 rounded-xl text-center",style:{background:g.charity.color+"15"},children:[e.jsx("div",{className:`w-12 h-12 rounded-xl bg-gradient-to-br ${g.charity.gradient} flex items-center justify-center mx-auto mb-3`,children:e.jsx(g.charity.icon,{className:"w-6 h-6 text-white"})}),e.jsxs("p",{className:"font-semibold",children:[g.amount," kr ",a("charity.to")," ",g.charity.name]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[a("charity.thankYou")," 💚"]})]}),e.jsxs(L,{onClick:p,className:"w-full bg-[#1877F2] hover:bg-[#166FE5] text-white",children:[e.jsx(Dn,{className:"w-5 h-5 mr-2"}),a("charity.shareOnFacebook")]}),e.jsx(L,{variant:"outline",onClick:()=>d(!1),className:"w-full",children:a("charity.maybeLater")})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(jt,{className:"w-5 h-5 text-rose-500"}),e.jsx("h2",{className:"text-lg font-semibold",children:a("charity.title")})]}),e.jsx("p",{className:"text-sm text-muted-foreground -mt-2 mb-4",children:a("charity.description")}),e.jsx("div",{className:"space-y-2",children:Bs.map((h,y)=>e.jsx(Ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:y*.03},children:e.jsxs(Ot,{open:s===h.id,onOpenChange:m=>o(m?h.id:null),children:[e.jsx(qt,{asChild:!0,children:e.jsxs("div",{className:"w-full p-3 rounded-xl border-2 cursor-pointer transition-all hover:shadow-md flex items-center gap-3",style:{borderColor:s===h.id?h.color:h.color+"30"},children:[e.jsx("div",{className:`w-10 h-10 rounded-xl bg-gradient-to-br ${h.gradient} flex items-center justify-center flex-shrink-0`,children:e.jsx(h.icon,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"flex-1 text-left",children:[e.jsx("h3",{className:"font-semibold text-sm",children:h.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h.description})]}),e.jsx(De,{className:`w-5 h-5 text-muted-foreground transition-transform ${s===h.id?"rotate-180":""}`})]})}),e.jsx(Gt,{children:e.jsx(wt,{children:e.jsxs(Ie.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"px-3 pb-4 pt-3 space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:h.mission}),e.jsx("div",{className:"p-3 rounded-xl text-sm",style:{background:h.color+"15"},children:e.jsxs("span",{className:"font-medium",style:{color:h.color},children:["💡 ",h.impact]})}),e.jsxs("div",{children:[e.jsx(ht,{htmlFor:`donation-${h.id}`,children:a("charity.amount")}),e.jsx(pt,{id:`donation-${h.id}`,type:"number",placeholder:a("charity.enterAmount"),value:r[h.id]||"",onChange:m=>i(u=>({...u,[h.id]:m.target.value})),max:t,className:"text-lg"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[a("charity.available"),": ",t," kr"]})]}),e.jsx("div",{className:"flex gap-2",children:j.map(m=>e.jsxs(L,{variant:r[h.id]===String(m)?"default":"outline",size:"sm",className:"flex-1",onClick:()=>i(u=>({...u,[h.id]:String(m)})),disabled:m>t,children:[m," kr"]},m))}),e.jsx(L,{className:"w-full",style:{background:h.color},onClick:()=>b(h),disabled:!r[h.id]||parseInt(r[h.id])<10||l,children:l?a("charity.donating"):`${a("charity.donate")} ${r[h.id]||0} kr`}),h.website&&e.jsxs("a",{href:h.website,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[a("charity.readMoreAt")," ",h.name,e.jsx(Nn,{className:"w-3 h-3"})]})]})})})]})},h.id))})]})]})}const re=.25,Jt=.35;function ae(t,n){const a=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0");return`RXV-${a}${s}-${String(t+1).padStart(5,"0")}`}function Ds(t){const n="0123456789ABCDEF";let a="";for(let s=0;s<6;s++)a+=n[Math.floor(Math.random()*n.length)];return`${t}-${a}`}function Xt(t){const n=t/(1-Jt),a=n-t,s=n*(1+re),o=s-n;return{grossAmount:Math.round(s*100)/100,vatAmount:Math.round(o*100)/100,taxDeducted:Math.round(a*100)/100,netAmount:t}}function He(t){return t?{companyName:t.organization_name,organizationNumber:t.organization_number,companyType:t.organization_type==="authority"?"Myndighet":"Aktiebolag",registeredCountry:t.country||"Sverige",address:{streetAddress:t.street_address,postalCode:t.postal_code,city:t.city,country:t.country||"Sverige"},orderer:{name:t.contact_person,title:"Beställare",department:"Uppdragsansvarig"}}:{companyName:"Rewault AB",organizationNumber:"559XXX-XXXX",companyType:"Aktiebolag",registeredCountry:"Sverige",address:{streetAddress:"Uppgift ej tillgänglig",postalCode:"",city:"Stockholm",country:"Sverige"},orderer:{name:"Systemgenererad",title:"Automatisk",department:"Plattformstjänster"}}}function Ue(t){var a;const n=t.includes(",")&&((a=t.split(",")[1])==null?void 0:a.trim())||"Stockholm";return{streetAddress:t||"Uppgift ej specificerad",postalCode:"",city:n,municipality:`${n}s kommun`,county:`${n}s län`,country:"Sverige",latitude:59.3293+(Math.random()-.5)*.1,longitude:18.0686+(Math.random()-.5)*.1,coordinateSystem:"WGS 84",accuracy:"±5 meter (GPS)"}}const Ps={"McDonald's Sverige AB":{organization_name:"McDonald's Sverige AB",organization_number:"556038-8434",organization_type:"company",contact_person:"Maria Lindqvist",street_address:"Frösundaviks allé 1",postal_code:"169 70",city:"Solna",country:"Sverige"},"Tesla Sweden AB":{organization_name:"Tesla Sweden AB",organization_number:"556959-2021",organization_type:"company",contact_person:"Johan Eriksson",street_address:"Karlavägen 60",postal_code:"114 49",city:"Stockholm",country:"Sverige"},"Spotify AB":{organization_name:"Spotify AB",organization_number:"556703-7485",organization_type:"company",contact_person:"Emma Andersson",street_address:"Regeringsgatan 19",postal_code:"111 53",city:"Stockholm",country:"Sverige"}};function _e(t){const n=[{title:"McDonald's Stureplan",area:"Kungsgatan 4, Stockholm",amount:150,payer:"McDonald's Sverige AB"},{title:"Tesla Supercharger Dokumentation",area:"Täby Centrum, Täby",amount:200,payer:"Tesla Sweden AB"},{title:"IKEA Entré-foto",area:"Modulvägen 1, Kungens Kurva",amount:120,payer:"McDonald's Sverige AB"},{title:"Spotify HQ Fasad",area:"Regeringsgatan 19, Stockholm",amount:180,payer:"Spotify AB"},{title:"SL Tunnelbana Station",area:"T-Centralen, Stockholm",amount:100,payer:"Tesla Sweden AB"},{title:"H&M Flagship Store",area:"Drottninggatan 56, Stockholm",amount:140,payer:"McDonald's Sverige AB"},{title:"Coop Matbutik",area:"Götgatan 31, Södermalm",amount:90,payer:"Spotify AB"},{title:"Circle K Bensinstation",area:"E4 Norrtull, Stockholm",amount:110,payer:"Tesla Sweden AB"},{title:"Systembolaget Skyltning",area:"Odengatan 43, Stockholm",amount:130,payer:"McDonald's Sverige AB"},{title:"Pressbyrån Kiosk",area:"Centralen, Stockholm",amount:75,payer:"Spotify AB"},{title:"MAX Hamburgare",area:"Fridhemsplan 1, Stockholm",amount:160,payer:"Tesla Sweden AB"},{title:"Volvo Showroom",area:"Fleminggatan 14, Kungsholmen",amount:220,payer:"McDonald's Sverige AB"},{title:"Nordic Choice Hotel",area:"Sky City, Arlanda",amount:190,payer:"Spotify AB"},{title:"Stadium Sportbutik",area:"Mall of Scandinavia, Solna",amount:145,payer:"Tesla Sweden AB"},{title:"Apotek Hjärtat",area:"Sveavägen 42, Vasastan",amount:95,payer:"McDonald's Sverige AB"}],a=[];let s=t,o=0;const r=new Date;for(;s>0&&o<n.length*3;){const i=n[o%n.length],l=Math.min(i.amount,s),c=Math.floor(o*2.5)+Math.floor(Math.random()*3),f=new Date(r);f.setDate(f.getDate()-c),f.setHours(8+Math.floor(Math.random()*12),Math.floor(Math.random()*60));const d=Xt(l),g=Ps[i.payer]||null;a.push({id:`mock-${o}`,receiptId:ae(o,f),grossAmount:d.grossAmount,vatAmount:d.vatAmount,taxDeducted:d.taxDeducted,netAmount:d.netAmount,created_at:f.toISOString(),description:null,mission_title:i.title,mission_area:i.area,completed_at:f.toISOString(),payer:He(g),serviceType:"Fotograferingstjänst – Professionell teknisk dokumentation",serviceContent:"Fotografering utförd i samband med teknisk inventering. Dokumentationen avser teknisk verifiering av objektets existens, placering och status.",servicePurpose:["intern kontroll","säkerhetsdokumentation","fastighetsrelaterad uppföljning"],location:Ue(i.area)}),s-=l,o++}return a}function Rs({open:t,onOpenChange:n,totalEarned:a}){const{t:s,i18n:o}=fe(),{user:r}=le(),[i,l]=v.useState([]),[c,f]=v.useState(!0),[d,g]=v.useState(null),[x,p]=v.useState(!1),j=(()=>{switch(o.language){case"de":return bt;case"en":return yt;default:return Y}})(),h=i.reduce((m,u)=>({gross:m.gross+u.grossAmount,vat:m.vat+u.vatAmount,tax:m.tax+u.taxDeducted,net:m.net+u.netAmount}),{gross:0,vat:0,tax:0,net:0});v.useEffect(()=>{if(!t||!r)return;async function m(){f(!0);try{const{data:u}=await K.from("wallets").select("id").eq("user_id",r.id).single();if(!u){a>0&&l(_e(a)),f(!1);return}const{data:w}=await K.from("transactions").select("id, amount, created_at, description, claim_id").eq("wallet_id",u.id).eq("type","credit").order("created_at",{ascending:!1});if(!w||w.length===0){a>0?l(_e(a)):l([]),f(!1);return}const C=await Promise.all(w.map(async(k,S)=>{const M=Xt(k.amount),N=new Date(k.created_at);if(k.claim_id){const{data:A}=await K.from("claims").select("completed_at, missions (title, area_name, created_by, latitude, longitude)").eq("id",k.claim_id).single(),E=A==null?void 0:A.missions,R=(E==null?void 0:E.title)||null,B=(E==null?void 0:E.area_name)||null,Ye=(E==null?void 0:E.created_by)||null;let We=null;if(Ye){const{data:Qt}=await K.from("orderer_profiles").select("organization_name, organization_number, organization_type, contact_person, street_address, postal_code, city, country").eq("user_id",Ye).maybeSingle();We=Qt}const be=Ue(B||"Stockholm");return E!=null&&E.latitude&&(E!=null&&E.longitude)&&(be.latitude=E.latitude,be.longitude=E.longitude),{id:k.id,receiptId:ae(S,N),...M,created_at:k.created_at,description:k.description,mission_title:R,mission_area:B,completed_at:(A==null?void 0:A.completed_at)||null,payer:He(We),serviceType:"Fotograferingstjänst – Professionell teknisk dokumentation",serviceContent:"Fotografering utförd i samband med teknisk inventering.",servicePurpose:["intern kontroll","säkerhetsdokumentation"],location:be}}return{id:k.id,receiptId:ae(S,N),...M,created_at:k.created_at,description:k.description,mission_title:null,mission_area:null,completed_at:null,payer:He(null),serviceType:"Fotograferingstjänst – Professionell teknisk dokumentation",serviceContent:"Fotografering utförd i samband med teknisk inventering.",servicePurpose:["intern kontroll","säkerhetsdokumentation"],location:Ue("Stockholm")}}));l(C)}catch(u){console.error("Error fetching earnings history:",u),a>0&&l(_e(a))}finally{f(!1)}}m()},[t,r,a]);const y=async()=>{var m,u;if(!r){T.error(s("earningsHistory.mustBeLoggedIn"));return}if(i.length===0){T.error(s("earningsHistory.noTransactionsToExport"));return}p(!0);try{const{data:{session:w}}=await K.auth.getSession();if(!w)throw new Error("No session");const C=new Date,k=ae(0,C),S={documentType:"Kontoutdrag",documentStatus:"Slutfört / Finalized",documentId:k,referenceNumber:k,documentDate:_(C,"yyyy-MM-dd"),documentTime:_(C,"HH:mm"),timezone:"CET",payer:i[0].payer,issuer:{companyName:"Rewault AB",organizationNumber:"559XXX-XXXX",vatRegistrationNumber:"SE559XXXXXX01",country:"Sverige",address:"Stockholm, Sverige",email:"faktura@rewault.com"},services:i.map((N,A)=>({description:N.mission_title||N.description||"Fotograferingsuppdrag",serviceType:N.serviceType,serviceContent:N.serviceContent,servicePurpose:N.servicePurpose,quantity:1,unitPrice:N.grossAmount/(1+re),vatRate:re,vatAmount:N.vatAmount,totalAmount:N.grossAmount,location:N.location})),timeline:{orderReceived:{date:_(new Date(i[0].created_at),"yyyy-MM-dd"),time:_(new Date(i[0].created_at),"HH:mm"),timezone:"CET"},serviceExecuted:{date:_(new Date(i[0].completed_at||i[0].created_at),"yyyy-MM-dd"),time:_(new Date(i[0].completed_at||i[0].created_at),"HH:mm"),timezone:"CET"},paymentReceived:{date:_(C,"yyyy-MM-dd"),time:_(C,"HH:mm"),timezone:"CET"},transactionCompleted:{date:_(C,"yyyy-MM-dd"),time:_(C,"HH:mm"),timezone:"CET"}},financials:{grossAmount:h.gross,vatAmount:h.vat,vatRate:re,preliminaryTax:h.tax,taxRate:Jt,netAmount:h.net,currency:"SEK"},taxCompliance:{taxNote:"Preliminärskatt om 35% har dragits för att säkerställa efterlevnad av kommunal beskattning oavsett hemkommun.",controlStatementNote:"Kontrolluppgift lämnas årligen i enlighet med svensk skattelagstiftning.",taxAuthority:"Skatteverket"},documentHash:Ds(k),recipient:{name:r.email||"Användare",email:r.email||"",userId:r.id}},M=await K.functions.invoke("generate-invoice-pdf",{body:{receiptData:S}});if(M.error)throw M.error;if((m=M.data)!=null&&m.downloadUrl)window.open(M.data.downloadUrl,"_blank"),T.success(s("earningsHistory.pdfGenerated"));else if(((u=M.data)==null?void 0:u.status)==="processing")T.info(s("earningsHistory.pdfProcessing"));else throw new Error("No download URL received")}catch(w){console.error("Error generating PDF:",w),T.error(s("earningsHistory.pdfError"))}finally{p(!1)}};return e.jsx(ce,{open:t,onOpenChange:n,children:e.jsxs(de,{className:"max-w-lg max-h-[85vh]",children:[e.jsx(ue,{children:e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(Nt,{className:"h-5 w-5 text-primary"}),s("earningsHistory.title")]})}),e.jsx("div",{className:"bg-muted/50 border border-border rounded-lg p-3 mb-2",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(kn,{className:"h-4 w-4 text-muted-foreground mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsx("p",{className:"font-medium",children:s("earningsHistory.auditCompliant")}),e.jsx("p",{children:s("earningsHistory.auditDescription")})]})]})}),e.jsx(I,{className:"bg-muted/30 border-border",children:e.jsxs(P,{className:"p-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("earningsHistory.grossAmount")}),e.jsxs("p",{className:"text-lg font-mono font-semibold",children:[h.gross.toFixed(2)," SEK"]})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:[s("earningsHistory.vat")," (25%)"]}),e.jsxs("p",{className:"text-lg font-mono font-semibold text-muted-foreground",children:["−",h.vat.toFixed(2)," SEK"]})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:[s("earningsHistory.preliminaryTax")," (35%)"]}),e.jsxs("p",{className:"text-lg font-mono font-semibold text-muted-foreground",children:["−",h.tax.toFixed(2)," SEK"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("earningsHistory.netPaid")}),e.jsxs("p",{className:"text-2xl font-mono font-bold",children:[h.net.toFixed(2)," SEK"]})]})]}),e.jsx(X,{className:"my-3"}),e.jsxs("div",{className:"flex justify-between items-center text-xs text-muted-foreground",children:[e.jsxs("span",{className:"font-mono",children:[s("earningsHistory.transactions"),": ",i.length]}),e.jsxs(ln,{children:[e.jsx(cn,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1.5 font-medium",disabled:x||i.length===0,children:[x?e.jsx(gt,{className:"h-3 w-3 animate-spin"}):e.jsx(rt,{className:"h-3 w-3"}),s(x?"earningsHistory.generating":"earningsHistory.pdf"),e.jsx(De,{className:"h-3 w-3 ml-0.5"})]})}),e.jsxs(dn,{align:"end",className:"w-40",children:[e.jsxs(Ze,{onClick:y,className:"gap-2 cursor-pointer",children:[e.jsx(Cn,{className:"h-4 w-4"}),s("earningsHistory.download")]}),e.jsxs(Ze,{onClick:()=>T.info(s("earningsHistory.sendEmailSoon")),className:"gap-2 cursor-pointer",children:[e.jsx(Sn,{className:"h-4 w-4"}),s("earningsHistory.send")]})]})]})]})]})}),e.jsx(vn,{className:"max-h-[350px] pr-4",children:c?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(m=>e.jsx(V,{className:"h-24 w-full"},m))}):i.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(rn,{className:"h-12 w-12 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:s("earningsHistory.noServicesRecorded")}),e.jsx("p",{className:"text-sm text-muted-foreground/60 mt-1",children:s("earningsHistory.completeMissionsForReceipts")})]}):e.jsx("div",{className:"space-y-2",children:i.map(m=>e.jsx(Ot,{open:d===m.id,onOpenChange:u=>g(u?m.id:null),children:e.jsxs(I,{className:"border-border",children:[e.jsx(qt,{asChild:!0,children:e.jsx(P,{className:"p-3 cursor-pointer hover:bg-muted/30 transition-colors",children:e.jsxs("div",{className:"flex justify-between items-start gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"font-medium text-sm truncate max-w-[140px] sm:max-w-none",children:m.mission_title||m.description||s("earningsHistory.serviceExecution")}),e.jsx(De,{className:`h-4 w-4 text-muted-foreground transition-transform flex-shrink-0 ${d===m.id?"rotate-180":""}`})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 mt-1 text-xs text-muted-foreground font-mono overflow-hidden",children:[e.jsxs("span",{className:"flex items-center gap-1 truncate",children:[e.jsx(rt,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:m.receiptId})]}),e.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx(En,{className:"h-3 w-3"}),_(new Date(m.completed_at||m.created_at),"yyyy-MM-dd",{locale:j})]})]})]}),e.jsxs(Q,{variant:"outline",className:"bg-muted text-foreground border-border font-mono flex-shrink-0 text-xs",children:["+",m.netAmount.toFixed(0)," SEK"]})]})})}),e.jsx(Gt,{children:e.jsxs("div",{className:"px-3 pb-3 pt-0",children:[e.jsx(X,{className:"mb-3"}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 space-y-3 text-xs",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground uppercase tracking-wide text-[10px]",children:s("earningsHistory.documentId")}),e.jsx("p",{className:"font-mono",children:m.receiptId})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground uppercase tracking-wide text-[10px]",children:s("earningsHistory.executed")}),e.jsxs("p",{className:"font-mono",children:[_(new Date(m.completed_at||m.created_at),"yyyy-MM-dd HH:mm",{locale:j})," CET"]})]})]}),e.jsx(X,{}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-muted-foreground uppercase tracking-wide text-[10px] flex items-center gap-1 mb-1",children:[e.jsx(An,{className:"h-3 w-3"}),s("earningsHistory.payingOrganization")]}),e.jsx("p",{className:"font-medium",children:m.payer.companyName}),e.jsxs("p",{className:"text-muted-foreground",children:[s("earningsHistory.orgNumber"),": ",m.payer.organizationNumber]}),e.jsxs("p",{className:"text-muted-foreground",children:[m.payer.companyType," · ",m.payer.registeredCountry]})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-muted-foreground uppercase tracking-wide text-[10px] flex items-center gap-1 mb-1",children:[e.jsx(mt,{className:"h-3 w-3"}),s("earningsHistory.serviceLocation")]}),e.jsx("p",{children:m.location.streetAddress}),e.jsxs("p",{className:"text-muted-foreground",children:[m.location.city,", ",m.location.country]}),e.jsxs("p",{className:"text-muted-foreground font-mono text-[10px]",children:[m.location.latitude.toFixed(4),"° N, ",m.location.longitude.toFixed(4),"° E (WGS84, ±5m)"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground uppercase tracking-wide text-[10px]",children:s("earningsHistory.serviceType")}),e.jsx("p",{children:m.serviceType})]}),e.jsx(X,{}),e.jsxs("div",{className:"space-y-1 font-mono",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:s("earningsHistory.grossAmount")}),e.jsxs("span",{children:[m.grossAmount.toFixed(2)," SEK"]})]}),e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsxs("span",{children:[s("earningsHistory.vat")," (25%)"]}),e.jsxs("span",{children:["−",m.vatAmount.toFixed(2)," SEK"]})]}),e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsxs("span",{children:[s("earningsHistory.preliminaryTax")," (35%)"]}),e.jsxs("span",{children:["−",m.taxDeducted.toFixed(2)," SEK"]})]}),e.jsx(X,{}),e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{children:s("earningsHistory.netPaid")}),e.jsxs("span",{children:[m.netAmount.toFixed(2)," SEK"]})]})]})]})]})})]})},m.id))})}),e.jsxs("div",{className:"text-[10px] text-muted-foreground/60 text-center pt-2 border-t border-border font-mono space-y-0.5",children:[e.jsx("p",{children:s("earningsHistory.footer1")}),e.jsx("p",{children:s("earningsHistory.footer2")}),e.jsx("p",{children:s("earningsHistory.footer3")})]})]})})}const Ls=t=>{switch(t){case"de":return bt;case"en":return yt;default:return Y}};function fr(){const{t,i18n:n}=fe(),{user:a,isLoading:s}=le(),{isLoading:o}=an(),{wallet:r,transactions:i,isLoading:l,error:c}=un(),{payouts:f,requestPayout:d}=Ln(),{activeVouchers:g,usedVouchers:x,expiresWithin7Days:p}=Ht(),[b,j]=v.useState(""),[h,y]=v.useState(!1),[m,u]=v.useState(!1),[w,C]=v.useState(!1),k=Ls(n.language);if(s||o)return e.jsxs("div",{className:"min-h-screen bg-background p-4",children:[e.jsx(V,{className:"h-40 w-full mb-4"}),e.jsx(V,{className:"h-20 w-full mb-2"}),e.jsx(V,{className:"h-20 w-full"})]});if(!a)return e.jsxs("div",{className:"min-h-screen bg-background pb-24",children:[e.jsxs("div",{className:"bg-gradient-to-br from-primary to-primary/80 text-primary-foreground p-6 pt-[calc(env(safe-area-inset-top)+1.5rem)]",children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:t("wallet.title")}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(I,{className:"bg-primary-foreground/10 border-primary-foreground/20",children:e.jsxs(P,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary-foreground/80 mb-1",children:[e.jsx(we,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:t("wallet.balance")})]}),e.jsx("p",{className:"text-3xl font-bold text-primary-foreground",children:"0"}),e.jsx("p",{className:"text-xs text-primary-foreground/60",children:t("common.credits")})]})}),e.jsx(I,{className:"bg-primary-foreground/10 border-primary-foreground/20",children:e.jsxs(P,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary-foreground/80 mb-1",children:[e.jsx(Mn,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:t("wallet.totalEarned")})]}),e.jsx("p",{className:"text-3xl font-bold text-primary-foreground",children:"0"}),e.jsx("p",{className:"text-xs text-primary-foreground/60",children:t("common.credits")})]})})]}),e.jsx(L,{className:"w-full mt-4 bg-primary-foreground text-primary hover:bg-primary-foreground/90",onClick:()=>window.location.href="/auth",children:t("wallet.loginToEarn")})]}),e.jsx("div",{className:"p-4 border-t border-border",children:e.jsx(Te,{})}),e.jsxs("div",{className:"p-4 border-t border-border",children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:t("wallet.transactionHistory")}),e.jsx(I,{children:e.jsxs(P,{className:"p-8 text-center",children:[e.jsx(se,{className:"h-12 w-12 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:t("wallet.loginToSeeTransactions")})]})})]}),e.jsx(je,{})]});if(c)return e.jsxs("div",{className:"min-h-screen bg-background pb-24",children:[e.jsxs("div",{className:"bg-gradient-to-br from-primary to-primary/80 text-primary-foreground p-6 pt-[calc(env(safe-area-inset-top)+1.5rem)]",children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:t("wallet.title")}),e.jsx(I,{className:"bg-primary-foreground/10 border-primary-foreground/20",children:e.jsxs(P,{className:"p-6 text-center",children:[e.jsx(we,{className:"h-12 w-12 mx-auto text-primary-foreground/40 mb-3"}),e.jsxs("p",{className:"text-primary-foreground font-medium mb-1",children:[t("wallet.balance"),": 0"]}),e.jsx("p",{className:"text-sm text-primary-foreground/60",children:t("common.credits")})]})})]}),e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(se,{className:"h-12 w-12 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:t("wallet.noTransactions")}),e.jsx("p",{className:"text-xs text-muted-foreground/60",children:t("wallet.completeMissionsToEarn")})]}),e.jsx("div",{className:"p-4 border-t border-border",children:e.jsx(Te,{})}),e.jsx(je,{})]});const S=parseInt(b)||0,M=async()=>{if(S<100){T.error(t("wallet.minWithdrawError"));return}u(!0);const N=await d(S,"stripe");u(!1),N&&(y(!1),j(""))};return e.jsxs("div",{className:"min-h-screen bg-background pb-24",children:[e.jsxs("div",{className:"bg-gradient-to-br from-primary to-primary/80 text-primary-foreground p-6 pt-[calc(env(safe-area-inset-top)+1.5rem)]",children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:t("wallet.title")}),l?e.jsx(V,{className:"h-24 w-full bg-primary-foreground/20"}):e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(I,{className:"bg-primary-foreground/10 border-primary-foreground/20",children:e.jsxs(P,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary-foreground/80 mb-1",children:[e.jsx(we,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Krediter"})]}),e.jsx("p",{className:"text-3xl font-bold text-primary-foreground",children:r?Ne(r.balance):"0 kr"}),e.jsx("p",{className:"text-xs text-primary-foreground/60",children:"Tjänade via uppdrag"})]})}),e.jsx(I,{className:"bg-primary-foreground/10 border-primary-foreground/20",children:e.jsxs(P,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary-foreground/80 mb-1",children:[e.jsx(at,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Utbetalningsbart"})]}),e.jsx("p",{className:"text-3xl font-bold text-primary-foreground",children:r&&r.balance>=ve?$e(et(r.balance)):"—"}),e.jsx("p",{className:"text-xs text-primary-foreground/60",children:r&&r.balance<ve?`Min ${ve} kr för uttag`:`${Math.round(tt*100)}% plattformsavgift`})]})})]}),e.jsxs(ce,{open:h,onOpenChange:y,children:[e.jsx(on,{asChild:!0,children:e.jsxs(L,{className:"w-full mt-4 bg-primary-foreground text-primary hover:bg-primary-foreground/90",disabled:!r||r.balance<100,children:[e.jsx(at,{className:"h-4 w-4 mr-2"}),"Begär utbetalning via Stripe"]})}),e.jsxs(de,{children:[e.jsx(ue,{children:e.jsx(me,{children:t("wallet.withdraw")})}),e.jsxs("div",{className:"space-y-4 pt-4",children:[e.jsxs("div",{children:[e.jsx(ht,{htmlFor:"amount",children:t("wallet.amount")}),e.jsx(pt,{id:"amount",type:"number",placeholder:t("wallet.minAmount"),value:b,onChange:N=>j(N.target.value),max:(r==null?void 0:r.balance)||0}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[t("wallet.available"),": ",(r==null?void 0:r.balance)||0," ",t("common.sek")]})]}),S>0&&e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-sm space-y-1",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Krediter att ta ut:"}),e.jsx("span",{className:"font-medium",children:Ne(Number(b)||0)})]}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Plattformsavgift (15%):"}),e.jsxs("span",{children:["- ",Ne(Math.round((Number(b)||0)*tt))]})]}),e.jsxs("div",{className:"flex justify-between font-semibold border-t pt-1 mt-1",children:[e.jsx("span",{children:"Du får (SEK):"}),e.jsx("span",{className:"text-green-600",children:$e(et(Number(b)||0))})]}),e.jsx("p",{className:"text-xs text-muted-foreground pt-1",children:"💡 Vouchers och produktbelöningar tas INTE ut som pengar — de löses in direkt hos företaget."})]}),e.jsx(L,{className:"w-full",onClick:M,disabled:S<100||m,children:t(m?"wallet.processing":"wallet.confirmWithdraw")})]})]})]})]}),f.filter(N=>N.status==="pending").length>0&&e.jsxs("div",{className:"p-4",children:[e.jsxs("h2",{className:"text-lg font-semibold mb-3 flex items-center gap-2",children:[e.jsx(Nt,{className:"h-5 w-5"}),t("wallet.pendingPayouts")]}),e.jsx("div",{className:"space-y-3",children:f.filter(N=>N.status==="pending").map(N=>e.jsx(I,{className:"border-orange-500/30 bg-orange-500/5",children:e.jsx(P,{className:"p-4",children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[N.net_amount," via Stripe Connect"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Stripe Connect"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:_(new Date(N.created_at),"PPp",{locale:k})})]}),e.jsx("span",{className:"text-sm text-orange-500 font-medium",children:t("wallet.pending")})]})})},N.id))})]}),e.jsx("div",{className:"p-4 border-t border-border",children:e.jsx(Is,{availableBalance:(r==null?void 0:r.balance)||0,onDonate:async(N,A)=>{const E=Be.getToken();if(!E)return T.error("Ingen giltig session — logga in igen"),!1;try{const R=await fetch("${import.meta.env.VITE_QZ_API_BASE}/auth/donate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${E}`},body:JSON.stringify({charity_id:N,amount:A})}),B=await R.json();return R.ok?!0:(T.error(B.error||"Donation misslyckades"),!1)}catch{return T.error("Nätverksfel — donation misslyckades"),!1}}})}),e.jsx("div",{className:"p-4 border-t border-border",children:e.jsx(Te,{})}),r&&e.jsxs("div",{className:"mx-4 mb-4 p-3 bg-blue-500/10 border border-blue-500/20 rounded-lg text-xs text-blue-700 dark:text-blue-300 space-y-1",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"🪙 Krediter"})," = in-app valuta du tjänar via uppdrag"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"💸 Pengar"})," = konverteras från krediter vid uttag (min 100 kr, 15% avgift)"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"🎟️ Vouchers"})," = kuponger från företag, löses in i butik — visas nedan"]})]}),e.jsxs("div",{className:"p-4 border-t border-border",children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:t("wallet.transactionHistory")}),l?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(N=>e.jsx(V,{className:"h-16 w-full"},N))}):i.length===0?e.jsx(I,{children:e.jsxs(P,{className:"p-8 text-center",children:[e.jsx(se,{className:"h-12 w-12 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:t("wallet.noTransactions")}),e.jsx("p",{className:"text-sm text-muted-foreground/60 mt-1",children:t("wallet.completeMissionsToEarn")})]})}):e.jsx("div",{className:"space-y-3",children:i.map(N=>{const A=mn(N.description||""),E=A==="cash"?"💸":A==="voucher"?"🎟️":"🪙",R=A==="cash"?"Utbetalning":A==="voucher"?"Kupong":"Krediter";return e.jsx(I,{children:e.jsxs(P,{className:"p-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[N.amount>0?e.jsx("div",{className:"h-10 w-10 rounded-full bg-green-500/10 flex items-center justify-center",children:e.jsx(Bn,{className:"h-5 w-5 text-green-500"})}):e.jsx("div",{className:"h-10 w-10 rounded-full bg-red-500/10 flex items-center justify-center",children:e.jsx(_n,{className:"h-5 w-5 text-red-500"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[e.jsx("span",{className:"mr-1",children:E}),N.description||N.type]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"text-xs text-muted-foreground/60 mr-2",children:R}),_(new Date(N.created_at),"PPp",{locale:k})]})]})]}),e.jsxs("p",{className:`text-lg font-semibold ${N.amount>0?"text-green-500":"text-red-500"}`,children:[N.amount>0?"+":"",N.amount]})]})},N.id)})})]}),(g.length>0||x.length>0)&&e.jsxs("div",{className:"px-4 pb-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xt,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"font-semibold",children:"Mina kuponger & belöningar"})]}),p.length>0&&e.jsxs("div",{className:"flex items-start gap-2 bg-amber-500/10 border border-amber-500/30 rounded-lg p-3",children:[e.jsx(Tn,{className:"w-4 h-4 text-amber-500 shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-sm text-amber-700 dark:text-amber-400",children:[p.length," kupong",p.length>1?"er":""," går ut inom 7 dagar"]})]}),g.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Aktiva"}),g.map(N=>e.jsx(ut,{voucher:N},N.id))]}),x.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Använda / Utgångna"}),x.slice(0,3).map(N=>e.jsx(ut,{voucher:N},N.id))]})]}),e.jsx(Rs,{open:w,onOpenChange:C,totalEarned:(r==null?void 0:r.total_earned)||0}),e.jsx(je,{})]})}export{fr as default};
|