import{At as e,U as t}from"./dom-CdSnbvZ6.js";import{C as n}from"./settings-BF7JcItU.js";var r=`https://download.bareos.com/release-info/bareos-version-info.js`,i=`https://download.bareos.com/`,a=1e4,o=`Update information could not be retrieved`;function s(e){return String(e??``).toLowerCase().match(/[0-9]+|[a-z]+/g)??[]}function c(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r+=1){let n=e[r],i=t[r];if(n==null&&i==null)return 0;if(n==null)return-1;if(i==null)return 1;let a=/^[0-9]+$/.test(n),o=/^[0-9]+$/.test(i);if(a&&o){let e=Number(n)-Number(i);if(e!==0)return e>0?1:-1;continue}if(a!==o)return a?1:-1;if(n!==i)return n>i?1:-1}return 0}function l(e,t){return c(s(e),s(t))}function u(e){if(!e||typeof e!=`object`)throw Error(`Release metadata contains an invalid entry`);if(typeof e.version!=`string`||!e.version.trim())throw Error(`Release metadata entry misses its version`);return{version:e.version.trim(),status:typeof e.status==`string`&&e.status.trim()?e.status.trim():`unknown`,package_update_info:typeof e.package_update_info==`string`?e.package_update_info.trim():``}}function d(e){let t=String(e??``).trim();if(!t)throw Error(`Release metadata is empty`);let n;if(t.startsWith(`[`)||t.startsWith(`{`))n=JSON.parse(t);else{let e=t.match(/^\s*(?:[A-Za-z_$][\w$]*\s*)?\(([\s\S]*)\)\s*;?\s*$/);if(!e)throw Error(`Unexpected release metadata format`);n=JSON.parse(e[1])}let r=Array.isArray(n)?n:n?.versions;if(!Array.isArray(r))throw Error(`Release metadata does not contain a version list`);return r.map(u)}function f(e,t){if(!t)return null;for(let n of e)if(l(t,n.version)>=0)return{...n,requested_version:t};return null}function p(e,t=o){return{version:e??``,requested_version:e??``,status:`unknown`,package_update_info:t}}var m=n(`release-info`,()=>{let n=e([]),i=e(!1),s=e(null),c=e(null),l=null;async function u(e=!1){return!e&&n.value.length?n.value:l||(l=(async()=>{i.value=!0,s.value=null;let e=new AbortController,t=setTimeout(()=>e.abort(),a);try{let t=await fetch(r,{method:`GET`,mode:`cors`,cache:`no-store`,signal:e.signal});if(!t.ok)throw Error(`Release metadata request failed (${t.status})`);return n.value=d(await t.text()),c.value=Date.now(),n.value}catch(e){throw n.value=[],s.value=e?.name===`AbortError`?`Release metadata request timed out`:e?.message??String(e),e}finally{clearTimeout(t),i.value=!1,l=null}})(),l)}function m(e){return e?n.value.length?f(n.value,e)??p(e,`No release metadata matched this version`):p(e,s.value??o):p(``,`Version information is unavailable`)}return{entries:n,error:s,hasMetadata:t(()=>n.value.length>0),lastFetchedAt:c,loading:i,refresh:u,getVersionInfo:m}});export{m as n,i as t};