import{u as e}from"./BE2ewAd6.js";var t=`__empty__`,n=`__me__`;function r(){return{version:1}}function i(e){if(!e)return!1;if(e.text?.search&&e.text.search.trim())return!0;if(e.enum){for(let t of Object.values(e.enum))if(t&&t.length>0)return!0}if(e.date){for(let t of Object.values(e.date))if(t&&(`preset`in t&&t.preset||`from`in t&&(t.from||t.to)))return!0}return!1}function a(e){if(!e)return 0;let t=0;if(e.text?.search&&e.text.search.trim()&&t++,e.enum)for(let n of Object.values(e.enum))n&&n.length>0&&t++;if(e.date)for(let n of Object.values(e.date))n&&(`preset`in n&&n.preset||`from`in n&&(n.from||n.to))&&t++;return t}var o=e=>`sg-filters-${e}`,s=e=>`sg-tagfilter-${e}`,c=e=>`sg-listview-${e}`,l=e=>`sg-galleryview-${e}`,u=e=>`sg-calendarview-${e}`;function d(e){if(typeof localStorage>`u`)return r();let t=o(e);try{let e=localStorage.getItem(t);if(e){let t=JSON.parse(e);if(t&&t.version===1)return t}}catch{}let n=r(),i=!1;try{let t=localStorage.getItem(s(e));if(t){let e=JSON.parse(t);Array.isArray(e)&&e.length>0&&(n.enum={tags:[...e]},i=!0)}}catch{}let a=f(c(e))??f(l(e))??f(u(e));if(a&&(n.enum={...n.enum??{},entity_type:[a]},i=!0),i){try{localStorage.setItem(t,JSON.stringify(n))}catch{}try{localStorage.removeItem(s(e))}catch{}}return n}function f(e){try{let t=localStorage.getItem(e);if(!t)return null;let n=JSON.parse(t)?.selectedType;return typeof n==`string`&&n?n:null}catch{return null}}function p(e,t){if(!(typeof localStorage>`u`))try{i(t)?localStorage.setItem(o(e),JSON.stringify(t)):localStorage.removeItem(o(e))}catch{}}function m(e,t=new Date){let n=new Date(t.getFullYear(),t.getMonth(),t.getDate()),r=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;switch(e){case`past-due`:return{to:r(h(n,-1))};case`today`:return{from:r(n),to:r(n)};case`this-week`:{let e=h(n,-((n.getDay()+6)%7)),t=h(e,6);return{from:r(e),to:r(t)}}case`next-30d`:return{from:r(n),to:r(h(n,30))};case`next-90d`:return{from:r(n),to:r(h(n,90))}}}function h(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function g(e){if(e==null)return[];let t=[];if(Array.isArray(e))for(let n of e)n!=null&&t.push(..._(String(n)));else t.push(..._(String(e)));return t}function _(e){return e?e.replace(/\[\[|\]\]/g,``).split(`,`).map(e=>e.trim().split(`|`)[0].trim()).filter(Boolean):[]}function v(e,t){if(t===`entity_type`)return e.entityType;if(t===`folder`)return e.repo;let n=e.fields[t];return n==null||Array.isArray(n)?``:String(n)}function y(e,t){if(t===`created_at`)return e.createdAt??``;if(t===`updated_at`)return e.updatedAt??``;let n=e.fields[t];return n==null?``:String(n).slice(0,10)}function b(e,t,n){if(!i(t))return e;let r=t.text?.search?.trim().toLowerCase()??``,a=t.enum?Object.entries(t.enum).filter(([,e])=>e&&e.length>0):[],o=t.date?Object.entries(t.date).filter(([,e])=>e&&(`preset`in e&&e.preset||`from`in e&&(e.from||e.to))):[];return e.filter(e=>{if(r&&!e.title.toLowerCase().includes(r))return!1;for(let[t,r]of a)if(!x(e,t,r,n))return!1;for(let[t,n]of o)if(!S(e,t,n))return!1;return!0})}function x(n,r,i,a){let o=i.includes(t),s=r===`assignee`&&i.includes(`__me__`),c=i.filter(e=>e!==`__empty__`&&e!==`__me__`);if(s&&a.currentUserPersonId&&c.push(a.currentUserPersonId),r===`tags`){let e=n.fields.tags,t=Array.isArray(e)?e.map(e=>String(e).trim()).filter(Boolean):[];return t.length===0?o:c.length===0?!1:t.some(e=>c.includes(e))}if(r!==`entity_type`&&r!==`folder`&&!e(n.entityType,r))return!1;if(a.wikilinkKeys.has(r)){let e=g(n.fields[r]);return e.length===0?o:c.length===0?!1:e.some(e=>c.includes(e))}let l=v(n,r);return l?c.length===0?!1:c.includes(l):o}function S(t,n,r){if(!e(t.entityType,n))return!1;let i=y(t,n),a=`preset`in r?m(r.preset):{from:r.from,to:r.to};return!(!i||a.from&&i<a.from||a.to&&i>a.to)}export{g as a,p as c,a as i,n,d as o,b as r,v as s,t};