// @bun
var{defineProperty:I,getOwnPropertyNames:N,getOwnPropertyDescriptor:O}=Object,Q=Object.prototype.hasOwnProperty;function T(h){return this[h]}var W=(h)=>{var j=(J??=new WeakMap).get(h),k;if(j)return j;if(j=I({},"__esModule",{value:!0}),h&&typeof h==="object"||typeof h==="function"){for(var v of N(h))if(!Q.call(j,v))I(j,v,{get:T.bind(h,v),enumerable:!(k=O(h,v))||k.enumerable})}return J.set(h,j),j},J;var U=(h)=>h;function V(h,j){this[h]=U.bind(null,j)}var X=(h,j)=>{for(var k in j)I(h,k,{get:j[k],enumerable:!0,configurable:!0,set:V.bind(j,k)})};var Y=(h,j)=>()=>(h&&(j=h(h=0)),j);var Z=import.meta.require;function B(h){return{state:h,isGranted:h==="granted",isDenied:h==="denied",isPrompt:h==="prompt"}}function K(){return typeof navigator<"u"&&"permissions"in navigator}function L(h){let j=K(),k=B("prompt"),v=[],z=null,A=null,F=()=>{v.forEach((w)=>w(k))},H=()=>{if(z)k=B(z.state),F()},x=async()=>{if(!j)return B("prompt");try{return z=await navigator.permissions.query({name:h}),k=B(z.state),z.addEventListener("change",H),A=()=>{z?.removeEventListener("change",H)},k}catch{return B("prompt")}};return{get:()=>k,subscribe:(w)=>{if(v.length===0&&j)x();return v.push(w),w(k),()=>{if(v=v.filter((D)=>D!==w),v.length===0&&A)A(),A=null}},query:x,isSupported:()=>j}}function $(h){let j=K(),k={},v=[],z={},A=[];for(let x of h)k[x]=B("prompt"),z[x]=L(x);let F=()=>{v.forEach((x)=>x(k))};return{get:()=>k,subscribe:(x)=>{if(v.length===0)for(let w of h){let D=z[w].subscribe((M)=>{k[w]=M,F()});A.push(D)}return v.push(x),x(k),()=>{if(v=v.filter((w)=>w!==x),v.length===0)A.forEach((w)=>w()),A.length=0}},queryAll:async()=>{let x=await Promise.all(h.map(async(w)=>{let D=await z[w].query();return[w,D]}));return k=Object.fromEntries(x),k},isSupported:()=>j}}async function E(h){return(await L(h).query()).isGranted}async function g(){return E("camera")}async function C(){return E("microphone")}async function q(){return E("geolocation")}async function R(){return E("notifications")}async function y(h={video:!0,audio:!0}){if(typeof navigator>"u"||!navigator.mediaDevices)return{granted:!1,error:Error("MediaDevices API not supported")};try{return{granted:!0,stream:await navigator.mediaDevices.getUserMedia(h)}}catch(j){return{granted:!1,error:j instanceof Error?j:Error(String(j))}}}var G={media:["camera","microphone"],location:["geolocation"],notifications:["notifications","push"],sensors:["accelerometer","gyroscope","magnetometer"],clipboard:["clipboard-read","clipboard-write"]};export{$ as usePermissions,L as usePermission,y as requestMediaPermissions,G as permissionGroups,E as isPermissionGranted,R as hasNotificationPermission,C as hasMicrophonePermission,q as hasGeolocationPermission,g as hasCameraPermission};
