// @bun
var{defineProperty:F,getOwnPropertyNames:M,getOwnPropertyDescriptor:N}=Object,O=Object.prototype.hasOwnProperty;function Q(j){return this[j]}var V=(j)=>{var g=(H??=new WeakMap).get(j),q;if(g)return g;if(g=F({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var m of M(j))if(!O.call(g,m))F(g,m,{get:Q.bind(j,m),enumerable:!(q=N(j,m))||q.enumerable})}return H.set(j,g),g},H;var R=(j)=>j;function T(j,g){this[j]=R.bind(null,g)}var W=(j,g)=>{for(var q in g)F(j,q,{get:g[q],enumerable:!0,configurable:!0,set:T.bind(g,q)})};var X=(j,g)=>()=>(j&&(g=j(j=0)),g);var Y=import.meta.require;function D(){return typeof navigator<"u"&&"getBattery"in navigator}function U(){return{charging:!1,chargingTime:0,dischargingTime:0,level:1}}function _(){let j=D(),g=U(),q=[],m=null,E=!1,G=()=>{q.forEach((w)=>w(g))},x=()=>{if(m)g={charging:m.charging,chargingTime:m.chargingTime,dischargingTime:m.dischargingTime,level:m.level},G()},J=async()=>{if(E||!j)return;try{let w=navigator;if(w.getBattery)m=await w.getBattery(),g={charging:m.charging,chargingTime:m.chargingTime,dischargingTime:m.dischargingTime,level:m.level},m.addEventListener("chargingchange",x),m.addEventListener("chargingtimechange",x),m.addEventListener("dischargingtimechange",x),m.addEventListener("levelchange",x),E=!0,G()}catch{}},K=()=>{if(m)m.removeEventListener("chargingchange",x),m.removeEventListener("chargingtimechange",x),m.removeEventListener("dischargingtimechange",x),m.removeEventListener("levelchange",x),m=null;E=!1};return{get:()=>g,subscribe:(w)=>{if(q.length===0)J();return q.push(w),w(g),()=>{if(q=q.filter((L)=>L!==w),q.length===0)K()}},isSupported:()=>j,getPercentage:()=>Math.round(g.level*100),isLow:(w=0.2)=>g.level<=w&&!g.charging,isCritical:()=>g.level<=0.1&&!g.charging}}async function $(){if(!D())return null;try{let j=navigator;if(j.getBattery){let g=await j.getBattery();return Math.round(g.level*100)}}catch{}return null}async function k(){if(!D())return null;try{let j=navigator;if(j.getBattery)return(await j.getBattery()).charging}catch{}return null}function A(){return D()}export{_ as useBattery,k as isCharging,A as hasBattery,$ as getBatteryLevel};
