import m from"picomatch";import{removeTrailingSlash as a}from"../../../../utils/url/remove-trailing-slash";import{normalizeRouteSlug as h}from"../../../../utils/path/normalize-route-slug";const l={};function f(t){const e=t.trim();return e===""||e==="**"||e==="/**"}function p(t){const e=t.trim();if(f(e))return"**";let i=e.toLowerCase();return i.startsWith("/")&&(i=i.slice(1)),i.endsWith("/")&&!i.endsWith("*/")&&(i=i.slice(0,-1)),i}function g(t){return l[t]||(l[t]=m(t,{nocase:!0})),l[t]}const s={CatchAll:0,DoubleWildcard:1,SingleWildcard:2,ExactMatch:3};function S(t){if(!t||f(t))return{tier:s.CatchAll,literalSegments:0};const e=t.trim().split("/").filter(i=>!i.includes("*")&&i.trim()!=="").length;return t.includes("*")?t.includes("**")?{tier:s.DoubleWildcard,literalSegments:e}:{tier:s.SingleWildcard,literalSegments:e}:{tier:s.ExactMatch,literalSegments:e}}function W(t,e){return t.tier!==e.tier?t.tier-e.tier:t.literalSegments-e.literalSegments}function u(t){if(!t)return;const e=Date.parse(t);return Number.isNaN(e)?void 0:e}function x(t,e=Date.now()){const i=u(t.startAt);if(i!==void 0&&e<i)return!1;const r=u(t.endAt);return!(r!==void 0&&e>=r)}function w(t,e=Date.now()){return t.flatMap(i=>[u(i.startAt),u(i.endAt)]).filter(i=>i!==void 0&&i>e).sort((i,r)=>i-r)[0]}function T(t,e){if(!e||f(e))return!0;const i=a(h(t)).toLowerCase(),r=i.startsWith("/")?i.slice(1):i,n=p(e);if(!n.includes("*")){const c=n.startsWith("/")?n.slice(1):n;return r===a(c)}if(n.endsWith("**")){const c=a(n.slice(0,-2));if(r===c)return!0}return g(n)(r)}function y(t,e,i=new Set,r=Date.now()){if(!t||t.length===0)return;let n,c;for(const o of t){if(i.has(o.hash)||!x(o,r)||!T(e,o.target))continue;const d=S(o.target);(!c||W(d,c)>0)&&(c=d,n=o)}return n}export{s as SpecificityTier,W as compareSpecificity,y as getBannerForSlug,w as getNextBannerTransition,S as getTargetSpecificity,x as isBannerWithinTimeRange,T as matchesBannerTarget};
