UNPKG

bknd

Version:

Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.

3 lines 45.4 kB
"use client"; import ot,{forwardRef,useState,useRef,useImperativeHandle,useEffect,createContext,memo,useCallback,useMemo,Children,cloneElement,useContext,Fragment as Fragment$1,isValidElement,useId}from'react';import {useApi,useAuth,useInvalidate,useApiInfiniteQuery,useApiQuery}from'bknd/client';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {getBrowser,formatNumber,ucFirstAllSnakeToPascalWithSpaces,transformObject,isFileAccepted}from'bknd/utils';import {useRouter,Link,useLocation}from'wouter';import'@mantine/core';import {Switch}from'radix-ui';import {useClickOutside,useInViewport}from'@mantine/hooks';import {useStore,createStore}from'zustand';import {combine}from'zustand/middleware';var Tt=t=>{let[a,r]=useState(),o=useApi(t?.baseUrl);return useEffect(()=>{(async()=>{let l=await o.auth.strategies();l.res.ok&&r(l.body);})();},[t?.baseUrl]),{strategies:a?.strategies,basepath:a?.basepath,loading:!a}};function Gt(t){var a,r,o="";if(typeof t=="string"||typeof t=="number")o+=t;else if(typeof t=="object")if(Array.isArray(t)){var l=t.length;for(a=0;a<l;a++)t[a]&&(r=Gt(t[a]))&&(o&&(o+=" "),o+=r);}else for(r in t)t[r]&&(o&&(o+=" "),o+=r);return o}function l0(){for(var t,a,r=0,o="",l=arguments.length;r<l;r++)(t=arguments[r])&&(a=Gt(t))&&(o&&(o+=" "),o+=a);return o}var at=l0;function Vt(t,a){let r=t?.tagName.toLowerCase()??"",o=["input","select","textarea"];return !t||!a?.contains(t)||!o.includes(r)||!("name"in t)||t.hasAttribute("data-ignore")||t.closest("[data-ignore]")}function Xt(t){let a=t.currentTarget,r=t.target;return Vt(r,a)?null:r}function Kt(t,a){let r=t.querySelectorAll(`[name="${a}"]`);return Array.from(r).filter(o=>Vt(o))}function Qt(t,a){if(!t)return a;let r=t.required;if(!(!a&&!r))if(t.type==="number"){let o=Number(a);if(Number.isNaN(o)&&!r)return;let l="min"in t&&t.min.length>0?Number(t.min):void 0,i="max"in t&&t.max.length>0?Number(t.max):void 0,e="step"in t&&t.step.length>0?Number(t.step):void 0;return l&&o<l?l:i&&o>i?i:e&&e!==1?Math.round(o/e)*e:o}else if(t.type==="text"){let o="maxLength"in t&&t.maxLength>-1?Number(t.maxLength):void 0,l="pattern"in t?new RegExp(t.pattern):void 0;return o&&a.length>o?a.slice(0,o):l&&!l.test(a)?"":a}else return t.type==="checkbox"?"checked"in t?!!t.checked:["on","1","true",1,true].includes(a):a}function pt(t,a){if(!t)return t;let r=[null,void 0,""],o={empty:a?.empty??r,emptyInArray:a?.emptyInArray??r,keepEmptyArray:a?.keepEmptyArray??false};return Object.entries(t).reduce((l,[i,e])=>{if(e&&Array.isArray(e)&&e.some(h=>typeof h=="object")){let h=e.map(c=>pt(c,o));(h.length>0||o?.keepEmptyArray)&&(l[i]=h);}else if(e&&typeof e=="object"&&!Array.isArray(e)){let h=pt(e,o);Object.keys(h).length>0&&(l[i]=h);}else if(Array.isArray(e)){let h=e.filter(c=>!o.emptyInArray.includes(c));(h.length>0||o?.keepEmptyArray)&&(l[i]=h);}else o.empty.includes(e)||(l[i]=e);return l},{})}function mt(t,a,r){let o=a;if(typeof o=="string"){let e=h=>h[0]==='"'&&h.at(-1)==='"';o=o.split(/[.\[\]]+/).filter(h=>h).map(h=>Number.isNaN(Number(h))?h:Number(h)).map(h=>typeof h=="string"&&e(h)?h.slice(1,-1):h);}if(o.length===0)throw new Error("The path must have at least one entry in it");let[l,...i]=o;return i.length===0?(t[l]=r,t):(l in t||(t[l]=typeof i[0]=="number"?[]:{}),mt(t[l],i,r),t)}function _t({children:t,validateOn:a="submit",hiddenSubmit:r=false,errorFieldSelector:o,reportValidity:l,onSubmit:i,onSubmitInvalid:e,onError:h,clean:c,disableSubmitOnError:k=true,...f}){let n=useRef(null),[s,T]=useState([]);useEffect(()=>{!n.current||f.noValidate||v();},[]),useEffect(()=>{if(!n.current||f.noValidate)return;let g=s.length>0;n.current.querySelectorAll("[type=submit]").forEach(M=>{!M||!("type"in M)||M.type!=="submit"||(M.disabled=g);}),h?.(s);},[s]);let S=(g,M)=>{if(f.noValidate||!g||!("name"in g))return;let x=n.current?.querySelector(o?.(g.name)??`[data-role="input-error"][data-name="${g.name}"]`);if(g.checkValidity())T(L=>L.filter(B=>B.name!==g.name)),x&&(x.textContent="");else {let L={name:g.name,message:g.validationMessage};return T(B=>[...B.filter(I=>I.name!==g.name),L]),M?.report&&(x?x.textContent=L.message:l&&g.reportValidity()),L}},v=g=>{if(!n.current||f.noValidate)return [];let M=[];return n.current.querySelectorAll("input, select, textarea").forEach(x=>{let B=S(x,g);B&&M.push(B);}),k&&n.current.querySelectorAll("[type=submit]").forEach(x=>{M.length>0?x.setAttribute("disabled","disabled"):x.removeAttribute("disabled");}),M},m=()=>{if(!n.current)return {};let g=new FormData(n.current),M={};return g.forEach((x,L)=>{let B=Kt(n.current,L);if(B.length===0){console.warn(`No target found for key: ${L}`);return}let V=B.length>1;B.forEach((X,u)=>{let N=L;V&&(N=`${L}[${u}]`),mt(M,N,Qt(X,X.value));});}),typeof c>"u"?M:pt(M,c===true?void 0:c)};return jsxs("form",{...f,onChange:async g=>{if(!n.current)return;let x=Xt(g);x&&((a==="change"||s.length>0)&&S(x,{report:true}),f.onChange&&await f.onChange(m(),{event:g,key:x.name,value:x.value,errors:s}));},onSubmit:async g=>{g.preventDefault();let M=n.current;if(!M)return;let x=v({report:true});if(x.length>0){e?.(x,{event:g,form:M});return}i?await i(m(),{event:g,form:M}):M.submit();},ref:n,onKeyDown:g=>{n.current&&g.keyCode===13&&s.length>0&&!f.noValidate&&l&&n.current.reportValidity();},children:[t,r&&jsx("input",{type:"submit",style:{visibility:"hidden"}})]})}function w(...t){return t.filter(Boolean).join(" ")}var n0=(t,a)=>false;function Yt(){try{return n0(0)}catch{return false}}var E=t=>(Yt(),t);var p0=(t="",a="")=>a.toLowerCase().indexOf(t.toLowerCase())?"~"+a:a.slice(t.length)||"/",$t=(t,a="")=>t[0]==="~"?t.slice(1):a+t;var s0=t=>{try{return decodeURI(t)}catch{return t}},u0=t=>{let[a,r]=t.hook(t);return [s0(p0(t.base,a)),E((o,l)=>r($t(o,t.base),l))]};function t1({className:t,native:a,onClick:r,...o}){let l=useRouter(),[i,e]=u0(l);function h(T,S){if(T.startsWith(S)){let v=T.replace(S,"");return v.length===0||v[0]==="/"}return false}let c=o.href??o.to,k=l.hrefs(c[0]==="~"?c.slice(1):l.base+c,l).replace("//","/"),f=$t(i,l.base).replace("//","/"),n=k.replace(l.base,"").length<=1?k===f:h(f,k);if(a)return jsx("a",{className:`${n?"active ":""}${t}`,...o});let s=T=>{r?.(T);};return jsx(Link,{className:`${n?"active ":""}${t}`,...o,onClick:s})}var M0={smaller:"px-1.5 py-1 rounded-md gap-1 !text-xs",small:"px-2 py-1.5 rounded-md gap-1 text-sm",default:"px-3 py-2.5 rounded-md gap-1.5",large:"px-4 py-3 rounded-md gap-2.5 text-lg"},k0={smaller:12,small:14,default:16,large:20},f0={default:"bg-primary/5 hover:bg-primary/10 link text-primary/70",primary:"bg-primary hover:bg-primary/80 link text-background",ghost:"bg-transparent hover:bg-primary/5 link text-primary/70",outline:"border border-primary/20 bg-transparent hover:bg-primary/5 link text-primary/80",red:"dark:bg-red-950 dark:hover:bg-red-900 bg-red-100 hover:bg-red-200 link text-primary/70",subtlered:"dark:text-red-700 text-red-700 dark:hover:bg-red-900 dark:hover:text-red-200 bg-transparent hover:bg-red-50 link"},r1=({children:t,size:a,variant:r,IconLeft:o,IconRight:l,iconSize:i=k0[a??"default"],iconProps:e,labelClassName:h,...c})=>({...c,className:w("flex flex-row flex-nowrap items-center !font-semibold disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed transition-[opacity,background-color,color,border-color]",M0[a??"default"],f0[r??"default"],c.className),children:jsxs(Fragment,{children:[o&&jsx(o,{size:i,...e}),t&&Children.count(t)===1?jsx("span",{className:w("leading-none",h),children:t}):t,l&&jsx(l,{size:i,...e})]})}),Y=forwardRef((t,a)=>jsx("button",{type:"button",ref:a,...r1(t)}));forwardRef((t,a)=>jsx(t1,{ref:a,href:"#",...r1(t)}));var Wt={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},jt=ot.createContext&&ot.createContext(Wt);var C0=["attr","size","title"];function b0(t,a){if(t==null)return {};var r=B0(t,a),o,l;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(l=0;l<i.length;l++)o=i[l],!(a.indexOf(o)>=0)&&Object.prototype.propertyIsEnumerable.call(t,o)&&(r[o]=t[o]);}return r}function B0(t,a){if(t==null)return {};var r={};for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){if(a.indexOf(o)>=0)continue;r[o]=t[o];}return r}function st(){return st=Object.assign?Object.assign.bind():function(t){for(var a=1;a<arguments.length;a++){var r=arguments[a];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);}return t},st.apply(this,arguments)}function l1(t,a){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);a&&(o=o.filter(function(l){return Object.getOwnPropertyDescriptor(t,l).enumerable})),r.push.apply(r,o);}return r}function ut(t){for(var a=1;a<arguments.length;a++){var r=arguments[a]!=null?arguments[a]:{};a%2?l1(Object(r),true).forEach(function(o){w0(t,o,r[o]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l1(Object(r)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(r,o));});}return t}function w0(t,a,r){return a=T0(a),a in t?Object.defineProperty(t,a,{value:r,enumerable:true,configurable:true,writable:true}):t[a]=r,t}function T0(t){var a=m0(t,"string");return typeof a=="symbol"?a:a+""}function m0(t,a){if(typeof t!="object"||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var o=r.call(t,a);if(typeof o!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return (a==="string"?String:Number)(t)}function i1(t){return t&&t.map((a,r)=>ot.createElement(a.tag,ut({key:r},a.attr),i1(a.child)))}function F(t){return a=>ot.createElement(W0,st({attr:ut({},t.attr)},a),i1(t.child))}function W0(t){var a=r=>{var{attr:o,size:l,title:i}=t,e=b0(t,C0),h=l||r.size||"1em",c;return r.className&&(c=r.className),t.className&&(c=(c?c+" ":"")+t.className),ot.createElement("svg",st({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},r.attr,o,e,{className:c,style:ut(ut({color:t.color||r.color},r.style),t.style),height:h,width:h,xmlns:"http://www.w3.org/2000/svg"}),i&&ot.createElement("title",null,i),t.children)};return jt!==void 0?ot.createElement(jt.Consumer,null,r=>a(r)):a(Wt)}function e1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M4 7a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12z"},child:[]},{tag:"path",attr:{d:"M16 3v4"},child:[]},{tag:"path",attr:{d:"M8 3v4"},child:[]},{tag:"path",attr:{d:"M4 11h16"},child:[]},{tag:"path",attr:{d:"M11 15h1"},child:[]},{tag:"path",attr:{d:"M12 15v3"},child:[]}]})(t)}function h1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 9l6 6l6 -6"},child:[]}]})(t)}function d1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},child:[]},{tag:"path",attr:{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},child:[]},{tag:"path",attr:{d:"M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},child:[]}]})(t)}function n1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M12 6h-6a2 2 0 0 0 -2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-6"},child:[]},{tag:"path",attr:{d:"M11 13l9 -9"},child:[]},{tag:"path",attr:{d:"M15 4h5v5"},child:[]}]})(t)}function c1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M10.585 10.587a2 2 0 0 0 2.829 2.828"},child:[]},{tag:"path",attr:{d:"M16.681 16.673a8.717 8.717 0 0 1 -4.681 1.327c-3.6 0 -6.6 -2 -9 -6c1.272 -2.12 2.712 -3.678 4.32 -4.674m2.86 -1.146a9.055 9.055 0 0 1 1.82 -.18c3.6 0 6.6 2 9 6c-.666 1.11 -1.379 2.067 -2.138 2.87"},child:[]},{tag:"path",attr:{d:"M3 3l18 18"},child:[]}]})(t)}function g1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0"},child:[]},{tag:"path",attr:{d:"M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6"},child:[]}]})(t)}function p1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M14 3v4a1 1 0 0 0 1 1h4"},child:[]},{tag:"path",attr:{d:"M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z"},child:[]},{tag:"path",attr:{d:"M9 9l1 0"},child:[]},{tag:"path",attr:{d:"M9 13l6 0"},child:[]},{tag:"path",attr:{d:"M9 17l6 0"},child:[]}]})(t)}function s1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M14 3v4a1 1 0 0 0 1 1h4"},child:[]},{tag:"path",attr:{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"},child:[]},{tag:"path",attr:{d:"M7 16.5a1.5 1.5 0 0 0 -3 0v3a1.5 1.5 0 0 0 3 0"},child:[]},{tag:"path",attr:{d:"M10 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75"},child:[]},{tag:"path",attr:{d:"M16 15l2 6l2 -6"},child:[]}]})(t)}function u1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M14 3v4a1 1 0 0 0 1 1h4"},child:[]},{tag:"path",attr:{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"},child:[]},{tag:"path",attr:{d:"M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"},child:[]},{tag:"path",attr:{d:"M17 18h2"},child:[]},{tag:"path",attr:{d:"M20 15h-3v6"},child:[]},{tag:"path",attr:{d:"M11 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1z"},child:[]}]})(t)}function v1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M14 3v4a1 1 0 0 0 1 1h4"},child:[]},{tag:"path",attr:{d:"M14 3v4a1 1 0 0 0 1 1h4"},child:[]},{tag:"path",attr:{d:"M5 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75"},child:[]},{tag:"path",attr:{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"},child:[]},{tag:"path",attr:{d:"M18 15v6h2"},child:[]},{tag:"path",attr:{d:"M13 15a2 2 0 0 1 2 2v2a2 2 0 1 1 -4 0v-2a2 2 0 0 1 2 -2z"},child:[]},{tag:"path",attr:{d:"M14 20l1.5 1.5"},child:[]}]})(t)}function M1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M14 3v4a1 1 0 0 0 1 1h4"},child:[]},{tag:"path",attr:{d:"M14 3v4a1 1 0 0 0 1 1h4"},child:[]},{tag:"path",attr:{d:"M16.5 15h3"},child:[]},{tag:"path",attr:{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"},child:[]},{tag:"path",attr:{d:"M4.5 15h3"},child:[]},{tag:"path",attr:{d:"M6 15v6"},child:[]},{tag:"path",attr:{d:"M18 15v6"},child:[]},{tag:"path",attr:{d:"M10 15l4 6"},child:[]},{tag:"path",attr:{d:"M10 21l4 -6"},child:[]}]})(t)}function k1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M14 3v4a1 1 0 0 0 1 1h4"},child:[]},{tag:"path",attr:{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"},child:[]},{tag:"path",attr:{d:"M4 15l4 6"},child:[]},{tag:"path",attr:{d:"M4 21l4 -6"},child:[]},{tag:"path",attr:{d:"M19 15v6h3"},child:[]},{tag:"path",attr:{d:"M11 21v-6l2.5 3l2.5 -3v6"},child:[]}]})(t)}function f1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M20 16v-8l3 8v-8"},child:[]},{tag:"path",attr:{d:"M15 8a2 2 0 0 1 2 2v4a2 2 0 1 1 -4 0v-4a2 2 0 0 1 2 -2z"},child:[]},{tag:"path",attr:{d:"M1 8h3v6.5a1.5 1.5 0 0 1 -3 0v-.5"},child:[]},{tag:"path",attr:{d:"M7 15a1 1 0 0 0 1 1h1a1 1 0 0 0 1 -1v-2a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1h1a1 1 0 0 1 1 1"},child:[]}]})(t)}function x1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M3 5m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z"},child:[]},{tag:"path",attr:{d:"M7 15v-6l2 2l2 -2v6"},child:[]},{tag:"path",attr:{d:"M14 13l2 2l2 -2m-2 2v-6"},child:[]}]})(t)}function L1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M3 17a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"},child:[]},{tag:"path",attr:{d:"M13 17a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"},child:[]},{tag:"path",attr:{d:"M9 17v-13h10v13"},child:[]},{tag:"path",attr:{d:"M9 8h10"},child:[]}]})(t)}function C1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M4 7l16 0"},child:[]},{tag:"path",attr:{d:"M10 11l0 6"},child:[]},{tag:"path",attr:{d:"M14 11l0 6"},child:[]},{tag:"path",attr:{d:"M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12"},child:[]},{tag:"path",attr:{d:"M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"},child:[]}]})(t)}function b1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"},child:[]},{tag:"path",attr:{d:"M7 9l5 -5l5 5"},child:[]},{tag:"path",attr:{d:"M12 4l0 12"},child:[]}]})(t)}function B1(t){return F({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M16 16v-8h2a2 2 0 1 1 0 4h-2"},child:[]},{tag:"path",attr:{d:"M12 8v8"},child:[]},{tag:"path",attr:{d:"M4 8h4l-4 8h4"},child:[]}]})(t)}var z0={xs:{className:"p-0.5",size:13},sm:{className:"p-0.5",size:15},md:{className:"p-1",size:18},lg:{className:"p-1.5",size:22}},lt=forwardRef(({Icon:t,size:a,variant:r="ghost",onClick:o,disabled:l,iconProps:i,tabIndex:e,...h},c)=>{let k=z0[a??"md"];return jsx(Y,{ref:c,variant:r,iconSize:k.size,iconProps:i,IconLeft:t,className:w(k.className,h.className),onClick:o,disabled:l,tabIndex:e})});var zt=({error:t,as:a,...r})=>jsx(a||"div",{...r,"data-role":"group",className:w("flex flex-col gap-1.5 w-full",a==="fieldset"&&"border border-primary/10 p-3 rounded-md",a==="fieldset"&&t&&"border-red-500",t&&"text-red-500",r.className)});var Ft=({as:t,...a})=>jsx(t||"label",{...a});var it=forwardRef((t,a)=>{let r=t.disabled||t.readOnly;return jsx("input",{type:"text",...t,ref:a,className:w("bg-muted/40 h-11 rounded-md py-2.5 px-4 outline-none w-full disabled:cursor-not-allowed",r&&"bg-muted/50 text-primary/50",!r&&"focus:bg-muted focus:outline-none focus:ring-2 focus:ring-zinc-500 focus:border-transparent transition-all",t.className)})});forwardRef((t,a)=>t.type==="password"?jsx(St,{...t,ref:a}):"data-type"in t&&t["data-type"]==="textarea"?jsx(A0,{...t,ref:a}):jsx(it,{...t,ref:a}));var St=forwardRef((t,a)=>{let[r,o]=useState(false);function l(){o(i=>!i);}return jsxs("div",{className:"relative w-full",children:[jsx(it,{...t,type:r?"text":"password",className:"w-full",ref:a}),jsx("div",{className:"absolute right-3 top-0 bottom-0 flex items-center",children:jsx(lt,{Icon:r?c1:g1,onClick:l,variant:"ghost",className:"opacity-70"})})]})}),A0=forwardRef((t,a)=>jsx("textarea",{rows:3,...t,ref:a,className:w("bg-muted/40 min-h-11 rounded-md py-2.5 px-4 focus:bg-muted outline-none focus:outline-none focus:ring-2 focus:ring-zinc-500 focus:border-transparent transition-all disabled:bg-muted/50 disabled:text-primary/50",t.className)}));forwardRef((t,a)=>{let r=useRef(null),o=getBrowser();useImperativeHandle(a,()=>r.current);let l=E(()=>{r?.current&&(r.current.focus(),["Safari"].includes(o)?r.current.click():r.current.showPicker());});return jsxs("div",{className:"relative w-full",children:[jsx("div",{className:"absolute h-full right-3 top-0 bottom-0 flex items-center",children:jsx(lt,{Icon:e1,onClick:l})}),jsx(it,{...t,type:t.type??"date",ref:r,className:"w-full appearance-none"})]})});forwardRef((t,a)=>{let[r,o]=useState(!!t.value);useEffect(()=>{o(!!t.value);},[t.value]);function l(i){o(i.target.checked),t.onChange?.(i.target.checked);}return jsx("div",{className:"h-11 flex items-center",children:jsx("input",{...t,type:"checkbox",ref:a,className:"outline-none focus:outline-none focus:ring-2 focus:ring-zinc-500 transition-all disabled:opacity-70 scale-150 ml-1",checked:r,onChange:l,disabled:t.disabled})})});var T1={xs:{root:"h-5 w-8",thumb:"data-[state=checked]:left-[calc(100%-1rem)]"},sm:{root:"h-6 w-10",thumb:"data-[state=checked]:left-[calc(100%-1.25rem)]"},md:{root:"h-7 w-12",thumb:"data-[state=checked]:left-[calc(100%-1.5rem)]"}};forwardRef(({type:t,required:a,...r},o)=>jsx(Switch.Root,{className:at("relative cursor-pointer rounded-full bg-muted border-2 border-transparent outline-none ring-1 dark:ring-primary/10 ring-primary/20 data-[state=checked]:ring-primary/60 data-[state=checked]:bg-primary/60 appearance-none transition-colors hover:bg-muted/80",T1[r.size??"md"].root,r.disabled&&"opacity-50 !cursor-not-allowed"),onCheckedChange:l=>{console.log("setting",l),r.onChange?.({target:{value:l}});},...r,checked:typeof r.checked<"u"?r.checked:typeof r.value<"u"?!!r.value:void 0,ref:o,children:jsx(Switch.Thumb,{className:at("absolute top-0 left-0 h-full aspect-square rounded-full bg-primary/30 data-[state=checked]:bg-background transition-[left,right] duration-100 border border-muted",T1[r.size??"md"].thumb)})}));forwardRef(({children:t,options:a,...r},o)=>jsxs("div",{className:"flex w-full relative",children:[jsx("select",{...r,ref:o,className:w("bg-muted/40 focus:bg-muted rounded-md py-2.5 px-4 outline-none focus:outline-none focus:ring-2 focus:ring-zinc-500 focus:border-transparent transition-all disabled:bg-muted/50 disabled:text-primary/50","appearance-none h-11 w-full",!r.multiple&&"border-r-8 border-r-transparent",r.className),children:a?jsxs(Fragment,{children:[!r.required&&jsx("option",{value:""}),a.map(l=>typeof l!="object"?{value:l,label:String(l)}:l).map(l=>jsx("option",{value:l.value,children:l.label},l.value))]}):t}),!r.multiple&&jsx(h1,{className:"absolute right-3 top-0 bottom-0 h-full opacity-70 pointer-events-none",size:18})]}));function Mt({label:t,provider:a,icon:r,action:o,method:l="POST",basepath:i="/api/auth",children:e}){let h=[i,a,o].join("/");return jsxs("form",{method:l,action:h,className:"w-full",children:[jsxs(Y,{type:"submit",size:"large",variant:"outline",className:"justify-center w-full",IconLeft:r,children:["Continue with ",t??ucFirstAllSnakeToPascalWithSpaces(a)]}),e]})}var kt=({visible:t=true,title:a,message:r,className:o,children:l,...i})=>t?jsx("div",{...i,className:w("flex flex-row items-center p-4",o),children:jsxs("p",{children:[a&&jsxs("b",{children:[a,": "]}),r||l]})}):null,q0=({className:t,...a})=>jsx(kt,{...a,className:w("bg-error text-error-foreground",t)}),z1={Exception:q0};function ft({formData:t,className:a,method:r="POST",action:o,auth:l,buttonLabel:i=o==="login"?"Sign in":"Sign up",onSubmit:e,...h}){let c=useAuth(),k=l?.basepath??"/api/auth",[f,n]=useState(),[,s]=useLocation(),T={action:`${k}/password/${o}`,strategy:l?.strategies?.password??{}},S=transformObject(l?.strategies??{},b=>b.type!=="password"?b.config:void 0),v=Object.keys(S).length>0;async function m(b,D){if(c?.local){D.event.preventDefault();let O=await c.login(b);if("token"in O)s("/");else {n(O.error);return}}await e?.(D.event),D.form.submit();}return useEffect(()=>{c.user&&s("/");},[c.user]),jsxs("div",{className:"flex flex-col gap-4 w-full",children:[v&&jsxs(Fragment,{children:[jsx("div",{children:Object.entries(S)?.map(([b,D],O)=>jsx(Mt,{provider:b,method:r,basepath:k,action:o},O))}),jsx(K0,{})]}),jsxs(_t,{method:r,action:T.action,onSubmit:m,...h,validateOn:"change",className:at("flex flex-col gap-3 w-full",a),children:[f&&jsx(z1.Exception,{message:f,className:"justify-center"}),jsxs(zt,{children:[jsx(Ft,{htmlFor:"email",children:"Email address"}),jsx(it,{type:"email",name:"email",required:true})]}),jsxs(zt,{children:[jsx(Ft,{htmlFor:"password",children:"Password"}),jsx(St,{name:"password",required:true,minLength:1})]}),jsx(Y,{type:"submit",variant:"primary",size:"large",className:"w-full mt-2 justify-center",children:i})]})]})}var K0=()=>jsxs("div",{className:"w-full flex flex-row items-center",children:[jsx("div",{className:"relative flex grow",children:jsx("div",{className:"h-px bg-primary/10 w-full absolute top-[50%] z-0"})}),jsx("div",{className:"mx-5",children:"or"}),jsx("div",{className:"relative flex grow",children:jsx("div",{className:"h-px bg-primary/10 w-full absolute top-[50%] z-0"})})]});function F1({method:t="POST",action:a="login",logo:r,intro:o,formOnly:l}){let{strategies:i,basepath:e,loading:h}=Tt(),c=jsx(ft,{auth:{basepath:e,strategies:i},method:t,action:a});return l?h?null:c:jsx("div",{className:"flex flex-1 flex-col select-none h-dvh w-dvw justify-center items-center bknd-admin",children:!h&&jsxs("div",{className:"flex flex-col gap-4 items-center w-96 px-6 py-7",children:[r||null,isValidElement(o)?o:jsxs("div",{className:"flex flex-col items-center",children:[jsxs("h1",{className:"text-xl font-bold",children:["Sign ",a==="login"?"in":"up"," to your admin panel"]}),jsx("p",{className:"text-primary/50",children:"Enter your credentials below to get access."})]}),c]})})}var mr={Screen:F1,Form:ft,SocialLink:Mt};function S1(){let t=useRef(0);return t.current++,t.current}var Y0={video:["mp4","webm"],audio:["ogg"],image:["jpeg","png","gif","webp","bmp","tiff","avif","heic","heif"],text:["html","css","mdx","yaml","vcard","csv","vtt"],application:["zip","toml","json","json5","pdf","xml"],font:["woff","woff2","ttf","otf"]},p={vnd:"vnd.openxmlformats-officedocument",z:"application/x-7z-compressed",t:(t="plain")=>`text/${t}`,a:(t="octet-stream")=>`application/${t}`,i:t=>`image/${t}`,v:t=>`video/${t}`,au:t=>`audio/${t}`},J0=new Map([["7z",p.z],["7zip",p.z],["txt",p.t()],["ai",p.a("postscript")],["apk",p.a("vnd.android.package-archive")],["doc",p.a("msword")],["docx",`${p.vnd}.wordprocessingml.document`],["eps",p.a("postscript")],["epub",p.a("epub+zip")],["ini",p.t()],["ico",p.i("vnd.microsoft.icon")],["jar",p.a("java-archive")],["jsonld",p.a("ld+json")],["jpg",p.i("jpeg")],["js",p.t("javascript")],["log",p.t()],["m3u",p.au("x-mpegurl")],["m3u8",p.a("vnd.apple.mpegurl")],["manifest",p.t("cache-manifest")],["md",p.t("markdown")],["mkv",p.v("x-matroska")],["mp3",p.au("mpeg")],["mobi",p.a("x-mobipocket-ebook")],["ppt",p.a("powerpoint")],["pptx",`${p.vnd}.presentationml.presentation`],["qt",p.v("quicktime")],["svg",p.i("svg+xml")],["tif",p.i("tiff")],["tsv",p.t("tab-separated-values")],["tgz",p.a("x-tar")],["text",p.t()],["vcd",p.a("x-cdlink")],["vcs",p.t("x-vcalendar")],["wav",p.au("vnd.wav")],["webmanifest",p.a("manifest+json")],["xls",p.a("vnd.ms-excel")],["xlsx",`${p.vnd}.spreadsheetml.sheet`],["yml",p.t("yaml")]]);function y1(t){try{let a=t.split(".").pop();if(!a)return p.a();for(let[r,o]of Object.entries(Y0))if(o.includes(a))return `${r}/${a}`;return J0.get(a)}catch{return p.a()}}function D1(t,a,r){let o=Math.min(a,r),l=Math.max(a,r);return Math.max(o,Math.min(t,l))}function P1({children:t,defaultOpen:a=false,openEvent:r="onClick",position:o="bottom-start",dropdownWrapperProps:l,items:i,title:e,hideOnEmpty:h=true,onClickItem:c,renderItem:k,itemsClassName:f,className:n}){let[s,T]=useState(a),[S,v]=useState(o),m=useClickOutside(()=>T(false)),b=i.filter(Boolean),[D,O]=useState(0),g=E((u=50)=>setTimeout(()=>T(N=>!N),typeof u=="number"?u:0)),M=r==="onClick"?u=>{u.stopPropagation(),g();}:void 0,x=E(u=>{if(r!=="onContextMenu")return;if(u.preventDefault(),s){g(0),setTimeout(()=>{v(o),O(0);},10);return}let N=u.clientX-u.currentTarget.getBoundingClientRect().left,{left:U=0,right:K=0}=m.current?.getBoundingClientRect()??{};if(U>0&&K>0){let ct=D1(N,U,K);N<(U+K)/2?(v("bottom-start"),O(ct)):(v("bottom-end"),O(K-ct));}else v(o),O(0);g();}),L=4,B={"bottom-start":{top:"100%",left:D,marginTop:L},"bottom-end":{right:D,top:"100%",marginTop:L},"top-start":{bottom:"100%",marginBottom:L},"top-end":{bottom:"100%",right:D,marginBottom:L}}[S],I=E(u=>{u.onClick&&u.onClick(),c&&c(u),g(50);});if(b.length===0&&h)return null;let V=b.some(u=>"icon"in u&&u.icon),X=k||((u,{key:N,onClick:U})=>typeof u=="function"?jsx(Fragment$1,{children:u()},N):jsxs("button",{type:"button",disabled:u.disabled,className:w("flex flex-row flex-nowrap text-nowrap items-center outline-none cursor-pointer px-2.5 rounded-md link leading-none h-8",f,u.disabled?"opacity-50 cursor-not-allowed":"hover:bg-primary/10",u.destructive&&"text-red-500 hover:bg-red-600 hover:text-white"),onClick:U,title:u.title,children:[V&&jsx("div",{className:"size-[16px] text-left mr-1.5 opacity-80",children:u.icon&&jsx(u.icon,{className:"size-[16px]"})}),jsx("div",{className:"flex flex-grow truncate text-nowrap",children:u.label})]},N));return jsxs("div",{role:"dropdown",className:w("relative flex",n),ref:m,onContextMenu:x,children:[cloneElement(t,{onClick:M}),s&&jsxs("div",{...l,className:w("absolute z-30 flex flex-col bg-background border border-muted px-1 py-1 rounded-lg shadow-lg min-w-full",l?.className),style:B,children:[e&&jsx("div",{className:"text-sm font-bold px-2.5 mb-1 mt-1 opacity-50 truncate",children:e}),b.map((u,N)=>X(u,{key:N,onClick:U=>{U.stopPropagation(),I(u);}}))]})]})}var ra=[".DS_Store","Thumbs.db"];function dt(t,a){let r=oa(t);if(typeof r.path!="string"){let{webkitRelativePath:o}=t;Object.defineProperty(r,"path",{value:typeof a=="string"?a:typeof o=="string"&&o.length>0?o:t.name,writable:false,configurable:false,enumerable:true});}return r}function oa(t){let{name:a}=t,r=a&&a.lastIndexOf(".")!==-1;if(console.log("withMimeType",a,r),r&&!t.type){let o=y1(a);console.log("guessed",o),o&&Object.defineProperty(t,"type",{value:o,writable:false,configurable:false,enumerable:true});}return t}async function nt(t){return xt(t)&&la(t.dataTransfer)?da(t.dataTransfer,t.type):ia(t)?ea(t):Array.isArray(t)&&t.every(a=>"getFile"in a&&typeof a.getFile=="function")?ha(t):[]}function la(t){return xt(t)}function ia(t){return xt(t)&&xt(t.target)}function xt(t){return typeof t=="object"&&t!==null}function ea(t){return Rt(t.target.files).map(a=>dt(a))}async function ha(t){return (await Promise.all(t.map(r=>r.getFile()))).map(r=>dt(r))}async function da(t,a){if(t.items){let r=Rt(t.items).filter(l=>l.kind==="file");if(a!=="drop")return r;let o=await Promise.all(r.map(na));return A1(O1(o))}return A1(Rt(t.files).map(r=>dt(r)))}function A1(t){return t.filter(a=>ra.indexOf(a.name)===-1)}function Rt(t){if(t===null)return [];let a=[];for(let r=0;r<t.length;r++){let o=t[r];a.push(o);}return a}function na(t){if(typeof t.webkitGetAsEntry!="function")return R1(t);let a=t.webkitGetAsEntry();return a?.isDirectory?N1(a):R1(t)}function O1(t){return t.reduce((a,r)=>[...a,...Array.isArray(r)?O1(r):[r]],[])}function R1(t){let a=t.getAsFile();if(!a)return Promise.reject(`${t} is not a File`);let r=dt(a);return Promise.resolve(r)}async function ca(t){return t.isDirectory?N1(t):ga(t)}function N1(t){let a=t.createReader();return new Promise((r,o)=>{let l=[];function i(){a.readEntries(async e=>{if(e.length){let h=Promise.all(e.map(ca));l.push(h),i();}else try{let h=await Promise.all(l);r(h);}catch(h){o(h);}},e=>{o(e);});}i();})}async function ga(t){return new Promise((a,r)=>{t.file(o=>{let l=dt(o,t.fullPath);a(l);},o=>{r(o);});})}var Ot={enter:["dragenter","dragover","dragstart"],leave:["dragleave","drop"]},H1=[...Ot.enter,...Ot.leave];function E1({onDropped:t,onOver:a,onLeave:r}){let[o,l]=useState(false),i=useRef(null),e=useRef(false),h=useCallback(n=>{n.preventDefault(),n.stopPropagation();},[]),c=useCallback(async n=>{let s=Ot.enter.includes(n.type);a&&s!==o&&!e.current&&(a(await nt(n),n),e.current=true),l(s),s===false&&e.current&&(e.current=false,r?.());},[]),k=useCallback(async n=>{let s=await nt(n);t?.(s),e.current=false;},[t]),f=useCallback(async n=>{let s=await nt(n);t?.(s);},[t]);return useEffect(()=>{let n=i.current;return H1.forEach(s=>{n.addEventListener(s,h),n.addEventListener(s,c);}),n.addEventListener("drop",k),()=>{H1.forEach(s=>{n.removeEventListener(s,h),n.removeEventListener(s,c);}),n.removeEventListener("drop",k);}},[]),{ref:i,isOver:o,fromEvent:nt,onDropped:t,handleFileInputChange:f}}function ua(t,a={overrides:{},baseUrl:""}){return {body:`${a.baseUrl}/api/media/file/${t.path}`,path:t.path,name:t.path,size:t.size??0,type:t.mime_type??"",state:"uploaded",progress:0,...a.overrides}}function I1(t,a={overrides:{},baseUrl:""}){return t.map(r=>ua(r,a))}function Nt({maxItems:t,current:a=0,overwrite:r,added:o}){if(!t)return {reject:false,to_drop:0};let l=t-a,i=o>l?o:o-l>0?o-l:0;return {reject:r?o>t:l-o<0,to_drop:i}}var U1=()=>createStore(combine({files:[],isOver:false,isOverAccepted:false,uploading:false},(t,a)=>({setFiles:r=>t(({files:o})=>({files:r(o)})),getFilesLength:()=>a().files.length,setIsOver:(r,o)=>t({isOver:r,isOverAccepted:o}),setUploading:r=>t({uploading:r}),setIsOverAccepted:r=>t({isOverAccepted:r}),reset:()=>t({files:[],isOver:false,isOverAccepted:false}),addFile:r=>t(o=>({files:[...o.files,r]})),removeFile:r=>t(o=>({files:o.files.filter(l=>l.path!==r)})),removeAllFiles:()=>t({files:[]}),setFileProgress:(r,o)=>t(l=>({files:l.files.map(i=>i.path===r?{...i,progress:o}:i)})),setFileState:(r,o,l)=>t(i=>({files:i.files.map(e=>e.path===r?{...e,state:o,progress:l??e.progress}:e)})),overrideFile:(r,o)=>t(l=>({files:l.files.map(i=>i.path===r?{...i,...o}:i)}))})));function La(t){if(t&&t instanceof XMLHttpRequest){let a=JSON.parse(t.responseText);alert(`Upload failed with code ${t.status}: ${a.error}`);}else alert("Upload failed");}function K1({getUploadInfo:t,handleDelete:a,initialItems:r=[],flow:o="start",allowedMimeTypes:l,maxItems:i,overwrite:e,autoUpload:h,placeholder:c,onRejected:k,onDeleted:f,onUploadedAll:n,onUploaded:s,children:T,onClick:S,footer:v}){let m=useRef(U1()).current,b=useStore(m,d=>d.files),D=useStore(m,d=>d.setFiles),O=useStore(m,d=>d.getFilesLength),g=useStore(m,d=>d.setUploading),M=useStore(m,d=>d.setIsOver),x=useStore(m,d=>d.uploading),L=useStore(m,d=>d.setFileState),B=useStore(m,d=>d.overrideFile),I=useStore(m,d=>d.removeFile),V=useRef(null);useEffect(()=>{D(()=>r);},[r.length]);function X(d){return (Array.isArray(d)?d:[d]).map(j=>({kind:"kind"in j?j.kind:"file",type:j.type,size:"size"in j?j.size:0})).every(j=>j.kind!=="file"?(console.warn("file not accepted: not a file",j.kind),false):l&&l.length>0&&!isFileAccepted(d,l)?(console.warn("file not accepted: not allowed mimetype",j.type),false):true)}let u=useCallback(d=>{if(console.log("onDropped",d),!X(d))return;let A=d.length;D(R=>{let j=0;if(i){let z=Nt({maxItems:i,overwrite:e,added:A,current:R.length});if(z.reject)return k?k(d):console.warn("maxItems reached"),R;j=z.to_drop;}let Z=R.slice(j),gt=Z.map(z=>z.path),tt=d.filter(z=>!("path"in z)||z.path&&!gt.includes(z.path)).map(z=>({body:z,path:"path"in z?z.path:z.name,name:z.name,size:z.size,type:z.type,state:"pending",progress:0})),y=o==="start"?[...tt,...Z]:[...Z,...tt];return h&&tt.length>0&&setTimeout(()=>g(true),0),y});},[h,o,i,e]),{handleFileInputChange:N,ref:U}=E1({onDropped:d=>{console.log("onDropped",d),u(d);},onOver:d=>{if(!X(d)){M(true,false);return}let A=O(),R=Nt({maxItems:i,overwrite:e,added:d.length,current:A});console.log("--files in onOver",A,R),M(true,!R.reject);},onLeave:()=>{M(false,false);}});useEffect(()=>{console.log("files updated");},[b]),useEffect(()=>{x&&(async()=>{let d=b.filter(A=>A.state==="pending");if(d.length===0){g(false);return}else {let A=[];for(let R of d)try{let j=await K(R);A.push(j),s?.(j);}catch(j){La(j);}g(false),n?.(A);}})();},[x]);function K(d){return new Promise((A,R)=>{if(d.body){if(d.state!=="pending"){console.error("File is not pending"),R();return}else if(!(d.body instanceof File)){console.error("File body is not a File instance"),R();return}}else {console.error("File has no body"),R();return}let j=t({path:d.body.path});console.log("dropzone:uploadInfo",j);let{url:Z,headers:gt,method:tt="POST"}=j,y=new XMLHttpRequest;console.log("xhr:url",Z);let z=new URLSearchParams;e&&z.append("overwrite","1"),y.open(tt,String(Z)+"?"+String(z),true),gt&&gt.forEach((P,_)=>{y.setRequestHeader(_,P);}),y.upload.addEventListener("progress",P=>{if(console.log("progress",P.loaded,P.total),P.lengthComputable){L(d.path,"uploading",P.loaded/P.total);let _=P.loaded/P.total*100;console.log(`Progress: ${_.toFixed(2)}%`);}else console.log("Unable to compute progress information since the total size is unknown");}),y.onload=()=>{if(console.log("onload",d.path,y.status),y.status>=200&&y.status<300){console.log("Upload complete");try{let P=JSON.parse(y.responseText);console.log("Response:",d,P);let _={...P.state,progress:1,state:"uploaded"};B(d.path,_),A({...P,...d,..._});}catch(P){L(d.path,"uploaded",1),console.error("Error parsing response",P),R(P);}}else L(d.path,"failed",1),console.error("Upload failed with status: ",y.status,y.statusText),R(y);},y.onerror=()=>{console.error("Error during the upload process.");},y.onloadstart=()=>{L(d.path,"uploading",0),console.log("loadstart");},y.setRequestHeader("Accept","application/json");let Ut=new FormData;Ut.append("file",d.body),y.send(Ut);})}let ct=useCallback(async d=>{switch(console.log("deleteFile",d),d.state){case "uploaded":case "initial":window.confirm("Are you sure you want to delete this file?")&&(console.log('setting state to "deleting"',d),L(d.path,"deleting"),await a(d),I(d.path),f?.(d));break}},[]),J1=useCallback(async d=>{let A=await K(d);n?.([A]),s?.(A);},[]),$1=useCallback(()=>V.current?.click(),[V]),t0=useMemo(()=>!!(c?.show!==false&&(!i||i&&b.length<i)),[c,i,b.length]),wt=useMemo(()=>({store:m,wrapperRef:U,inputProps:{ref:V,type:"file",multiple:!i||i>1,onChange:N,accept:l?.join(",")},showPlaceholder:t0,actions:{uploadFile:J1,deleteFile:ct,openFileInput:$1,addFiles:u},dropzoneProps:{maxItems:i,placeholder:c,autoUpload:h,flow:o,allowedMimeTypes:l},onClick:S,footer:v}),[i,b.length,o,c,h,v,l]);return jsx(Q1.Provider,{value:wt,children:T?typeof T=="function"?T(wt):T:jsx(Z1,{...wt})})}var Q1=createContext(void 0);function bt(){return useContext(Q1)}var Bt=()=>{let{store:t}=bt(),a=useStore(t,i=>i.files),r=useStore(t,i=>i.isOver),o=useStore(t,i=>i.isOverAccepted),l=useStore(t,i=>i.uploading);return {files:a,isOver:r,isOverAccepted:o,uploading:l}},Q=(t,a)=>{let{store:r}=bt();return useStore(r,o=>{let l=typeof t=="string"?o.files.find(i=>i.path===t):o.files.find(i=>i.path===t.path);return l?a(l):void 0})};function Ba(t){if(t&&t instanceof XMLHttpRequest){let a=JSON.parse(t.responseText);alert(`Upload failed with code ${t.status}: ${a.error}`);}else alert("Upload failed");}var Z1=({wrapperRef:t,inputProps:a,showPlaceholder:r,actions:{uploadFile:o,deleteFile:l,openFileInput:i},dropzoneProps:{placeholder:e,flow:h,maxItems:c,allowedMimeTypes:k},onClick:f,footer:n})=>{let{files:s,isOver:T,isOverAccepted:S}=Bt(),v=r&&jsx(wa,{onClick:i,text:e?.text}),m=useCallback(async b=>{try{return await o(b)}catch(D){Ba(D);}},[o]);return jsxs("div",{ref:t,className:w("dropzone w-full h-full align-start flex flex-col select-none",T&&S&&"bg-green-200/10",T&&!S&&"bg-red-200/40 cursor-not-allowed"),children:[jsx("div",{className:"hidden",children:jsx("input",{...a})}),jsx("div",{className:"flex flex-1 flex-col",children:jsxs("div",{className:"flex flex-row flex-wrap gap-2 md:gap-3",children:[h==="start"&&v,s.map(b=>jsx(ma,{file:b,handleUpload:m,handleDelete:l,onClick:f},b.path)),h==="end"&&v,n]})})]})},wa=({onClick:t,text:a="Upload files"})=>jsx("div",{className:"w-[49%] aspect-square md:w-60 flex flex-col border-2 border-dashed border-muted relative justify-center items-center text-primary/30 hover:border-primary/30 hover:text-primary/50 hover:cursor-pointer hover:bg-muted/20 transition-colors duration-200",onClick:t,children:jsx("span",{className:"",children:a})}),Ta=({file:t,fallback:a,...r})=>t.type.startsWith("image/")?jsx(Fa,{...r,file:t}):t.type.startsWith("video/")?jsx(Sa,{...r,file:t}):a?a({file:t}):null,Et=memo(Ta,(t,a)=>t.file.path===a.file.path),ma=memo(({file:t,handleUpload:a,handleDelete:r,onClick:o})=>{S1();let i=Q(t,h=>{let{progress:c,...k}=h;return k});if(!i)return null;let e=useCallback(()=>{o&&o(i);},[o,i.path]);return jsxs("div",{className:w("w-[49%] md:w-60 aspect-square flex flex-col border border-muted relative hover:bg-primary/5 cursor-pointer transition-colors",i.state==="failed"&&"border-red-500 bg-red-200/20",i.state==="deleting"&&"opacity-70"),onClick:e,children:[jsx("div",{className:"absolute top-2 right-2",children:jsx(ja,{file:i,handleDelete:r,handleUpload:a})}),jsx(Wa,{file:i}),jsx("div",{className:"flex bg-primary/5 aspect-[1/0.78] overflow-hidden items-center justify-center",children:jsx(Et,{file:i,fallback:Da,className:"max-w-full max-h-full"})}),jsxs("div",{className:"flex flex-col px-1.5 py-1",children:[jsxs("div",{className:"flex flex-row gap-2 items-center",children:[jsx("p",{className:"truncate select-text w-[calc(100%-10px)]",children:i.name}),jsx(za,{file:i})]}),jsxs("div",{className:"flex flex-row justify-between text-xs md:text-sm font-mono opacity-50 text-nowrap gap-2",children:[jsx("span",{className:"truncate select-text",children:i.type}),jsx("span",{className:"whitespace-nowrap",children:formatNumber.fileSize(i.size)})]})]})]})},(t,a)=>t.file.path===a.file.path&&t.file.state===a.file.state),Wa=({file:t})=>{let a=Q(t.path,r=>({state:r.state,progress:r.progress}));return !a||a.state!=="uploading"?null:jsx("div",{className:"absolute w-full top-0 left-0 right-0 h-1",children:jsx("div",{className:"bg-blue-600 h-1 transition-all duration-75",style:{width:(a.progress*100).toFixed(0)+"%"}})})},ja=memo(({file:t,handleDelete:a,handleUpload:r})=>{let o=Q(t.path,i=>{let{progress:e,...h}=i;return h});if(!o)return null;let l=useMemo(()=>[o.state==="uploaded"&&typeof o.body=="string"&&{label:"Open",icon:n1,onClick:()=>{window.open(o.body,"_blank");}},["initial","uploaded"].includes(o.state)&&{label:"Delete",destructive:true,icon:C1,onClick:()=>a(o)},["initial","pending"].includes(o.state)&&{label:"Upload",icon:b1,onClick:()=>r(o)}],[o,a,r]);return jsx(P1,{items:l,position:"bottom-end",children:jsx(lt,{Icon:d1})})},(t,a)=>t.file.path===a.file.path),za=({file:t})=>{let a=Q(t.path,o=>o.state);if(!a||a==="uploaded")return null;let r={failed:"bg-red-500",deleting:"bg-orange-500 animate-pulse",uploading:"bg-blue-500 animate-pulse"}[a]??"bg-primary/50";return jsx("div",{className:"w-2 h-2 rounded-full mt-px "+r,title:a})},Fa=({file:t,...a})=>{let r=typeof t.body=="string"?t.body:URL.createObjectURL(t.body);return jsx("img",{...a,src:r})},Sa=({file:t,...a})=>{let r=typeof t.body=="string"?t.body:URL.createObjectURL(t.body);return jsx("video",{...a,src:r})},ya=[{mime:"text/plain",Icon:M1},{mime:"text/csv",Icon:s1},{mime:/(text|application)\/xml/,Icon:k1},{mime:"text/markdown",Icon:x1},{mime:/^text\/.*$/,Icon:p1},{mime:"application/json",Icon:f1},{mime:"application/pdf",Icon:u1},{mime:/^audio\/.*$/,Icon:L1},{mime:"application/zip",Icon:B1},{mime:"application/sql",Icon:v1}],Da=({file:t})=>{let a=ya.find(r=>r.mime instanceof RegExp?r.mime.test(t.type):r.mime===t.type);return a?jsx(a.Icon,{className:"size-10 text-gray-400"}):jsx("div",{className:"text-xs text-primary/50 text-center font-mono leading-none max-w-[90%] truncate",children:t.type})};function Y1({initialItems:t,media:a,entity:r,query:o,randomFilename:l,infinite:i=false,...e}){let h=useId(),c=useApi(),k=useInvalidate(),f=c.baseUrl,n=o?.limit??e.maxItems??50,s=B=>({limit:n,offset:B*n}),T=a?.entity_name??"media",S=(B,I=0)=>r?B.data.readManyByReference(r.name,r.id,r.field,{...s(I),...o}):B.data.readMany(T,{...s(I),...o}),v=i?useApiInfiniteQuery(S,{pageSize:n}):useApiQuery(S,{enabled:t!==false&&!t,revalidateOnFocus:false}),m=E(B=>({url:r?c.media.getEntityUploadUrl(r.name,r.id,r.field):c.media.getFileUploadUrl(l?void 0:B),headers:c.media.getUploadHeaders(),method:"POST"}));E(async()=>{await k(v.promise.key({search:false}));});let D=E(async B=>c.media.deleteFile(B.path)),O=t??(Array.isArray(v.data)?v.data:[])??[],g=I1(O,{baseUrl:f}),M=h+JSON.stringify(t),x="_data"in v?v._data?.[0]?.body.meta.count:void 0,L=0;return i&&"setSize"in v&&(L=typeof x=="number"?x:v.endReached?g.length:g.length+n,!x&&!v.isValidating&&n*v.size>=L&&(L=g.length)),jsx(K1,{getUploadInfo:m,handleDelete:D,autoUpload:true,initialItems:g,footer:i&&"setSize"in v&&jsx(Ua,{items:g.length,length:L,onFirstVisible:()=>v.setSize(v.size+1)}),...e},M)}var Ua=({items:t=0,length:a=0,onFirstVisible:r})=>{let{ref:o,inViewport:l}=useInViewport(),[i,e]=useState(0),h=useRef(-1);return useEffect(()=>{l&&t>h.current&&(h.current=t,e(k=>k+1),r());},[l]),a-t<=0?null:new Array(Math.max(a-t,0)).fill(0).map((k,f)=>jsx("div",{ref:f===0?o:void 0,className:"w-[49%] md:w-60 bg-muted aspect-square"},f))};var To={Dropzone:Y1,Preview:Et,useDropzone:bt,useDropzoneState:Bt,useDropzoneFileState:Q}; export{mr as Auth,To as Media,_t as NativeForm,Tt as useAuthStrategies,bt as useMediaDropzone,Q as useMediaDropzoneFileState,Bt as useMediaDropzoneState};