mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-24 18:08:19 +03:00
1 line
147 KiB
JavaScript
1 line
147 KiB
JavaScript
var $n=Object.defineProperty;var An=(e,t,r)=>t in e?$n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var T=(e,t,r)=>(An(e,typeof t!="symbol"?t+"":t,r),r);import{j as xs,o as Pn,l as Xr,r as Qt,i as Ce,a as H,u as Z,b as v,c as Fe,v as Ls,d as Bn,e as x,N as jn,f as Gn,L as $,g as Hn,F as y,h as Wn,C as qn,k as Jr,m as zn,n as Yr,p as Qn,q as Kn,s as Xn,t as Jn,w as We,x as Y,R as Q,y as Es,E as ae,z as Yn,A as Zr,B as Se,D as O,G as Is,H as ea,I as Kt,J as ys,K as rt,M as at,O as Zn,P as Xt,Q as F,S as Fs,T as ei,U as ta,V as ti,W as sa,X as si,Y as ri,Z as ra,_ as V,$ as W,a0 as ai,a1 as aa,a2 as qe,a3 as Ve,a4 as Ie,a5 as ni,a6 as pe,a7 as ii,a8 as oi,a9 as Ns,aa as Jt,ab as Vs,ac as Ms,ad as na,ae as Os,af as ci,ag as li,ah as di,ai as b,aj as Yt,ak as Bt,al as hi,am as ui,an as $s,ao as mi,ap as ee,aq as gi,ar as pi,as as vi,at as ia,au as fi,av as oa,aw as ca,ax as Be,ay as je,az as la,aA as da,aB as Ci,aC as Si,aD as yi,aE as ie,aF as nt,aG as L,aH as Ni,aI as As,aJ as bi,aK as hr,aL as it,aM as Ri,aN as wi,aO as Ps,aP as Bs,aQ as Di,aR as js,aS as de,aT as ye,aU as he,aV as ze,aW as bs,aX as _i,aY as Me,aZ as Ui,a_ as ki,a$ as Ti,b0 as ne,b1 as ot,b2 as ha,b3 as ua,b4 as xi,b5 as ur,b6 as Li,b7 as Ei,b8 as Ii,b9 as Fi,ba as jt,bb as Vi,bc as Je,bd as ma,be as Mi,bf as Oi,bg as $i,bh as Ai,bi as Pi,bj as Bi,bk as ji,bl as Gi,bm as Hi,bn as Wi,bo as qi,bp as ga,bq as Rs,br as pa,bs as os,bt as ws,bu as va,bv as zi,bw as fa,bx as Qi,by as Ki,bz as Xi,bA as Ji,bB as Yi,bC as mr,bD as Ca,bE as Zi,bF as Ds,bG as eo,bH as to,bI as so,bJ as ro,bK as ao,bL as no,bM as io,bN as oo,bO as co,bP as lo,bQ as ho,bR as uo,bS as mo,bT as Sa,bU as go,bV as po,bW as vo,bX as fo,bY as Co,bZ as So,b_ as yo,b$ as No,c0 as bo,c1 as Ro,c2 as wo,c3 as Do,c4 as _o,c5 as ya,c6 as Uo,c7 as gr,c8 as ko,c9 as To,ca as xo,cb as Lo,cc as Eo,cd as Io}from"./vendor-7d10c334.js";import"./__commonjsHelpers__-042e6b4d.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))a(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const c of i.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&a(c)}).observe(document,{childList:!0,subtree:!0});function r(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerpolicy&&(i.referrerPolicy=n.referrerpolicy),n.crossorigin==="use-credentials"?i.credentials="include":n.crossorigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function a(n){if(n.ep)return;n.ep=!0;const i=r(n);fetch(n.href,i)}})();const w=xs.Fragment,s=xs.jsx,o=xs.jsxs,Fo="shlink-web-client",Vo="A React-based progressive web application for shlink",Mo="/shlink-web-client/feature/chunk-split",Oo="https://github.com/shlinkio/shlink-web-client",$o="MIT",Ao={lint:"npm run lint:css && npm run lint:js","lint:css":"stylelint src/*.scss src/**/*.scss","lint:js":"eslint --ext .js,.ts,.tsx src test","lint:fix":"npm run lint:css:fix && npm run lint:js:fix","lint:css:fix":"npm run lint:css -- --fix","lint:js:fix":"npm run lint:js -- --fix",start:"vite serve --host=0.0.0.0",build:"tsc --noEmit && vite build && node scripts/replace-version.mjs","build:dist":"npm run build && node scripts/create-dist-file.mjs","build:serve":"serve -p 5000 ./build",test:"jest --env=jsdom --colors","test:coverage":"npm run test -- --coverage --coverageReporters=text --coverageReporters=text-summary","test:ci":"npm run test:coverage -- --coverageReporters=clover --ci","test:pretty":"npm run test:coverage -- --coverageReporters=html","test:verbose":"npm run test -- --verbose",mutate:"./node_modules/.bin/stryker run --concurrency 4 --ignoreStatic"},Po={"@babel/preset-env":"^7.20.2","@babel/preset-react":"^7.18.6","@babel/preset-typescript":"^7.18.6","@fortawesome/fontawesome-free":"^6.2.1","@fortawesome/fontawesome-svg-core":"^6.2.1","@fortawesome/free-regular-svg-icons":"^6.2.1","@fortawesome/free-solid-svg-icons":"^6.2.1","@fortawesome/react-fontawesome":"^0.2.0","@json2csv/plainjs":"^6.1.2","@reduxjs/toolkit":"^1.9.1",bootstrap:"^5.2.3",bottlejs:"^2.0.1",bowser:"^2.11.0","chart.js":"^4.1.1",classnames:"^2.3.2","compare-versions":"^5.0.3",csvtojson:"^2.0.10","date-fns":"^2.29.3","event-source-polyfill":"^1.0.31",history:"^5.3.0",leaflet:"^1.9.3",qs:"^6.11.0",ramda:"^0.27.2",react:"^18.2.0","react-chartjs-2":"^5.1.0","react-colorful":"^5.6.1","react-copy-to-clipboard":"^5.1.0","react-datepicker":"^4.8.0","react-dom":"^18.2.0","react-external-link":"^2.0.0","react-leaflet":"^4.2.0","react-redux":"^8.0.5","react-router-dom":"^6.6.1","react-swipeable":"^7.0.0","react-tag-autocomplete":"^6.3.0",reactstrap:"^9.1.5",redux:"^4.2.0","redux-localstorage-simple":"^2.5.1","redux-thunk":"^2.4.2",uuid:"^8.3.2","workbox-core":"^6.5.4","workbox-expiration":"^6.5.4","workbox-precaching":"^6.5.4","workbox-routing":"^6.5.4","workbox-strategies":"^6.5.4"},Bo={"@shlinkio/eslint-config-js-coding-standard":"~2.0.2","@shlinkio/stylelint-config-css-coding-standard":"~1.0.1","@stryker-mutator/core":"^6.3.1","@stryker-mutator/jest-runner":"^6.3.1","@stryker-mutator/typescript-checker":"^6.3.1","@testing-library/jest-dom":"^5.16.5","@testing-library/react":"^13.4.0","@testing-library/user-event":"^14.4.3","@types/jest":"^29.2.4","@types/json2csv":"^5.0.3","@types/leaflet":"^1.9.0","@types/qs":"^6.9.7","@types/ramda":"^0.28.15","@types/react":"^18.0.26","@types/react-color":"^3.0.6","@types/react-copy-to-clipboard":"^5.0.4","@types/react-datepicker":"^4.8.0","@types/react-dom":"^18.0.10","@types/react-tag-autocomplete":"^6.3.0","@types/uuid":"^8.3.4","@vitejs/plugin-react":"^3.0.0","adm-zip":"^0.5.10","babel-jest":"^29.3.1",chalk:"^5.2.0",eslint:"^8.30.0","identity-obj-proxy":"^3.0.0",jest:"^29.3.1","jest-canvas-mock":"^2.4.0","jest-environment-jsdom":"^29.3.1","resize-observer-polyfill":"^1.5.1",sass:"^1.57.1",serve:"^14.1.2","stryker-cli":"^1.0.2",stylelint:"^14.16.0","ts-mockery":"^1.2.0",typescript:"^4.9.4",vite:"^4.0.3","vite-plugin-chunk-split":"^0.4.7","vite-plugin-pwa":"^0.14.0"},jo=[">0.2%","not dead","not ie <= 11","not op_mini all"],Gt={name:Fo,description:Vo,private:!1,homepage:Mo,repository:Oo,license:$o,scripts:Ao,dependencies:Po,devDependencies:Bo,browserslist:jo},Gs=e=>!!(e!=null&&e.url)&&!!(e!=null&&e.apiKey),ge=e=>!!(e!=null&&e.id),Zt=e=>!!(e!=null&&e.version),Go=e=>!!(e!=null&&e.serverNotFound),lt=e=>ge(e)?e.id:"",Ho=e=>Pn(["id","autoConnect"],e),es=(e,t,r)=>e!==t?"ASC":r?{ASC:"DESC",DESC:void 0}[r]:"ASC",Na=(e,{field:t,dir:r})=>!t||!r?e:e.sort((a,n)=>{const i=r==="ASC"?1:-1,c=r==="ASC"?-1:1;return a[t]>n[t]?i:c}),ba=e=>e.dir?`${e.field}-${e.dir}`:void 0,Wo=e=>{const[t,r]=e.split("-");return{field:t,dir:r}};var ts=(e=>(e.INVALID_ARGUMENT="INVALID_ARGUMENT",e.INVALID_SHORT_URL_DELETION="INVALID_SHORT_URL_DELETION",e.DOMAIN_NOT_FOUND="DOMAIN_NOT_FOUND",e.FORBIDDEN_OPERATION="FORBIDDEN_OPERATION",e.INVALID_URL="INVALID_URL",e.INVALID_SLUG="INVALID_SLUG",e.INVALID_SHORTCODE="INVALID_SHORTCODE",e.TAG_CONFLICT="TAG_CONFLICT",e.TAG_NOT_FOUND="TAG_NOT_FOUND",e.MERCURE_NOT_CONFIGURED="MERCURE_NOT_CONFIGURED",e.INVALID_AUTHORIZATION="INVALID_AUTHORIZATION",e.INVALID_API_KEY="INVALID_API_KEY",e.NOT_FOUND="NOT_FOUND",e))(ts||{}),ss=(e=>(e.INVALID_ARGUMENT="https://shlink.io/api/error/invalid-data",e.INVALID_SHORT_URL_DELETION="https://shlink.io/api/error/invalid-short-url-deletion",e.DOMAIN_NOT_FOUND="https://shlink.io/api/error/domain-not-found",e.FORBIDDEN_OPERATION="https://shlink.io/api/error/forbidden-tag-operation",e.INVALID_URL="https://shlink.io/api/error/invalid-url",e.INVALID_SLUG="https://shlink.io/api/error/non-unique-slug",e.INVALID_SHORTCODE="https://shlink.io/api/error/short-url-not-found",e.TAG_CONFLICT="https://shlink.io/api/error/tag-conflict",e.TAG_NOT_FOUND="https://shlink.io/api/error/tag-not-found",e.MERCURE_NOT_CONFIGURED="https://shlink.io/api/error/mercure-not-configured",e.INVALID_AUTHORIZATION="https://shlink.io/api/error/missing-authentication",e.INVALID_API_KEY="https://shlink.io/api/error/invalid-api-key",e.NOT_FOUND="https://shlink.io/api/error/not-found",e))(ss||{});const qo=e=>!!e&&typeof e=="object"&&["type","detail","title","status"].every(t=>t in e),oe=e=>qo(e)?e:void 0,zo=e=>(e==null?void 0:e.type)===ts.INVALID_ARGUMENT||(e==null?void 0:e.type)===ss.INVALID_ARGUMENT,Qo=e=>(e==null?void 0:e.type)==="INVALID_SHORTCODE_DELETION"||(e==null?void 0:e.type)===ts.INVALID_SHORT_URL_DELETION||(e==null?void 0:e.type)===ss.INVALID_SHORT_URL_DELETION,Ko=e=>((e==null?void 0:e.type)===ts.NOT_FOUND||(e==null?void 0:e.type)===ss.NOT_FOUND)&&(e==null?void 0:e.status)===404,Qe=e=>Xr.parse(e,{ignoreQueryPrefix:!0}),dt=e=>Xr.stringify(e,{arrayFormat:"brackets"}),Xo=(e,t)=>`${e}/rest/v${t}`,Jo=Qt(Ce),Yo=({orderBy:e={},excludeMaxVisitsReached:t,excludePastValidUntil:r,...a})=>({...a,excludeMaxVisitsReached:t===!0?"true":void 0,excludePastValidUntil:r===!0?"true":void 0,orderBy:ba(e)});class Zo{constructor(t,r,a){T(this,"apiVersion");T(this,"listShortUrls",async(t={})=>this.performRequest("/short-urls","GET",Yo(t)).then(({shortUrls:r})=>r));T(this,"createShortUrl",async t=>{const r=Qt(a=>H(a)||Ce(a),t);return this.performRequest("/short-urls","POST",{},r)});T(this,"getShortUrlVisits",async(t,r)=>this.performRequest(`/short-urls/${t}/visits`,"GET",r).then(({visits:a})=>a));T(this,"getTagVisits",async(t,r)=>this.performRequest(`/tags/${t}/visits`,"GET",r).then(({visits:a})=>a));T(this,"getDomainVisits",async(t,r)=>this.performRequest(`/domains/${t}/visits`,"GET",r).then(({visits:a})=>a));T(this,"getOrphanVisits",async t=>this.performRequest("/visits/orphan","GET",t).then(({visits:r})=>r));T(this,"getNonOrphanVisits",async t=>this.performRequest("/visits/non-orphan","GET",t).then(({visits:r})=>r));T(this,"getVisitsOverview",async()=>this.performRequest("/visits").then(({visits:t})=>t));T(this,"getShortUrl",async(t,r)=>this.performRequest(`/short-urls/${t}`,"GET",{domain:r}));T(this,"deleteShortUrl",async(t,r)=>this.performEmptyRequest(`/short-urls/${t}`,"DELETE",{domain:r}));T(this,"updateShortUrl",async(t,r,a)=>this.performRequest(`/short-urls/${t}`,"PATCH",{domain:r},a));T(this,"listTags",async()=>this.performRequest("/tags","GET",{withStats:"true"}).then(({tags:t})=>t).then(({data:t,stats:r})=>({tags:t,stats:r})));T(this,"deleteTags",async t=>this.performEmptyRequest("/tags","DELETE",{tags:t}).then(()=>({tags:t})));T(this,"editTag",async(t,r)=>this.performEmptyRequest("/tags","PUT",{},{oldName:t,newName:r}).then(()=>({oldName:t,newName:r})));T(this,"health",async()=>this.performRequest("/health","GET"));T(this,"mercureInfo",async()=>this.performRequest("/mercure-info","GET"));T(this,"listDomains",async()=>this.performRequest("/domains").then(({domains:t})=>t));T(this,"editDomainRedirects",async t=>this.performRequest("/domains/redirects","PATCH",{},t));T(this,"performRequest",async(t,r="GET",a={},n)=>this.httpClient.fetchJson(...this.toFetchParams(t,r,a,n)).catch(this.handleFetchError(()=>this.httpClient.fetchJson(...this.toFetchParams(t,r,a,n)))));T(this,"performEmptyRequest",async(t,r="GET",a={},n)=>this.httpClient.fetchEmpty(...this.toFetchParams(t,r,a,n)).catch(this.handleFetchError(()=>this.httpClient.fetchEmpty(...this.toFetchParams(t,r,a,n)))));T(this,"toFetchParams",(t,r,a={},n)=>{const i=dt(Jo(a)),c=H(i)?"":`?${i}`;return[`${Xo(this.baseUrl,this.apiVersion)}${t}${c}`,{method:r,body:n&&JSON.stringify(n),headers:{"X-Api-Key":this.apiKey}}]});T(this,"handleFetchError",t=>r=>{if(!Ko(oe(r)))throw r;return this.apiVersion=2,t()});this.httpClient=t,this.baseUrl=r,this.apiKey=a,this.apiVersion=3}}const cs={},ec=e=>typeof e=="function",tc=e=>{const{selectedServer:t}=e();if(!Gs(t))throw new Error("There's no selected server or it is not found");return t},sc=e=>t=>{const{url:r,apiKey:a}=ec(t)?tc(t):t,n=`${r}_${a}`;return cs[n]||(cs[n]=new Zo(e,r,a)),cs[n]},rc=e=>{e.serviceFactory("buildShlinkApiClient",sc,"HttpClient")},ac=({children:e})=>{const t=Z();return v.useEffect(()=>{scrollTo(0,0)},[t]),s(w,{children:e})},nc=2e3,ic=(e,t)=>(r=!1,a=nc)=>{const[n,i]=v.useState(r),c=v.useRef(void 0);return[n,()=>{i(!r),c.current&&t(c.current),c.current=e(()=>i(r),a)}]},A=(e=!1)=>{const[t,r]=v.useState(e);return[t,()=>r(!t),()=>r(!0),()=>r(!1)]},oc=(e,t)=>{const r=a=>n=>{n.event.composedPath().some(({classList:c})=>c==null?void 0:c.contains("visits-table"))||document.querySelector(".modal")||a()};return Bn({delta:40,onSwipedLeft:r(t),onSwipedRight:r(e)})},cc=(e,t)=>{const[r,a]=v.useState(t);return[r,i=>{const{location:c,history:l}=window,d=Qe(c.search);d[e]=i,l.pushState(null,"",`${c.pathname}?${dt(d)}`),a(i)}]},lc=(e,t)=>{const r=v.useRef(!0);v.useEffect(()=>{!r.current&&e(),r.current=!1},t)},Ne=()=>{const e=Fe();return()=>e(-1)},rs=()=>{const{current:e}=v.useRef(`dom-${Ls()}`);return e},Hs="#4696e5",dc="rgba(70, 150, 229, 0.4)",Ra="#f77f28",hc="rgba(247, 127, 40, 0.4)",uc="white",mc="#161b22",wa=e=>{var t,r;return(r=(t=document.getElementsByTagName("html"))==null?void 0:t[0])==null?void 0:r.setAttribute("data-theme",e)},gc=()=>{var e,t;return((t=(e=document.getElementsByTagName("html"))==null?void 0:e[0])==null?void 0:t.getAttribute("data-theme"))==="dark"},Da=({color:e=Hs,className:t})=>s("svg",{className:t,viewBox:"0 0 512 512",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:o("g",{fill:e,children:[s("path",{d:" M 23.71 85.08 C 17.22 49.81 49.44 14.86 85.08 18.12 C 118.83 19.21 145.72 53.33 139.45 86.37 C 155.64 102.30 171.32 118.83 187.87 134.36 C 198.32 111.73 208.84 89.12 219.57 66.62 C 226.05 53.84 243.47 48.74 255.73 56.27 C 263.76 62.10 270.34 69.69 277.25 76.75 C 286.28 86.61 285.72 102.89 276.31 112.31 C 223.38 165.37 170.38 218.37 117.35 271.34 C 107.72 280.99 91.01 281.25 81.11 271.86 C 74.39 264.94 66.82 258.69 61.24 250.77 C 53.72 238.52 58.85 221.07 71.64 214.62 C 94.11 203.87 116.72 193.38 139.33 182.91 C 123.81 166.36 107.30 150.68 91.37 134.49 C 60.20 140.28 27.37 116.78 23.71 85.08 Z"}),s("path",{d:" M 205.21 201.23 C 225.32 181.36 260.88 181.11 281.14 200.86 C 299.25 218.75 317.37 236.65 335.10 254.93 C 356.73 278.01 352.01 318.70 326.03 336.56 C 320.07 330.47 313.73 324.65 308.12 318.28 C 323.86 309.39 328.76 286.18 316.63 272.39 C 301.73 256.95 286.30 242.03 271.24 226.75 C 264.49 219.65 256.80 212.00 246.37 211.52 C 224.65 208.64 205.52 233.36 214.49 253.58 C 221.09 266.81 234.22 275.12 243.62 286.24 C 240.43 295.96 238.09 306.13 238.29 316.46 C 225.55 304.29 213.16 291.73 200.89 279.09 C 180.97 257.57 183.10 220.45 205.21 201.23 Z"}),s("path",{d:" M 273.90 352.07 C 252.28 328.99 256.98 288.31 282.96 270.46 C 288.93 276.54 295.26 282.36 300.88 288.72 C 285.14 297.62 280.23 320.82 292.38 334.61 C 307.27 350.05 322.70 364.96 337.75 380.25 C 344.51 387.35 352.20 395.00 362.64 395.48 C 384.35 398.37 403.49 373.64 394.51 353.42 C 387.92 340.18 374.78 331.88 365.38 320.76 C 368.56 311.04 370.91 300.86 370.71 290.54 C 383.45 302.70 395.84 315.27 408.11 327.91 C 428.03 349.43 425.90 386.55 403.78 405.77 C 383.68 425.64 348.13 425.89 327.86 406.14 C 309.75 388.25 291.60 370.37 273.90 352.07 Z"}),s("path",{d:" M 422.11 403.83 C 431.96 394.07 441.60 384.06 451.66 374.51 C 460.90 383.74 471.89 392.70 474.89 406.11 C 480.16 429.97 484.08 454.13 488.76 478.12 C 490.00 483.41 484.47 488.29 479.35 486.63 C 454.66 481.52 429.55 478.12 405.14 471.84 C 393.17 467.97 385.20 457.75 376.55 449.27 C 386.39 439.49 396.13 429.60 406.06 419.91 C 416.37 433.45 435.74 414.00 422.11 403.83 Z"})]})});const pc=e=>()=>{const[t,r,,a]=A(),n=Z(),{pathname:i}=n;v.useEffect(a,[n]);const c="/settings",l=x("main-header__toggle-icon",{"main-header__toggle-icon--opened":t});return o(jn,{color:"primary",dark:!0,fixed:"top",className:"main-header",expand:"md",children:[o(Gn,{tag:$,to:"/",children:[s(Da,{className:"main-header__brand-logo",color:"white"})," Shlink"]}),s(Hn,{onClick:r,children:s(y,{icon:Wn,className:l})}),s(qn,{navbar:!0,isOpen:t,children:o(Jr,{navbar:!0,className:"ms-auto",children:[s(zn,{children:o(Yr,{tag:$,to:c,active:i.startsWith(c),children:[s(y,{icon:Qn})," Settings"]})}),s(e,{})]})})]})};const vc=({id:e,name:t})=>o(Xn,{tag:$,to:`/server/${e}`,className:"servers-list__server-item",children:[t,s(y,{icon:Jn,className:"servers-list__server-item-icon"})]}),_a=({servers:e,children:t,embedded:r=!1})=>o(w,{children:[t&&s("h5",{className:"mb-md-3",children:t}),e.length>0&&s(Kn,{className:x("servers-list__list-group",{"servers-list__list-group--embedded":r}),children:e.map(({id:a,name:n})=>s(vc,{id:a,name:n},a))})]});const fc=({servers:e})=>{const t=Fe(),r=We(e),a=!H(r);return v.useEffect(()=>{const n=r.find(({autoConnect:i})=>i);n&&t(`/server/${n.id}`)},[]),s("div",{className:"home",children:s(Y,{className:"home__main-card",children:o(Q,{className:"g-0",children:[s("div",{className:"col-md-5 d-none d-md-block",children:s("div",{className:"home__logo-wrapper",children:s("div",{className:"home__logo",children:s(Da,{})})})}),o("div",{className:"col-md-7 home__servers-container",children:[s("div",{className:"home__title-wrapper",children:s("h1",{className:"home__title",children:"Welcome!"})}),s(_a,{embedded:!0,servers:r,children:!a&&o("div",{className:"p-4 text-center",children:[s("p",{className:"mb-5",children:"This application will help you manage your Shlink servers."}),s("p",{children:o($,{to:"/server/create",className:"btn btn-outline-primary btn-lg me-2",children:[s(y,{icon:Es})," ",s("span",{className:"ms-1",children:"Add a server"})]})}),s("p",{className:"mb-0 mt-5",children:s(ae,{href:"https://shlink.io/documentation",children:o("small",{children:[s("span",{className:"me-1",children:"Learn more about Shlink"})," ",s(y,{icon:Yn})]})})})]})})]})]})})})},Cc=e=>({error:"border-danger",default:""})[e],Sc=e=>({error:"text-danger",default:"text-muted"})[e],ce=({className:e,children:t,loading:r=!1,type:a="default",fullWidth:n=!1})=>{const i=x({"col-md-12":n,"col-md-10 offset-md-1":!n});return s(Q,{className:x("g-0",e),children:s("div",{className:i,children:s(Y,{className:Cc(a),body:!0,children:o("h3",{className:x("text-center mb-0",Sc(a)),children:[r&&s(y,{icon:Zr,spin:!0}),r&&s("span",{className:"ms-2",children:t??"Loading..."}),!r&&t]})})})})};const Ke=({children:e})=>s("div",{className:"no-menu-wrapper container-xl",children:e});function Ua(e,t){return r=>{const a=Se(),{selectServer:n,selectedServer:i}=r;return v.useEffect(()=>{a.serverId&&n(a.serverId)},[a.serverId]),i?Go(i)?s(t,{}):s(e,{...r}):s(Ke,{children:s(ce,{loading:!0})})}}const Ws=(e,t,r=1)=>Is(r,e+1).map(t),se=e=>!Ce(e)&&!H(e),ht=e=>O(t=>t.preventDefault(),e),ls=e=>H(e)?null:e,Te=e=>t=>e===t,ka=e=>e?"true":"false",ds=e=>e===void 0?void 0:ka(e),yc=(e,{maxVersion:t,minVersion:r})=>{if(!se(e))return!1;const a=!r||ys(e,r,">=");return(!t||ys(e,t,"<="))&&a},Ta=ea(Kt,e=>{try{return ys(e,e,"=")}catch{return!1}}),xa=e=>Ta(e)?`v${e}`:e,La=(e="latest")=>t=>Ta(t)?t:e,ut=e=>t=>Zt(t)&&yc(t.version,{minVersion:e}),Ea=ut("2.9.0"),Nc=Ea,bc=ut("2.10.0"),qs=ut("3.0.0"),Rc=qs,Ia=ut("3.1.0"),Fa=ut("3.4.0"),wc=Fa,j=({title:e,children:t,bodyClassName:r,...a})=>o(Y,{...a,children:[e&&s(rt,{role:"heading",children:e}),s(at,{className:r,children:t})]}),Va=({to:e="/",children:t="Home"})=>s("div",{className:"home",children:o(j,{className:"p-4",children:[s("h2",{children:"Oops! We could not find requested route."}),s("p",{children:"Use your browser's back button to navigate to the page you have previously come from, or just press this button."}),s("br",{}),s($,{to:e,className:"btn btn-outline-primary btn-lg",children:t})]})});const Dc=(e,t,r,a,n,i,c,l,d,h,u,p,m)=>Ua(({selectedServer:g,sidebarNotPresent:f,sidebarPresent:C})=>{const R=Z(),[_,N,D,S]=A(),U=Zt(g);if(v.useEffect(()=>S(),[R]),v.useEffect(()=>(U&&C(),()=>f()),[]),!U)return s(h,{});const B=qs(g),I=Ia(g),k=x("menu-layout__burger-icon",{"menu-layout__burger-icon--active":_}),E=oc(D,S);return o(w,{children:[s(y,{icon:Zn,className:k,onClick:N}),s("div",{...E,className:"menu-layout__swipeable",children:o("div",{className:"menu-layout__swipeable-inner",children:[s(r,{selectedServer:g,showOnMobile:_}),s("div",{className:"menu-layout__container",onClick:()=>S(),children:s("div",{className:"container-xl",children:o(Xt,{children:[s(F,{index:!0,element:s(Fs,{replace:!0,to:"overview"})}),s(F,{path:"/overview",element:s(u,{})}),s(F,{path:"/list-short-urls/:page",element:s(t,{})}),s(F,{path:"/create-short-url",element:s(a,{})}),s(F,{path:"/short-code/:shortCode/visits/*",element:s(n,{})}),s(F,{path:"/short-code/:shortCode/edit",element:s(p,{})}),s(F,{path:"/tag/:tag/visits/*",element:s(i,{})}),I&&s(F,{path:"/domain/:domain/visits/*",element:s(c,{})}),s(F,{path:"/orphan-visits/*",element:s(l,{})}),B&&s(F,{path:"/non-orphan-visits/*",element:s(d,{})}),s(F,{path:"/manage-tags",element:s(e,{})}),s(F,{path:"/manage-domains",element:s(m,{})}),s(F,{path:"*",element:s(Va,{to:`/server/${g.id}/list-short-urls/1`,children:"List short URLs"})})]})})})]})})]})},h);const Oe=({children:e,to:t,className:r,...a})=>s(ra,{className:({isActive:n})=>x("aside-menu__item",r,{"aside-menu__item--selected":n}),to:t,...a,children:e}),_c=e=>({selectedServer:t,showOnMobile:r=!1})=>{const a=ge(t),n=a?t.id:"",{pathname:i}=Z(),c=x("aside-menu",{"aside-menu--hidden":!r}),l=d=>`/server/${n}${d}`;return s("aside",{className:c,children:o("nav",{className:"nav flex-column aside-menu__nav",children:[o(Oe,{to:l("/overview"),children:[s(y,{fixedWidth:!0,icon:ei}),s("span",{className:"aside-menu__item-text",children:"Overview"})]}),o(Oe,{to:l("/list-short-urls/1"),className:x({"aside-menu__item--selected":i.match("/list-short-urls")!==null}),children:[s(y,{fixedWidth:!0,icon:ta}),s("span",{className:"aside-menu__item-text",children:"List short URLs"})]}),o(Oe,{to:l("/create-short-url"),children:[s(y,{fixedWidth:!0,icon:ti,flip:"horizontal"}),s("span",{className:"aside-menu__item-text",children:"Create short URL"})]}),o(Oe,{to:l("/manage-tags"),children:[s(y,{fixedWidth:!0,icon:sa}),s("span",{className:"aside-menu__item-text",children:"Manage tags"})]}),o(Oe,{to:l("/manage-domains"),children:[s(y,{fixedWidth:!0,icon:si}),s("span",{className:"aside-menu__item-text",children:"Manage domains"})]}),o(Oe,{to:l("/edit"),className:"aside-menu__item--push",children:[s(y,{fixedWidth:!0,icon:ri}),s("span",{className:"aside-menu__item-text",children:"Edit this server"})]}),a&&s(e,{className:"aside-menu__item aside-menu__item--danger",textClassName:"aside-menu__item-text",server:t})]})})},Uc=({location:e},{error:t})=>class extends v.Component{constructor(r){super(r),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(r){t(r)}render(){const{hasError:r}=this.state;if(r)return s("div",{className:"home",children:o(j,{className:"p-4",children:[s("h1",{children:"Oops! This is awkward :S"}),s("p",{children:"It seems that something went wrong. Try refreshing the page or just click this button."}),s("br",{}),s(V,{outline:!0,color:"primary",onClick:()=>e.reload(),children:"Take me back"})]})});const{children:a}=this.props;return a}},kc="%_VERSION_%",Tc=O(La(),xa),pr=({project:e,version:t})=>s(ae,{href:`https://github.com/shlinkio/${e}/releases/${t}`,className:"text-muted",children:s("b",{children:t})}),xc=({selectedServer:e,clientVersion:t=kc})=>{const r=Tc(t);return o("small",{className:"text-muted",children:[Zt(e)&&o(w,{children:["Server: ",s(pr,{project:"shlink",version:e.printableVersion})," - "]}),"Client: ",s(pr,{project:"shlink-web-client",version:r})]})};const Lc=({selectedServer:e,sidebar:t})=>{const r=x("text-center",{"shlink-versions-container--with-sidebar":t.sidebarPresent});return s("div",{className:r,children:s(xc,{selectedServer:e})})};function Ht(e){return t=>{const{resetSelectedServer:r}=t;return v.useEffect(()=>{r()},[]),s(e,{...t})}}const Ec={sidebarPresent:!1},{actions:Ic,reducer:Fc}=W({name:"shlink/sidebar",initialState:Ec,reducers:{sidebarPresent:()=>({sidebarPresent:!0}),sidebarNotPresent:()=>({sidebarPresent:!1})}}),{sidebarPresent:Vc,sidebarNotPresent:Mc}=Ic,Oc=Fc,Ma=({document:e},t,r)=>{const a=e.createElement("a");a.setAttribute("href",t),a.setAttribute("download",r),a.style.visibility="hidden",e.body.appendChild(a),a.click(),e.body.removeChild(a)},Oa=(e,t,r)=>{const a=new Blob([t],{type:"text/csv;charset=utf-8;"}),n=URL.createObjectURL(a);Ma(e,n,r)};class $c{constructor(t,r){this.httpClient=t,this.window=r}async saveImage(t,r){const a=await this.httpClient.fetchBlob(t),n=URL.createObjectURL(a);Ma(this.window,n,r)}}class Ac{constructor(t,r){T(this,"exportVisits",(t,r)=>{r.length&&this.exportCsv(t,r)});T(this,"exportShortUrls",t=>{t.length&&this.exportCsv("short_urls.csv",t)});T(this,"exportCsv",(t,r)=>{const a=this.jsonToCsv(r);Oa(this.window,a,t)});this.window=t,this.jsonToCsv=r}}const vr={"Content-Type":"application/json"},fr=e=>e!=null&&e.body?e?{...e,headers:{...e.headers??{},...vr}}:{headers:vr}:e;class Pc{constructor(t){T(this,"fetchJson",(t,r)=>this.fetch(t,fr(r)).then(async a=>{const n=await a.json();if(!a.ok)throw n;return n}));T(this,"fetchEmpty",(t,r)=>this.fetch(t,fr(r)).then(async a=>{if(!a.ok)throw await a.json()}));T(this,"fetchBlob",t=>this.fetch(t).then(r=>r.blob()));this.fetch=t}}const Bc=(e,t)=>{e.constant("window",window),e.constant("console",console),e.constant("fetch",window.fetch.bind(window)),e.service("HttpClient",Pc,"fetch"),e.service("ImageDownloader",$c,"HttpClient","window"),e.service("ReportExporter",Ac,"window","jsonToCsv"),e.serviceFactory("ScrollToTop",()=>ac),e.serviceFactory("MainHeader",pc,"ServersDropdown"),e.serviceFactory("Home",()=>fc),e.decorator("Home",Ht),e.decorator("Home",t(["servers"],["resetSelectedServer"])),e.serviceFactory("MenuLayout",Dc,"TagsList","ShortUrlsList","AsideMenu","CreateShortUrl","ShortUrlVisits","TagVisits","DomainVisits","OrphanVisits","NonOrphanVisits","ServerError","Overview","EditShortUrl","ManageDomains"),e.decorator("MenuLayout",t(["selectedServer"],["selectServer","sidebarPresent","sidebarNotPresent"])),e.serviceFactory("AsideMenu",_c,"DeleteServerButton"),e.serviceFactory("ShlinkVersionsContainer",()=>Lc),e.decorator("ShlinkVersionsContainer",t(["selectedServer","sidebar"])),e.serviceFactory("ErrorHandler",Uc,"window","console"),e.serviceFactory("sidebarPresent",()=>Vc),e.serviceFactory("sidebarNotPresent",()=>Mc)};const jc=500;let kt;const mt=({onChange:e,className:t,large:r=!0,noBorder:a=!1,initialValue:n=""})=>{const[i,c]=v.useState(n),l=()=>{kt&&clearTimeout(kt),kt=null},d=(h,u=jc)=>{c(h),l(),kt=setTimeout(()=>{e(h),l()},u)};return o("div",{className:x("search-field",t),children:[s("input",{type:"text",className:x("form-control search-field__input",{"form-control-lg":r,"search-field__input--no-border":a}),placeholder:"Search...",value:i,onChange:h=>d(h.target.value)}),s(y,{icon:ai,className:"search-field__icon"}),s("div",{className:"close search-field__close btn-close",hidden:i==="",id:"search-field__close",onClick:()=>d("",0)})]})};const be=({text:e,disabled:t=!1,className:r="",children:a,dropdownClassName:n,right:i=!1,minWidth:c})=>{const[l,d]=A(),h=`dropdown-btn__toggle btn-block ${r}`,u={minWidth:c&&`${c}px`};return o(aa,{isOpen:l,toggle:d,disabled:t,className:n,children:[s(qe,{caret:!0,className:h,color:"primary",children:e}),s(Ve,{className:"w-100",end:i,style:u,children:a})]})},Ze="yyyy-MM-dd",zs="yyyy-MM-dd HH:mm",ve=()=>new Date,Qs=e=>typeof e!="string",$a=(e,t)=>!e||!Qs(e)?e:t?Ie(e,t):ni(e),Aa=(e=Ze)=>t=>$a(t,e),fe=e=>$a(e,void 0),Tt=Aa(),Wt=Aa(zs),re=e=>Qs(e)?e:pe(e),Cr=e=>e?re(e):null,gt=(e,t,r)=>{try{return ii(re(e),{start:re(t??e),end:re(r??e)})}catch{return!1}},xe=(e,t)=>oi(e,t)||Ns(e,t),pt="all",Pa={today:"Today",yesterday:"Yesterday",last7Days:"Last 7 days",last30Days:"Last 30 days",last90Days:"Last 90 days",last180Days:"Last 180 days",last365Days:"Last 365 days",[pt]:void 0},Ba=Object.keys(Pa),ja=e=>e===void 0||H(ci(Boolean,e)),qt=e=>typeof e=="string"&&Ba.includes(e),Gc=Ba.filter(e=>e!==pt),Ga=(e,t)=>({startDate:Cr(e),endDate:Cr(t)}),Hc=e=>{if(!(!e||ja(e)))return e.startDate&&!e.endDate?`Since ${Tt(e.startDate)}`:!e.startDate&&e.endDate?`Until ${Tt(e.endDate)}`:`${Tt(e.startDate)} - ${Tt(e.endDate)}`},Ks=e=>{if(!(!e||e===pt))return qt(e)?Pa[e]:Hc(e)},X=e=>Vs(na(ve(),e)),$e=e=>({startDate:e,endDate:Ms(ve())}),Ha=Jt([[Te("today"),()=>$e(Vs(ve()))],[Te("yesterday"),()=>({startDate:X(1),endDate:Ms(na(ve(),1))})],[Te("last7Days"),()=>$e(X(7))],[Te("last30Days"),()=>$e(X(30))],[Te("last90Days"),()=>$e(X(90))],[Te("last180Days"),()=>$e(X(180))],[Te("last365Days"),()=>$e(X(365))],[Os,()=>({})]]),Wc=e=>{const t=re(e);return Jt([[()=>xe(Vs(ve()),t),()=>"today"],[()=>xe(X(1),t),()=>"yesterday"],[()=>xe(X(7),t),()=>"last7Days"],[()=>xe(X(30),t),()=>"last30Days"],[()=>xe(X(90),t),()=>"last90Days"],[()=>xe(X(180),t),()=>"last180Days"],[()=>xe(X(365),t),()=>"last365Days"],[Os,()=>pt]])()},qc=e=>qt(e)?Ha(e):e;const _s=e=>{const{className:t,isClearable:r,selected:a,dateFormat:n}=e,i=!r||Ce(a),c=v.useRef();return o("div",{className:"date-input-container",children:[s(li,{...e,popperModifiers:[{name:"arrow",options:{padding:24}}],dateFormat:n??Ze,className:x("date-input-container__input form-control",t),ref:c}),i&&s(y,{icon:di,className:"date-input-container__icon",onClick:()=>{var l;return(l=c.current)==null?void 0:l.input.focus()}})]})},zc=({startDate:e=null,endDate:t=null,disabled:r=!1,onStartDateChange:a,onEndDateChange:n})=>o("div",{className:"row",children:[s("div",{className:"col-md-6",children:s(_s,{selected:e,placeholderText:"Since...",isClearable:!0,maxDate:t??void 0,disabled:r,onChange:a})}),s("div",{className:"col-md-6",children:s(_s,{className:"mt-2 mt-md-0",selected:t,placeholderText:"Until...",isClearable:!0,minDate:e??void 0,disabled:r,onChange:i=>n(i&&Ms(i))})})]}),Wa=({active:e,allText:t,onChange:r})=>o(w,{children:[s(b,{active:e==="all",onClick:()=>r("all"),children:t}),s(b,{divider:!0}),Gc.map(a=>s(b,{active:e===a,onClick:()=>r(a),children:Ks(a)},a))]}),qa=({onDatesChange:e,initialDateRange:t,defaultText:r,disabled:a,updatable:n=!1})=>{const i=qt(t),[c,l]=v.useState(i?t:void 0),[d,h]=v.useState(i?void 0:t),u=m=>{l(ja(m)?pt:void 0),h(m),e(m)},p=m=>{l(m),h(void 0),e(Ha(m))};return n&&lc(()=>{const m=qt(t);m&&p(t),t&&!m&&u(t)},[t]),o(be,{disabled:a,text:Ks(c??d)??r,children:[s(Wa,{allText:r,active:c,onChange:p}),s(b,{divider:!0}),s(b,{header:!0,children:"Custom:"}),s(b,{text:!0,children:s(zc,{...d,onStartDateChange:m=>u({...d,startDate:m}),onEndDateChange:m=>u({...d,endDate:m})})})]})};function vt({items:e,order:t,onChange:r,isButton:a=!0,right:n=!1,prefixed:i=!0}){const c=l=>()=>{const d=es(l,t.field,t.dir);r(d?l:void 0,d)};return o(Yt,{children:[o(qe,{caret:!0,color:a?"primary":"link",className:x({"dropdown-btn__toggle btn-block pe-4 overflow-hidden":a,"btn-sm p-0":!a}),children:[!a&&s(w,{children:"Order by"}),a&&!t.field&&s("i",{children:"Order by..."}),a&&t.field&&o(w,{children:[i&&"Order by: ",e[t.field]," - ",s("small",{children:t.dir??"DESC"})]})]}),o(Ve,{end:n,className:x("w-100",{"ordering-dropdown__menu--link":!a}),children:[Bt(e).map(([l,d])=>o(b,{active:t.field===l,onClick:c(l),children:[d,t.field===l&&s(y,{icon:t.dir==="ASC"?hi:ui,className:"ordering-dropdown__sort-icon"})]},l)),s(b,{divider:!0}),s(b,{disabled:!t.field,onClick:()=>r(),children:s("i",{children:"Clear selection"})})]})]})}const as=()=>{const e=Fe(),{search:t}=Z(),{serverId:r=""}=Se(),a=v.useMemo(O(()=>Qe(t),({orderBy:i,tags:c,excludeBots:l,excludeMaxVisitsReached:d,excludePastValidUntil:h,...u})=>{const p=i?Wo(i):void 0,m=(c==null?void 0:c.split(","))??[];return{...u,orderBy:p,tags:m,excludeBots:l!==void 0?l==="true":void 0,excludeMaxVisitsReached:d!==void 0?d==="true":void 0,excludePastValidUntil:h!==void 0?h==="true":void 0}}),[t]);return[a,i=>{const c={...a,...i},{orderBy:l,tags:d,excludeBots:h,excludeMaxVisitsReached:u,excludePastValidUntil:p,...m}=c,g={...m,orderBy:l&&ba(l),tags:d.length>0?d.join(","):void 0,excludeBots:ds(h),excludeMaxVisitsReached:ds(u),excludePastValidUntil:ds(p)},f=dt(g),C=H(f)?"":`?${f}`;e(`/server/${r}/list-short-urls/1${C}`)}]},za={dateCreated:"Created at",shortCode:"Short URL",longUrl:"Long URL",title:"Title",visits:"Visits"},Qc=({onChange:e,selected:t={},className:r,supportsDisabledFiltering:a})=>{const{excludeBots:n=!1,excludeMaxVisitsReached:i=!1,excludePastValidUntil:c=!1}=t,l=d=>()=>e({...t,[d]:!(t!=null&&t[d])});return o(be,{text:"Filters",dropdownClassName:r,className:"me-3",right:!0,minWidth:250,children:[s(b,{header:!0,children:"Visits:"}),s(b,{active:n,onClick:l("excludeBots"),children:"Ignore visits from bots"}),a&&o(w,{children:[s(b,{divider:!0}),s(b,{header:!0,children:"Short URLs:"}),s(b,{active:i,onClick:l("excludeMaxVisitsReached"),children:"Exclude with visits reached"}),s(b,{active:c,onClick:l("excludePastValidUntil"),children:"Exclude enabled in the past"})]}),s(b,{divider:!0}),s(b,{disabled:!se(t),onClick:()=>e({excludeBots:!1,excludeMaxVisitsReached:!1,excludePastValidUntil:!1}),children:s("i",{children:"Clear filters"})})]})};const Kc=(e,t)=>({selectedServer:r,className:a,shortUrlsAmount:n,order:i,handleOrderBy:c,settings:l})=>{var k;const[d,h]=as(),{search:u,tags:p,startDate:m,endDate:g,excludeBots:f,excludeMaxVisitsReached:C,excludePastValidUntil:R,tagsMode:_="any"}=d,N=wc(r),D=O(({startDate:E,endDate:M})=>({startDate:fe(E)??void 0,endDate:fe(M)??void 0}),h),S=O(E=>H(E)?void 0:E,E=>h({search:E})),U=E=>h({tags:E}),B=Rc(r),I=O(()=>_==="any"?"all":"any",E=>h({tagsMode:E}));return o("div",{className:x("short-urls-filtering-bar-container",a),children:[s(mt,{initialValue:u,onChange:S}),o($s,{className:"mt-3",children:[s(t,{allowNew:!1,placeholder:"With tags...",selectedTags:p,onChange:U}),B&&p.length>1&&o(w,{children:[s(V,{outline:!0,color:"secondary",onClick:I,id:"tagsModeBtn","aria-label":"Change tags mode",children:s(y,{className:"short-urls-filtering-bar__tags-icon",icon:_==="all"?sa:mi})}),s(ee,{target:"tagsModeBtn",placement:"left",children:_==="all"?"With all the tags.":"With any of the tags."})]})]}),o(Q,{className:"flex-lg-row-reverse",children:[s("div",{className:"col-lg-8 col-xl-6 mt-3",children:o("div",{className:"d-md-flex",children:[s("div",{className:"flex-fill",children:s(qa,{defaultText:"All short URLs",initialDateRange:Ga(m,g),onDatesChange:D})}),s(Qc,{className:"ms-0 ms-md-2 mt-3 mt-md-0",selected:{excludeBots:f??((k=l.visits)==null?void 0:k.excludeBots),excludeMaxVisitsReached:C,excludePastValidUntil:R},onChange:h,supportsDisabledFiltering:N})]})}),s("div",{className:"col-6 col-lg-4 col-xl-6 mt-3",children:s(e,{amount:n})}),s("div",{className:"col-6 d-lg-none mt-3",children:s(vt,{prefixed:!1,items:za,order:i,onChange:c})})]})]})},Xc=(e,t,r,a)=>{const{mercureHubUrl:n,token:i,loading:c,error:l}=e;if(c||l||!n)return;const d=({data:p})=>r(JSON.parse(p)),h=({status:p})=>p===401&&a(),u=t.map(p=>{const m=new URL(n);m.searchParams.append("topic",p);const g=new gi.EventSourcePolyfill(m,{headers:{Authorization:`Bearer ${i}`}});return g.onmessage=d,g.onerror=h,g});return()=>u.forEach(p=>p.close())};function Re(e,t){const r=new Set;return a=>{const{createNewVisits:n,loadMercureInfo:i,mercureInfo:c}=a,{interval:l}=c,d=Se();return v.useEffect(()=>{const h=g=>l?r.add(g):n([g]),u=t(a,d),p=Xc(c,u,h,i);if(!l)return p;const m=setInterval(()=>{n([...r]),r.clear()},l*1e3*60);return O(()=>clearInterval(m),()=>p==null?void 0:p())},[c]),s(e,{...a})}}class J{}T(J,"visits","https://shlink.io/new-visit"),T(J,"orphanVisits","https://shlink.io/new-orphan-visit"),T(J,"shortUrlVisits",t=>`https://shlink.io/new-visit/${t}`);function et({currentOrder:e,field:t,className:r="ms-1"}){return!e.dir||e.field!==t?null:s(y,{icon:e.dir==="ASC"?pi:vi,className:r})}const Xs={field:"dateCreated",dir:"DESC"},Jc={realTimeUpdates:{enabled:!0},shortUrlCreation:{validateUrls:!1},ui:{theme:"light"},visits:{defaultInterval:"last30Days"},shortUrlsList:{defaultOrdering:Xs}},Yc=(e,{payload:t})=>ia(e,t),Le=e=>({reducer:Yc,prepare:e}),Ee=e=>({payload:e}),{reducer:Zc,actions:el}=W({name:"shlink/settings",initialState:Jc,reducers:{toggleRealTimeUpdates:Le(e=>Ee({realTimeUpdates:{enabled:e}})),setRealTimeUpdatesInterval:Le(e=>Ee({realTimeUpdates:{interval:e}})),setShortUrlCreationSettings:Le(e=>Ee({shortUrlCreation:e})),setShortUrlsListSettings:Le(e=>Ee({shortUrlsList:e})),setUiSettings:Le(e=>Ee({ui:e})),setVisitsSettings:Le(e=>Ee({visits:e})),setTagsSettings:Le(e=>Ee({tags:e}))}}),{toggleRealTimeUpdates:tl,setRealTimeUpdatesInterval:sl,setShortUrlCreationSettings:rl,setShortUrlsListSettings:al,setUiSettings:nl,setVisitsSettings:il,setTagsSettings:ol}=el,cl=Zc,Sr=10,{ceil:ll}=Math,dl=new Intl.NumberFormat("en-US"),G=e=>dl.format(Number(e)),hl=e=>ll(e/Sr)*Sr,Ae=2,Us="...",Qa=(e,t)=>{const r=Is(fi(Ae,e-Ae),oa(t-1,e+Ae)+1);return e-Ae>Ae&&r.unshift(Us),e+Ae<t-1&&r.push(Us),r.unshift(1),r.push(t),r},ct=e=>e===Us,Ka=e=>ct(e)?e:G(e),Xa=(e,t)=>ct(e)?`${e}_${t}`:`${e}`,ul=({paginator:e,serverId:t,currentQueryString:r=""})=>{const{currentPage:a=0,pagesCount:n=0}=e??{},i=l=>`/server/${t}/list-short-urls/${l}${r}`;if(n<=1)return s("div",{className:"pb-3"});const c=()=>Qa(a,n).map((l,d)=>s(Be,{disabled:ct(l),active:a===l,children:s(je,{tag:$,to:i(l),children:Ka(l)})},Xa(l,d)));return o(ca,{className:"sticky-card-paginator py-3",listClassName:"flex-wrap justify-content-center mb-0",children:[s(Be,{disabled:a===1,children:s(je,{previous:!0,tag:$,to:i(a-1)})}),c(),s(Be,{disabled:a>=n,children:s(je,{next:!0,tag:$,to:i(a+1)})})]})},ml=(e,t)=>Re(({listShortUrls:r,shortUrlsList:a,selectedServer:n,settings:i})=>{var De,_e,Dt;const c=lt(n),{page:l}=Se(),d=Z(),[h,u]=as(),{tags:p,search:m,startDate:g,endDate:f,orderBy:C,tagsMode:R,excludeBots:_,excludePastValidUntil:N,excludeMaxVisitsReached:D}=h,[S,U]=v.useState(C??((De=i.shortUrlsList)==null?void 0:De.defaultOrdering)??Xs),{pagination:B}=(a==null?void 0:a.shortUrls)??{},I=_??((_e=i.visits)==null?void 0:_e.excludeBots),k=(q,Ue)=>{u({orderBy:{field:q,dir:Ue}}),U({field:q,dir:Ue})},E=q=>()=>k(q,es(q,S.field,S.dir)),M=q=>s(et,{currentOrder:S,field:q}),ue=O(q=>[...new Set([...p,q])],q=>u({tags:q})),me=({field:q,dir:Ue})=>Fa(n)&&I&&q==="visits"?{field:"nonBotVisits",dir:Ue}:{field:q,dir:Ue};return v.useEffect(()=>{r({page:l,searchTerm:m,tags:p,startDate:g,endDate:f,orderBy:me(S),tagsMode:R,excludePastValidUntil:N,excludeMaxVisitsReached:D})},[l,m,p,g,f,S.field,S.dir,R,N,D]),o(w,{children:[s(t,{selectedServer:n,shortUrlsAmount:(Dt=a.shortUrls)==null?void 0:Dt.pagination.totalItems,order:S,handleOrderBy:k,settings:i,className:"mb-3"}),o(Y,{body:!0,className:"pb-0",children:[s(e,{selectedServer:n,shortUrlsList:a,orderByColumn:E,renderOrderIcon:M,onTagClick:ue}),s(ul,{paginator:B,serverId:c,currentQueryString:d.search})]})]})},()=>[J.visits]);const Ja=({text:e,onCopy:t})=>s(la,{text:e,onCopy:t,children:s(y,{icon:da,className:"ms-2 copy-to-clipboard-icon"})}),zt=({date:e,format:t=zs,relative:r=!1})=>{const a=Qs(e)?e:pe(e);return s("time",{dateTime:`${Ci(a)}000`,children:r?`${Si(ve(),a)} ago`:Ie(a,t)})},z=(e,t)=>yi(e,t,{serializeError:Kt}),ft=ie("shlink/visitCreation/createNewVisits",e=>({payload:{createdVisits:e}})),yr=5e3,Nr=4,br=2,gl=({currentPage:e,pagesCount:t})=>e>=t,pl=(e,t)=>t*100/e,Ct=({typePrefix:e,createLoaders:t,getExtraFulfilledPayload:r,shouldCancel:a})=>{const n=ie(`${e}/progressChanged`),i=ie(`${e}/large`),c=ie(`${e}/fallbackToInterval`),l=z(e,async(d,{getState:h,dispatch:u})=>{const[p,m]=t(d,h),g=async N=>Promise.all(N.map(async D=>p(D,yr).then(L("data")))).then(Ni),f=async(N,D=0)=>{if(a(h))return[];const S=await g(N[D]);return u(n(pl(N.length,D+br))),D<N.length-1?S.concat(await f(N,D+1)):S},C=async(N=1)=>{const{pagination:D,data:S}=await p(N,yr);if(!D||gl(D))return S;const U=Is(br,D.pagesCount+1),B=nt(Nr,U);return D.pagesCount-1>Nr&&u(i()),S.concat(await f(B))},[R,_]=await Promise.all([C(),m()]);return!R.length&&_&&u(c(Wc(_.date))),{...r(d),visits:R}});return Object.assign(l,{progressChanged:n,large:i,fallbackToInterval:c})},St=(e,t)=>e?async()=>t({page:1,itemsPerPage:1}).then(({data:r})=>r[0]):async()=>Promise.resolve(void 0),yt=({name:e,asyncThunkCreator:t,initialState:r,filterCreatedVisits:a})=>{const{pending:n,rejected:i,fulfilled:c,large:l,progressChanged:d,fallbackToInterval:h}=t,{reducer:u,actions:p}=W({name:e,initialState:r,reducers:{cancelGetVisits:g=>({...g,cancelLoad:!0})},extraReducers:g=>{g.addCase(n,()=>({...r,loading:!0})),g.addCase(i,(f,{error:C})=>({...r,error:!0,errorData:oe(C)})),g.addCase(c,(f,{payload:C})=>({...f,...C,loading:!1,loadingLarge:!1,error:!1})),g.addCase(l,f=>({...f,loadingLarge:!0})),g.addCase(d,(f,{payload:C})=>({...f,progress:C})),g.addCase(h,(f,{payload:C})=>({...f,fallbackInterval:C})),g.addCase(ft,(f,{payload:C})=>{const{visits:R}=f,_=a(f,C.createdVisits).map(({visit:N})=>N);return _.length?{...f,visits:[..._,...R]}:f})}}),{cancelGetVisits:m}=p;return{reducer:u,cancelGetVisits:m}},Ya="shlink/domainVisits",Za="DEFAULT",vl={visits:[],domain:"",loading:!1,loadingLarge:!1,error:!1,cancelLoad:!1,progress:0},fl=e=>Ct({typePrefix:`${Ya}/getDomainVisits`,createLoaders:({domain:t,query:r={},doIntervalFallback:a=!1},n)=>{const{getDomainVisits:i}=e(n),c=async(d,h)=>i(t,{...r,page:d,itemsPerPage:h}),l=St(a,async d=>i(t,d));return[c,l]},getExtraFulfilledPayload:({domain:t,query:r={}})=>({domain:t,query:r}),shouldCancel:t=>t().domainVisits.cancelLoad}),Cl=e=>yt({name:Ya,initialState:vl,asyncThunkCreator:e,filterCreatedVisits:({domain:t,query:r={}},a)=>{const{startDate:n,endDate:i}=r;return a.filter(({shortUrl:c,visit:l})=>c&&Sl(c,t)&>(l.date,n,i))}}),tt=(e,t,r)=>Ce(r)?e.shortCode===t&&!e.domain:e.shortCode===t&&e.domain===r,Sl=(e,t)=>!e.domain&&t===Za?!0:e.domain===t,yl=(e,t)=>{const r=(t==null?void 0:t.validateUrls)??!1;return e?{longUrl:e.longUrl,tags:e.tags,title:e.title??void 0,domain:e.domain??void 0,validSince:e.meta.validSince??void 0,validUntil:e.meta.validUntil??void 0,maxVisits:e.meta.maxVisits??void 0,crawlable:e.crawlable,forwardQuery:e.forwardQuery,validateUrl:r}:{longUrl:"",validateUrl:r}},en="__",Nl=e=>e.replaceAll("/",en),$t=e=>e.replaceAll(en,"/"),bl=({id:e},{shortCode:t,domain:r},a)=>{const n=r?`?domain=${r}`:"";return`/server/${e}/short-code/${Nl(t)}/${a}${n}`},ks=({selectedServer:e,shortUrl:t,suffix:r,children:a,...n})=>!e||!ge(e)||!t?s("span",{...n,children:a}):s($,{to:bl(e,t,r),...n,children:a}),Nt=e=>t=>{e.current=t??void 0};const tn=({visitsCount:e,shortUrl:t,selectedServer:r,active:a=!1})=>{const{maxVisits:n,validSince:i,validUntil:c}=(t==null?void 0:t.meta)??{},l=!!n||!!i||!!c,d=s(ks,{selectedServer:r,shortUrl:t,suffix:"visits",children:s("strong",{className:x("short-url-visits-count__amount",{"short-url-visits-count__amount--big":a}),children:G(e)})});if(!l)return d;const h=v.useRef();return o(w,{children:[o("span",{className:"indivisible",children:[d,o("small",{className:"short-urls-visits-count__max-visits-control",ref:Nt(h),children:[n&&o(w,{children:[" / ",G(n)]}),s("sup",{className:"ms-1",children:s(y,{icon:As})})]})]}),s(ee,{target:()=>h.current,placement:"bottom",children:o("ul",{className:"list-unstyled mb-0",children:[n&&o("li",{className:"short-url-visits-count__tooltip-list-item",children:["This short URL will not accept more than ",s("b",{children:G(n)})," visit",n===1?"":"s","."]}),i&&o("li",{className:"short-url-visits-count__tooltip-list-item",children:["This short URL will not accept visits before ",s("b",{className:"indivisible",children:Wt(re(i))}),"."]}),c&&o("li",{className:"short-url-visits-count__tooltip-list-item",children:["This short URL will not accept visits after ",s("b",{className:"indivisible",children:Wt(re(c))}),"."]})]})})]})};const Js=({text:e,children:t,clearable:r,className:a="",colorGenerator:n,onClick:i,onClose:c})=>o("span",{className:x("badge tag",a,{"tag--light-bg":n.isColorLightForKey(e)}),style:{backgroundColor:n.getColorForKey(e),cursor:r||!i?"auto":"pointer"},onClick:i,children:[t??e,r&&s("span",{"aria-label":`Remove ${e}`,className:"close tag__close-selected-tag",onClick:c,children:"×"})]}),Rl=({tags:e,onTagClick:t,colorGenerator:r})=>H(e)?s("i",{className:"indivisible",children:s("small",{children:"No tags"})}):s(w,{children:e.map(a=>s(Js,{text:a,colorGenerator:r,onClick:()=>t==null?void 0:t(a)},a))}),wl=e=>{const{meta:t,visitsCount:r,visitsSummary:a}=e,{maxVisits:n,validSince:i,validUntil:c}=t,l=(a==null?void 0:a.total)??r;return n&&l>=n?{icon:bi,className:"text-danger",description:o(w,{children:["This short URL cannot be currently visited because it has reached the maximum amount of ",s("b",{children:n})," visit",n>1?"s":"","."]})}:c&&Ns(re(c),ve())?{icon:hr,className:"text-danger",description:o(w,{children:["This short URL cannot be visited since ",s("b",{className:"indivisible",children:Wt(re(c))}),"."]})}:i&&Ns(ve(),re(i))?{icon:hr,className:"text-warning",description:o(w,{children:["This short URL will start working on ",s("b",{className:"indivisible",children:Wt(re(i))}),"."]})}:{icon:it,className:"text-primary",description:"This short URL can be visited normally."}},Dl=({shortUrl:e})=>{const t=v.useRef(),{icon:r,className:a,description:n}=wl(e);return o(w,{children:[s("span",{style:{cursor:n?"help":void 0},ref:Nt(t),children:s(y,{icon:r,className:a})}),s(ee,{target:()=>t.current,placement:"bottom",children:n})]})};const _l=(e,t,r)=>({shortUrl:a,selectedServer:n,onTagClick:i,settings:c})=>{var C,R,_,N;const[l,d]=r(),[h,u]=r(!1,500),p=v.useRef(!0),[{excludeBots:m}]=as(),{visits:g}=c,f=m??(g==null?void 0:g.excludeBots);return v.useEffect(()=>{!p.current&&u(),p.current=!1},[(C=a.visitsSummary)==null?void 0:C.total,(R=a.visitsSummary)==null?void 0:R.nonBots,a.visitsCount]),o("tr",{className:"responsive-table__row",children:[s("td",{className:"indivisible short-urls-row__cell responsive-table__cell","data-th":"Created at",children:s(zt,{date:a.dateCreated})}),s("td",{className:"responsive-table__cell short-urls-row__cell","data-th":"Short URL",children:o("span",{className:"position-relative short-urls-row__cell--indivisible",children:[s("span",{className:"short-urls-row__short-url-wrapper",children:s(ae,{href:a.shortUrl})}),s(Ja,{text:a.shortUrl,onCopy:d}),s("span",{className:"badge bg-warning text-black short-urls-row__copy-hint",hidden:!l,children:"Copied short URL!"})]})}),s("td",{className:"responsive-table__cell short-urls-row__cell short-urls-row__cell--break","data-th":`${a.title?"Title":"Long URL"}`,children:s(ae,{href:a.longUrl,children:a.title??a.longUrl})}),a.title&&s("td",{className:"short-urls-row__cell responsive-table__cell short-urls-row__cell--break d-lg-none","data-th":"Long URL",children:s(ae,{href:a.longUrl})}),s("td",{className:"responsive-table__cell short-urls-row__cell","data-th":"Tags",children:s(Rl,{tags:a.tags,colorGenerator:t,onTagClick:i})}),s("td",{className:"responsive-table__cell short-urls-row__cell text-lg-end","data-th":"Visits",children:s(tn,{visitsCount:(f?(_=a.visitsSummary)==null?void 0:_.nonBots:(N=a.visitsSummary)==null?void 0:N.total)??a.visitsCount,shortUrl:a,selectedServer:n,active:h})}),s("td",{className:"responsive-table__cell short-urls-row__cell","data-th":"Status",children:s(Dl,{shortUrl:a})}),s("td",{className:"responsive-table__cell short-urls-row__cell",children:s(e,{selectedServer:n,shortUrl:a})})]})};const ns=({isOpen:e,toggle:t,children:r,right:a=!0})=>o(Ri,{toggle:t,isOpen:e,children:[o(qe,{size:"sm",caret:!0,outline:!0,className:"dropdown-btn-menu__dropdown-toggle",children:[" ",s(y,{icon:wi})," "]}),s(Ve,{end:a,children:r})]}),Ul=(e,t)=>({shortUrl:r,selectedServer:a})=>{const[n,i]=A(),[c,,l,d]=A(),[h,,u,p]=A();return o(ns,{toggle:i,isOpen:n,children:[o(b,{tag:ks,selectedServer:a,shortUrl:r,suffix:"visits",children:[s(y,{icon:Ps,fixedWidth:!0})," Visit stats"]}),o(b,{tag:ks,selectedServer:a,shortUrl:r,suffix:"edit",children:[s(y,{icon:Bs,fixedWidth:!0})," Edit short URL"]}),o(b,{onClick:l,children:[s(y,{icon:Di,fixedWidth:!0})," QR code"]}),s(t,{shortUrl:r,isOpen:c,toggle:d}),s(b,{divider:!0}),o(b,{className:"dropdown-item--danger",onClick:u,children:[s(y,{icon:js,fixedWidth:!0})," Delete short URL"]}),s(e,{shortUrl:r,isOpen:h,toggle:p})]})},kl=e=>({longUrl:"",tags:[],customSlug:"",title:void 0,shortCodeLength:void 0,domain:"",validSince:void 0,validUntil:void 0,maxVisits:void 0,findIfExists:!1,validateUrl:(e==null?void 0:e.validateUrls)??!1,forwardQuery:(e==null?void 0:e.forwardQuery)??!0}),Tl=(e,t)=>({createShortUrl:r,shortUrlCreation:a,resetCreateShortUrl:n,selectedServer:i,basicMode:c=!1,settings:{shortUrlCreation:l}})=>{const d=v.useMemo(()=>kl(l),[l]);return o(w,{children:[s(e,{initialState:d,saving:a.saving,selectedServer:i,mode:c?"create-basic":"create",onSave:async h=>(n(),r(h))}),s(t,{creation:a,resetCreateShortUrl:n,canBeClosed:c})]})},K=({children:e,type:t,className:r,small:a=!1})=>s(Q,{className:r,children:s("div",{className:x({"col-md-10 offset-md-1":!a,"col-12":a}),children:s(j,{role:"document",className:x("text-center",{"bg-main":t==="success","bg-danger":t==="error","bg-warning":t==="warning","text-white":t!=="warning"}),bodyClassName:x({"p-2":a}),children:e})})}),le=({errorData:e,fallbackMessage:t})=>o(w,{children:[(e==null?void 0:e.detail)??t,zo(e)&&o("p",{className:"mb-0",children:["Invalid elements: [",e.invalidElements.join(", "),"]"]})]}),hs="delete",xl=({shortUrl:e,toggle:t,isOpen:r,shortUrlDeletion:a,resetDeleteShortUrl:n,deleteShortUrl:i,shortUrlDeleted:c})=>{const[l,d]=v.useState("");v.useEffect(()=>n,[]);const{loading:h,error:u,deleted:p,errorData:m}=a,g=O(n,t),f=ht(()=>i(e).then(t));return s(de,{isOpen:r,toggle:g,centered:!0,onClosed:()=>p&&c(e),children:o("form",{onSubmit:f,children:[s(ye,{toggle:g,children:s("span",{className:"text-danger",children:"Delete short URL"})}),o(he,{children:[o("p",{children:[s("b",{className:"text-danger",children:"Caution!"})," You are about to delete a short URL."]}),s("p",{children:"This action cannot be undone. Once you have deleted it, all the visits stats will be lost."}),o("p",{children:["Write ",s("b",{children:hs})," to confirm deletion."]}),s("input",{type:"text",className:"form-control",placeholder:`Insert ${hs}`,value:l,onChange:C=>d(C.target.value)}),u&&s(K,{type:Qo(m)?"warning":"error",small:!0,className:"mt-2",children:s(le,{errorData:m,fallbackMessage:"Something went wrong while deleting the URL :("})})]}),o(ze,{children:[s("button",{type:"button",className:"btn btn-link",onClick:g,children:"Cancel"}),s("button",{type:"submit",className:"btn btn-danger",disabled:l!==hs||h,children:h?"Deleting...":"Delete"})]})]})})};const Ll=e=>({creation:t,resetCreateShortUrl:r,canBeClosed:a=!1})=>{const[n,i]=e(),{error:c,saved:l}=t;if(v.useEffect(()=>{r()},[]),c)return o(K,{type:"error",className:"mt-3",children:[a&&s(y,{icon:bs,className:"float-end pointer",onClick:r}),s(le,{errorData:t.errorData,fallbackMessage:"An error occurred while creating the URL :("})]});if(!l)return null;const{shortUrl:d}=t.result;return o(K,{type:"success",className:"mt-3",children:[a&&s(y,{icon:bs,className:"float-end pointer",onClick:r}),o("span",{children:[s("b",{children:"Great!"})," The short URL is ",s("b",{children:d})]}),s(la,{text:d,onCopy:i,children:o("button",{className:"btn btn-light btn-sm create-short-url-result__copy-btn",id:"copyBtn",type:"button",children:[s(y,{icon:da})," Copy"]})}),s(_i,{placement:"left",isOpen:n,target:"copyBtn",children:"Copied!"})]})},Ys="shlink/shortUrlDeletion",Rr={shortCode:"",loading:!1,deleted:!1,error:!1},El=e=>z(`${Ys}/deleteShortUrl`,async({shortCode:t,domain:r},{getState:a})=>{const{deleteShortUrl:n}=e(a);return await n(t,r),{shortCode:t,domain:r}}),sn=ie(`${Ys}/shortUrlDeleted`),Il=e=>{const{actions:t,reducer:r}=W({name:Ys,initialState:Rr,reducers:{resetDeleteShortUrl:()=>Rr},extraReducers:n=>{n.addCase(e.pending,i=>({...i,loading:!0,error:!1,deleted:!1})),n.addCase(e.rejected,(i,{error:c})=>({...i,errorData:oe(c),loading:!1,error:!0,deleted:!1})),n.addCase(e.fulfilled,(i,{payload:c})=>({...i,shortCode:c.shortCode,loading:!1,error:!1,deleted:!0}))}}),{resetDeleteShortUrl:a}=t;return{reducer:r,resetDeleteShortUrl:a}},rn="shlink/shortUrlsList",an=5,Fl={loading:!0,error:!1},Vl=e=>z(`${rn}/listShortUrls`,(t,{getState:r})=>{const{listShortUrls:a}=e(r);return a(t??{})}),Ml=(e,t,r)=>W({name:rn,initialState:Fl,reducers:{},extraReducers:a=>{a.addCase(e.pending,n=>({...n,loading:!0,error:!1})),a.addCase(e.rejected,()=>({loading:!1,error:!0})),a.addCase(e.fulfilled,(n,{payload:i})=>({loading:!1,error:!1,shortUrls:i})),a.addCase(r.fulfilled,O((n,{payload:i})=>n.shortUrls?Me(["shortUrls","data"],[i,...n.shortUrls.data.slice(0,an-1)],n):n,n=>n.shortUrls?Me(["shortUrls","pagination","totalItems"],n.shortUrls.pagination.totalItems+1,n):n)),a.addCase(t.fulfilled,(n,{payload:i})=>n.shortUrls?Me(["shortUrls","data"],n.shortUrls.data.map(c=>{const{shortCode:l,domain:d}=i;return tt(c,l,d)?i:c}),n):n),a.addCase(sn,O((n,{payload:i})=>n.shortUrls?Me(["shortUrls","data"],Qt(c=>tt(c,i.shortCode,i.domain),n.shortUrls.data),n):n,n=>n.shortUrls?Me(["shortUrls","pagination","totalItems"],n.shortUrls.pagination.totalItems-1,n):n)),a.addCase(ft,(n,{payload:i})=>{var c,l;return Me(["shortUrls","data"],(l=(c=n.shortUrls)==null?void 0:c.data)==null?void 0:l.map(d=>{var h;return((h=Ui(i.createdVisits.filter(({shortUrl:u})=>u&&tt(d,u.shortCode,u.domain))))==null?void 0:h.shortUrl)??d}),n)})}}),nn="shlink/shortUrlCreation",wr={saving:!1,saved:!1,error:!1},Ol=e=>z(`${nn}/createShortUrl`,(t,{getState:r})=>{const{createShortUrl:a}=e(r);return a(t)}),$l=e=>{const{reducer:t,actions:r}=W({name:nn,initialState:wr,reducers:{resetCreateShortUrl:()=>wr},extraReducers:n=>{n.addCase(e.pending,()=>({saving:!0,saved:!1,error:!1})),n.addCase(e.rejected,(i,{error:c})=>({saving:!1,saved:!1,error:!0,errorData:oe(c)})),n.addCase(e.fulfilled,(i,{payload:c})=>({result:c,saving:!1,saved:!0,error:!1}))}}),{resetCreateShortUrl:a}=r;return{reducer:t,resetCreateShortUrl:a}},on="shlink/shortUrlEdition",Al={saving:!1,saved:!1,error:!1},Pl=e=>z(`${on}/editShortUrl`,({shortCode:t,domain:r,data:a},{getState:n})=>{const{updateShortUrl:i}=e(n);return i(t,r,a)}),Bl=e=>W({name:on,initialState:Al,reducers:{},extraReducers:t=>{t.addCase(e.pending,r=>({...r,saving:!0,error:!1,saved:!1})),t.addCase(e.rejected,(r,{error:a})=>({...r,saving:!1,error:!0,saved:!1,errorData:oe(a)})),t.addCase(e.fulfilled,(r,{payload:a})=>({shortUrl:a,saving:!1,error:!1,saved:!0}))}}),Dr="shlink/shortUrlDetail",_r={loading:!1,error:!1},jl=e=>{const t=z(`${Dr}/getShortUrlDetail`,async({shortCode:a,domain:n},{getState:i})=>{var d;const{shortUrlsList:c}=i();return((d=c==null?void 0:c.shortUrls)==null?void 0:d.data.find(h=>tt(h,a,n)))??await e(i).getShortUrl(a,n)}),{reducer:r}=W({name:Dr,initialState:_r,reducers:{},extraReducers:a=>{a.addCase(t.pending,()=>({loading:!0,error:!1})),a.addCase(t.rejected,(n,{error:i})=>({loading:!1,error:!0,errorData:oe(i)})),a.addCase(t.fulfilled,(n,{payload:i})=>({..._r,shortUrl:i}))}});return{reducer:r,getShortUrlDetail:t}};const Gl=e=>({orderByColumn:t,renderOrderIcon:r,shortUrlsList:a,onTagClick:n,selectedServer:i,className:c})=>{const{error:l,loading:d,shortUrls:h}=a,u=x({"short-urls-table__header-cell--with-action":!!t}),p=x("short-urls-table__header-cell",u),m=x("table table-hover responsive-table short-urls-table",c),g=()=>l?s("tr",{children:s("td",{colSpan:6,className:"text-center table-danger text-dark",children:"Something went wrong while loading short URLs :("})}):d?s("tr",{children:s("td",{colSpan:6,className:"text-center",children:"Loading..."})}):!d&&H(h==null?void 0:h.data)?s("tr",{children:s("td",{colSpan:6,className:"text-center",children:"No results found"})}):h==null?void 0:h.data.map(f=>s(e,{shortUrl:f,selectedServer:i,onTagClick:n},f.shortUrl));return o("table",{className:m,children:[s("thead",{className:"responsive-table__header short-urls-table__header",children:o("tr",{children:[o("th",{className:p,onClick:t==null?void 0:t("dateCreated"),children:["Created at ",r==null?void 0:r("dateCreated")]}),o("th",{className:p,onClick:t==null?void 0:t("shortCode"),children:["Short URL ",r==null?void 0:r("shortCode")]}),o("th",{className:"short-urls-table__header-cell",children:[o("span",{className:u,onClick:t==null?void 0:t("title"),children:["Title ",r==null?void 0:r("title")]})," / ",o("span",{className:u,onClick:t==null?void 0:t("longUrl"),children:[s("span",{className:"indivisible",children:"Long URL"})," ",r==null?void 0:r("longUrl")]})]}),s("th",{className:"short-urls-table__header-cell",children:"Tags"}),s("th",{className:p,onClick:t==null?void 0:t("visits"),children:o("span",{className:"indivisible",children:["Visits ",r==null?void 0:r("visits")]})}),s("th",{className:"short-urls-table__header-cell",colSpan:2})]})}),s("tbody",{children:g()})]})},Hl=e=>s(_s,{...e,dateFormat:zs,showTimeSelect:!0,timeIntervals:10}),cn=({checked:e=!1,onChange:t=Kt,className:r,children:a,type:n,inline:i=!1})=>{const c=rs(),l=u=>t(u.target.checked,u),d={"form-switch":n==="switch","form-checkbox":n==="checkbox"},h=i?{display:"inline-block"}:{};return o("span",{className:x("form-check",d,r),style:h,children:[s("input",{type:"checkbox",className:"form-check-input",id:c,checked:e,onChange:l}),s("label",{className:"form-check-label",htmlFor:c,children:a})]})},ln=e=>s(cn,{type:"checkbox",...e});const Wl=({isOpen:e,toggle:t})=>o(de,{isOpen:e,toggle:t,centered:!0,size:"lg",children:[s(ye,{toggle:t,children:"Info"}),o(he,{children:[o("p",{children:["When the ",s("b",{children:s("i",{children:'"Use existing URL if found"'})})," checkbox is checked, the server will return an existing short URL if it matches provided params."]}),s("p",{children:"These are the checks performed by Shlink in order to determine if an existing short URL should be returned:"}),o("ul",{children:[s("li",{children:"When only the long URL is provided: The most recent match will be returned, or a new short URL will be created if none is found."}),o("li",{children:["When long URL and custom slug and/or domain are provided: Same as in previous case, but it will try to match the short URL using both the long URL and the slug, the long URL and the domain, or the three of them.",s("br",{}),"If the slug is being used by another long URL, an error will be returned."]}),s("li",{children:"When other params are provided: Same as in previous cases, but it will try to match existing short URLs with all provided data. If any of them does not match, a new short URL will be created"})]})]})]}),ql=()=>{const[e,t]=A();return o(w,{children:[s("span",{title:"What does this mean?",children:s(y,{icon:As,style:{cursor:"pointer"},onClick:t})}),s(Wl,{isOpen:e,toggle:t})]})},At=({className:e="",placement:t,children:r})=>{const a=v.useRef();return o(w,{children:[s("span",{className:e,ref:Nt(a),children:s(y,{icon:As})}),s(ee,{target:()=>a.current,placement:t,children:r})]})},us=({children:e,infoTooltip:t,checked:r,onChange:a})=>o("p",{children:[s(ln,{inline:!0,checked:r,className:t?"me-2":"",onChange:a,children:e}),t&&s(At,{placement:"right",children:t})]});const zl=O(Ti,ki(/ /g,"-")),ms=e=>typeof e=="string"?pe(e):e,Ql=(e,t)=>({mode:r,saving:a,onSave:n,initialState:i,selectedServer:c})=>{const[l,d]=v.useState(i),h=r==="edit",u=r==="create-basic",p=se(i.title),m=S=>d({...l,tags:S.map(zl)}),g=()=>d(i),f=()=>{const S=se(l.title);return Jt([[()=>!S&&!p,()=>{}],[()=>!S&&p,()=>null],[Os,()=>l.title]])()},C=ht(async()=>n({...l,validSince:fe(l.validSince)??null,validUntil:fe(l.validUntil)??null,maxVisits:se(l.maxVisits)?Number(l.maxVisits):null,title:f()}).then(()=>!h&&g()).catch(()=>{}));v.useEffect(()=>{d(i)},[i]);const R=(S,U,B="text",I={},k={})=>s(ne,{...k,children:s(ot,{id:S,type:B,placeholder:U,value:l[S]??"",onChange:E=>d({...l,[S]:E.target.value}),...I})}),_=(S,U,B={})=>s(Hl,{selected:l[S]?ms(l[S]):null,placeholderText:U,isClearable:!0,onChange:I=>d({...l,[S]:I}),...B}),N=o(w,{children:[s(ne,{children:s(ot,{bsSize:"lg",type:"url",placeholder:"URL to be shortened",required:!0,value:l.longUrl,onChange:S=>d({...l,longUrl:S.target.value})})}),o(Q,{children:[u&&R("customSlug","Custom slug","text",{bsSize:"lg"},{className:"col-lg-6"}),s("div",{className:u?"col-lg-6 mb-3":"col-12",children:s(e,{selectedTags:l.tags??[],onChange:m})})]})]}),D=Ea(c);return o("form",{name:"shortUrlForm",className:"short-url-form",onSubmit:C,children:[u&&N,!u&&o(w,{children:[s(j,{title:"Main options",className:"mb-3",children:N}),o(Q,{children:[s("div",{className:"col-sm-6 mb-3",children:o(j,{title:"Customize the short URL",children:[R("title","Title"),!h&&o(w,{children:[o(Q,{children:[s("div",{className:"col-lg-6",children:R("customSlug","Custom slug","text",{disabled:se(l.shortCodeLength)})}),s("div",{className:"col-lg-6",children:R("shortCodeLength","Short code length","number",{min:4,disabled:se(l.customSlug)})})]}),s(t,{value:l.domain,onChange:S=>d({...l,domain:S})})]})]})}),s("div",{className:"col-sm-6 mb-3",children:o(j,{title:"Limit access to the short URL",children:[R("maxVisits","Maximum number of visits allowed","number",{min:1}),s("div",{className:"mb-3",children:_("validSince","Enabled since...",{maxDate:l.validUntil?ms(l.validUntil):void 0})}),_("validUntil","Enabled until...",{minDate:l.validSince?ms(l.validSince):void 0})]})})]}),o(Q,{children:[s("div",{className:"col-sm-6 mb-3",children:o(j,{title:"Extra checks",children:[s(us,{infoTooltip:"If checked, Shlink will try to reach the long URL, failing in case it's not publicly accessible.",checked:l.validateUrl,onChange:S=>d({...l,validateUrl:S}),children:"Validate URL"}),!h&&o("p",{children:[s(ln,{inline:!0,className:"me-2",checked:l.findIfExists,onChange:S=>d({...l,findIfExists:S}),children:"Use existing URL if found"}),s(ql,{})]})]})}),s("div",{className:"col-sm-6 mb-3",children:o(j,{title:"Configure behavior",children:[s(us,{infoTooltip:"This short URL will be included in the robots.txt for your Shlink instance, allowing web crawlers (like Google) to index it.",checked:l.crawlable,onChange:S=>d({...l,crawlable:S}),children:"Make it crawlable"}),D&&s(us,{infoTooltip:"When this short URL is visited, any query params appended to it will be forwarded to the long URL.",checked:l.forwardQuery,onChange:S=>d({...l,forwardQuery:S}),children:"Forward query params on redirect"})]})})]})]}),s("div",{className:"text-center",children:s(V,{outline:!0,color:"primary",disabled:a||H(l.longUrl),className:"btn-xs-block",children:a?"Saving...":"Save"})})]})},Kl=e=>({settings:{shortUrlCreation:t},selectedServer:r,shortUrlDetail:a,getShortUrlDetail:n,shortUrlEdition:i,editShortUrl:c})=>{const{search:l}=Z(),d=Se(),h=Ne(),{loading:u,error:p,errorData:m,shortUrl:g}=a,{saving:f,saved:C,error:R,errorData:_}=i,{domain:N}=Qe(l),D=v.useMemo(()=>yl(g,t),[g,t]);return v.useEffect(()=>{d.shortCode&&n({shortCode:$t(d.shortCode),domain:N})},[]),u?s(ce,{loading:!0}):p?s(K,{type:"error",children:s(le,{errorData:m,fallbackMessage:"An error occurred while loading short URL detail :("})}):o(w,{children:[s("header",{className:"mb-3",children:s(Y,{body:!0,children:o("h2",{className:"d-sm-flex justify-content-between align-items-center mb-0",children:[s(V,{color:"link",size:"lg",className:"p-0 me-3",onClick:h,children:s(y,{icon:ha})}),s("span",{className:"text-center",children:o("small",{children:["Edit ",s(ae,{href:(g==null?void 0:g.shortUrl)??""})]})}),s("span",{})]})})}),s(e,{initialState:D,saving:f,selectedServer:r,mode:"edit",onSave:async S=>{g&&c({...g,data:S})}}),C&&R&&s(K,{type:"error",className:"mt-3",children:s(le,{errorData:_,fallbackMessage:"An error occurred while updating short URL :("})}),C&&!R&&s(K,{type:"success",className:"mt-3",children:"Short URL properly edited."})]})},Xl=(e,{margin:t,...r})=>{const a=`${e}/qr-code`,n=dt({...r,margin:t>0?t:void 0});return`${a}${H(n)?"":`?${n}`}`},Jl=({format:e,setFormat:t})=>o(be,{text:`Format (${e})`,children:[s(b,{active:e==="png",onClick:()=>t("png"),children:"PNG"}),s(b,{active:e==="svg",onClick:()=>t("svg"),children:"SVG"})]}),Yl=({errorCorrection:e,setErrorCorrection:t})=>o(be,{text:`Error correction (${e})`,children:[o(b,{active:e==="L",onClick:()=>t("L"),children:[s("b",{children:"L"}),"ow"]}),o(b,{active:e==="M",onClick:()=>t("M"),children:[s("b",{children:"M"}),"edium"]}),o(b,{active:e==="Q",onClick:()=>t("Q"),children:[s("b",{children:"Q"}),"uartile"]}),o(b,{active:e==="H",onClick:()=>t("H"),children:[s("b",{children:"H"}),"igh"]})]});const Zl=e=>({shortUrl:{shortUrl:t,shortCode:r},toggle:a,isOpen:n,selectedServer:i})=>{const[c,l]=v.useState(300),[d,h]=v.useState(0),[u,p]=v.useState("png"),[m,g]=v.useState("L"),f=Nc(i),C=v.useMemo(()=>Xl(t,{size:c,format:u,margin:d,errorCorrection:m}),[t,c,u,d,m]),R=v.useMemo(()=>c+d,[c,d]),_=v.useMemo(()=>{if(!(R<500))return R<800?"lg":"xl"},[R]);return o(de,{isOpen:n,toggle:a,centered:!0,size:_,children:[o(ye,{toggle:a,children:["QR code for ",s(ae,{href:t,children:t})]}),o(he,{children:[o(Q,{children:[o(ne,{className:"d-grid col-md-4",children:[o("label",{children:["Size: ",c,"px"]}),s("input",{type:"range",className:"form-control-range",value:c,step:10,min:50,max:1e3,onChange:N=>l(Number(N.target.value))})]}),o(ne,{className:"d-grid col-md-4",children:[o("label",{htmlFor:"marginControl",children:["Margin: ",d,"px"]}),s("input",{id:"marginControl",type:"range",className:"form-control-range",value:d,step:1,min:0,max:100,onChange:N=>h(Number(N.target.value))})]}),s(ne,{className:"d-grid col-md-4",children:s(Jl,{format:u,setFormat:p})}),s(ne,{className:"col-md-6",children:s(Yl,{errorCorrection:m,setErrorCorrection:g})})]}),o("div",{className:"text-center",children:[o("div",{className:"mb-3",children:[s(ae,{href:C}),s(Ja,{text:C})]}),s("img",{src:C,className:"qr-code-modal__img",alt:"QR code"}),f&&s("div",{className:"mt-3",children:o(V,{block:!0,color:"primary",onClick:()=>{e.saveImage(C,`${r}-qr-code.${u}`).catch(()=>{})},children:["Download ",s(y,{icon:ua,className:"ms-1"})]})})]})]})]})},dn=({amount:e=0,loading:t=!1,...r})=>o(V,{...r,outline:!0,color:"primary",disabled:t,children:[s(y,{icon:xi})," ",t?"Exporting...":o(w,{children:["Export (",G(e),")"]})]}),Ur=20,ed=(e,{exportShortUrls:t})=>({amount:r=0,selectedServer:a})=>{const[{tags:n,search:i,startDate:c,endDate:l,orderBy:d,tagsMode:h}]=as(),[u,,p,m]=A();return s(dn,{loading:u,className:"btn-md-block",amount:r,onClick:async()=>{if(!ge(a))return;const f=r/Ur,{listShortUrls:C}=e(a),R=async(N=1)=>{const{data:D}=await C({page:`${N}`,tags:n,searchTerm:i,startDate:c,endDate:l,orderBy:d,tagsMode:h,itemsPerPage:Ur});return N>=f?D:D.concat(await R(N+1))};p();const _=await R();t(_.map(N=>{var D;return{createdAt:N.dateCreated,shortUrl:N.shortUrl,longUrl:N.longUrl,title:N.title??"",tags:N.tags.join(","),visits:((D=N==null?void 0:N.visitsSummary)==null?void 0:D.total)??N.visitsCount}})),m()}})},td=(e,t)=>{e.serviceFactory("ShortUrlsList",ml,"ShortUrlsTable","ShortUrlsFilteringBar"),e.decorator("ShortUrlsList",t(["selectedServer","mercureInfo","shortUrlsList","settings"],["listShortUrls","createNewVisits","loadMercureInfo"])),e.serviceFactory("ShortUrlsTable",Gl,"ShortUrlsRow"),e.serviceFactory("ShortUrlsRow",_l,"ShortUrlsRowMenu","ColorGenerator","useTimeoutToggle"),e.decorator("ShortUrlsRow",t(["settings"])),e.serviceFactory("ShortUrlsRowMenu",Ul,"DeleteShortUrlModal","QrCodeModal"),e.serviceFactory("CreateShortUrlResult",Ll,"useTimeoutToggle"),e.serviceFactory("ShortUrlForm",Ql,"TagsSelector","DomainSelector"),e.serviceFactory("CreateShortUrl",Tl,"ShortUrlForm","CreateShortUrlResult"),e.decorator("CreateShortUrl",t(["shortUrlCreation","selectedServer","settings"],["createShortUrl","resetCreateShortUrl"])),e.serviceFactory("EditShortUrl",Kl,"ShortUrlForm"),e.decorator("EditShortUrl",t(["shortUrlDetail","shortUrlEdition","selectedServer","settings"],["getShortUrlDetail","editShortUrl"])),e.serviceFactory("DeleteShortUrlModal",()=>xl),e.decorator("DeleteShortUrlModal",t(["shortUrlDeletion"],["deleteShortUrl","shortUrlDeleted","resetDeleteShortUrl"])),e.serviceFactory("QrCodeModal",Zl,"ImageDownloader"),e.decorator("QrCodeModal",t(["selectedServer"])),e.serviceFactory("ShortUrlsFilteringBar",Kc,"ExportShortUrlsBtn","TagsSelector"),e.serviceFactory("ExportShortUrlsBtn",ed,"buildShlinkApiClient","ReportExporter"),e.decorator("ExportShortUrlsBtn",t(["selectedServer"])),e.serviceFactory("shortUrlsListReducerCreator",Ml,"listShortUrls","editShortUrl","createShortUrl"),e.serviceFactory("shortUrlsListReducer",L("reducer"),"shortUrlsListReducerCreator"),e.serviceFactory("shortUrlCreationReducerCreator",$l,"createShortUrl"),e.serviceFactory("shortUrlCreationReducer",L("reducer"),"shortUrlCreationReducerCreator"),e.serviceFactory("shortUrlEditionReducerCreator",Bl,"editShortUrl"),e.serviceFactory("shortUrlEditionReducer",L("reducer"),"shortUrlEditionReducerCreator"),e.serviceFactory("shortUrlDeletionReducerCreator",Il,"deleteShortUrl"),e.serviceFactory("shortUrlDeletionReducer",L("reducer"),"shortUrlDeletionReducerCreator"),e.serviceFactory("shortUrlDetailReducerCreator",jl,"buildShlinkApiClient"),e.serviceFactory("shortUrlDetailReducer",L("reducer"),"shortUrlDetailReducerCreator"),e.serviceFactory("listShortUrls",Vl,"buildShlinkApiClient"),e.serviceFactory("createShortUrl",Ol,"buildShlinkApiClient"),e.serviceFactory("resetCreateShortUrl",L("resetCreateShortUrl"),"shortUrlCreationReducerCreator"),e.serviceFactory("deleteShortUrl",El,"buildShlinkApiClient"),e.serviceFactory("resetDeleteShortUrl",L("resetDeleteShortUrl"),"shortUrlDeletionReducerCreator"),e.serviceFactory("shortUrlDeleted",()=>sn),e.serviceFactory("getShortUrlDetail",L("getShortUrlDetail"),"shortUrlDetailReducerCreator"),e.serviceFactory("editShortUrl",Pl,"buildShlinkApiClient")},Xe=({children:e,label:t,className:r="",labelClassName:a="",noMargin:n=!1,id:i})=>o("div",{className:`${r} ${n?"":"mb-3"}`,children:[s("label",{className:`form-label ${a}`,htmlFor:i,children:t}),e]}),Pt=({children:e,value:t,onChange:r,type:a,required:n,placeholder:i,className:c,labelClassName:l})=>{const d=rs();return s(Xe,{label:o(w,{children:[e,":"]}),className:c??"",labelClassName:l,id:d,children:s("input",{id:d,className:"form-control",type:a??"text",value:t,required:n??!0,placeholder:i,onChange:h=>r(h.target.value)})})},hn=({onSubmit:e,initialValues:t,children:r,title:a})=>{const[n,i]=v.useState(""),[c,l]=v.useState(""),[d,h]=v.useState(""),u=ht(()=>e({name:n,url:c,apiKey:d}));return v.useEffect(()=>{t&&i(t.name),t&&l(t.url),t&&h(t.apiKey)},[t]),o("form",{className:"server-form",name:"serverForm",onSubmit:u,children:[o(j,{className:"mb-3",title:a,children:[s(Pt,{value:n,onChange:i,children:"Name"}),s(Pt,{type:"url",value:c,onChange:l,children:"URL"}),s(Pt,{value:d,onChange:h,children:"API key"})]}),s("div",{className:"text-end",children:r})]})},un=({isOpen:e,duplicatedServers:t,onDiscard:r,onSave:a})=>{const n=t.length>1;return o(de,{centered:!0,isOpen:e,children:[o(ye,{children:["Duplicated server",n&&"s"]}),o(he,{children:[s("p",{children:n?"The next servers already exist:":"There is already a server with:"}),s("ul",{children:t.map(({url:i,apiKey:c},l)=>n?o("li",{children:[s("b",{children:i})," - ",s("b",{children:c})]},l):o(v.Fragment,{children:[o("li",{children:["URL: ",s("b",{children:i})]}),o("li",{children:["API key: ",s("b",{children:c})]})]},l))}),o("span",{children:[n?"Do you want to ignore duplicated servers":"Do you want to save this server anyway","?"]})]}),o(ze,{children:[s(V,{color:"link",onClick:r,children:n?"Ignore duplicated":"Discard"}),s(V,{color:"primary",onClick:a,children:"Save anyway"})]})]})},kr=4e3,Tr=({type:e})=>s("div",{className:"mt-3",children:o(K,{type:e,children:[e==="success"&&"Servers properly imported. You can now select one from the list :)",e==="error"&&"The servers could not be imported. Make sure the format is correct."]})}),sd=(e,t)=>({servers:r,createServers:a})=>{const n=Fe(),i=Ne(),c=!!Object.keys(r).length,[l,d]=t(!1,kr),[h,u]=t(!1,kr),[p,m]=A(),[g,f]=v.useState(),C=()=>{if(!g)return;const R=Ls();a([{...g,id:R}]),n(`/server/${R}`)};return v.useEffect(()=>{Object.values(r).some(({url:_,apiKey:N})=>(g==null?void 0:g.url)===_&&(g==null?void 0:g.apiKey)===N)?m():C()},[g]),o(Ke,{children:[o(hn,{title:s("h5",{className:"mb-0",children:"Add new server"}),onSubmit:f,children:[!c&&s(e,{tooltipPlacement:"top",onImport:d,onImportError:u}),c&&s(V,{outline:!0,onClick:i,children:"Cancel"}),s(V,{outline:!0,color:"primary",className:"ms-2",children:"Create server"})]}),l&&s(Tr,{type:"success"}),h&&s(Tr,{type:"error"}),s(un,{isOpen:p,duplicatedServers:g?[g]:[],onDiscard:i,onSave:C})]})},rd=({servers:e,selectedServer:t})=>{const r=We(e);return o(Yt,{nav:!0,inNavbar:!0,children:[o(qe,{nav:!0,caret:!0,children:[s(y,{icon:ur})," ",s("span",{className:"ms-1",children:"Servers"})]}),s(Ve,{end:!0,style:{right:0},children:(()=>H(r)?o(b,{tag:$,to:"/server/create",children:[s(y,{icon:Es})," ",s("span",{className:"ms-1",children:"Add a server"})]}):o(w,{children:[r.map(({name:n,id:i})=>s(b,{tag:$,to:`/server/${i}`,active:lt(t)===i,children:n},i)),s(b,{divider:!0}),o(b,{tag:$,to:"/manage-servers",children:[s(y,{icon:ur})," ",s("span",{className:"ms-1",children:"Manage servers"})]})]}))()})]})},ad=({server:e,toggle:t,isOpen:r,deleteServer:a,redirectHome:n=!0})=>{const i=Fe(),c=v.useRef(!1),l=()=>{c.current=!0,t()};return o(de,{isOpen:r,toggle:t,centered:!0,onClosed:()=>{c.current&&(a(e),n&&i("/"))},children:[s(ye,{toggle:t,className:"text-danger",children:"Remove server"}),o(he,{children:[o("p",{children:["Are you sure you want to remove ",s("b",{children:e?e.name:""}),"?"]}),s("p",{children:s("i",{children:"No data will be deleted, only the access to this server will be removed from this device. You can create it again at any moment."})})]}),o(ze,{children:[s(V,{color:"link",onClick:t,children:"Cancel"}),s(V,{color:"danger",onClick:l,children:"Delete"})]})]})},nd=e=>({server:t,className:r,children:a,textClassName:n})=>{const[i,,c,l]=A();return o(w,{children:[o("span",{className:r,onClick:c,children:[!a&&s(y,{fixedWidth:!0,icon:js}),s("span",{className:n,children:a??"Remove this server"})]}),s(e,{server:t,isOpen:i,toggle:l})]})},id=e=>Ua(({editServer:t,selectedServer:r})=>{const a=Ne();if(!ge(r))return null;const n=i=>{t(r.id,i),a()};return s(Ke,{children:o(hn,{title:o("h5",{className:"mb-0",children:['Edit "',r.name,'"']}),initialValues:r,onSubmit:n,children:[s(V,{outline:!0,className:"me-2",onClick:a,children:"Cancel"}),s(V,{outline:!0,color:"primary",children:"Save"})]})})},e);const xr=e=>({url:t,apiKey:r})=>e.some(a=>a.url===t&&a.apiKey===r),od=({importServersFromFile:e})=>({createServers:t,servers:r,children:a,onImport:n=()=>{},onImportError:i=()=>{},tooltipPlacement:c="bottom",className:l=""})=>{const d=v.useRef(),[h,u]=v.useState(),[p,m]=v.useState([]),[g,,f,C]=A(),R=O(t,n),_=O(()=>R(h??[]),C),N=O(()=>R((h??[]).filter(Li(xr(p)))),C),D=async({target:S})=>{var U;return e((U=S.files)==null?void 0:U[0]).then(u).then(()=>{S.value=null}).catch(i)};return v.useEffect(()=>{if(!h)return;const S=Object.values(r),U=h.filter(xr(S)),B=!!U.length;B?m(U):R(h),B&&f()},[h]),o(w,{children:[o(V,{outline:!0,id:"importBtn",className:l,onClick:()=>{var S;return(S=d.current)==null?void 0:S.click()},children:[s(y,{icon:Ei,fixedWidth:!0})," ",a??"Import from file"]}),o(ee,{placement:c,target:"importBtn",children:["You can create servers by importing a CSV file with columns ",s("b",{children:"name"}),", ",s("b",{children:"apiKey"})," and ",s("b",{children:"url"}),"."]}),s("input",{type:"file",accept:"text/csv",className:"import-servers-btn__csv-select",ref:Nt(d),onChange:D}),s(un,{isOpen:g,duplicatedServers:p,onDiscard:N,onSave:_})]})},Zs="shlink/selectedServer",cd="1.0.0",ld="999.999.999",dd="latest",hd=O(e=>e===dd?ld:e,La(cd)),ud=ea(Kt,async(e,t)=>t().then(({version:r})=>({version:hd(r),printableVersion:xa(r)}))),Lr=null,er=ie(`${Zs}/resetSelectedServer`),md=e=>z(`${Zs}/selectServer`,async(t,{dispatch:r,getState:a})=>{r(er());const{servers:n}=a(),i=n[t];if(!i)return{serverNotFound:!0};try{const{health:c}=e(i),{version:l,printableVersion:d}=await ud(t,c);return{...i,version:l,printableVersion:d}}catch{return{...i,serverNotReachable:!0}}}),gd=(e,t)=>{const r=Ii();return r.startListening({actionCreator:e.fulfilled,effect:({payload:a},{dispatch:n})=>{Zt(a)&&n(t())}}),r},pd=e=>W({name:Zs,initialState:Lr,reducers:{},extraReducers:t=>{t.addCase(er,()=>Lr),t.addCase(e.fulfilled,(r,{payload:a})=>a)}}),vd={},fd=e=>e.id?e:jt("id",Ls(),e),Cd=Fi((e,t)=>jt(t.id,t,e),{}),{actions:Sd,reducer:yd}=W({name:"shlink/servers",initialState:vd,reducers:{editServer:{prepare:(e,t)=>({payload:{serverId:e,serverData:t}}),reducer:(e,{payload:t})=>{const{serverId:r,serverData:a}=t;return e[r]?jt(r,{...e[r],...a},e):e}},deleteServer:(e,{payload:t})=>Vi(t.id,e),setAutoConnect:{prepare:({id:e},t)=>({payload:{serverId:e,autoConnect:t}}),reducer:(e,{payload:t})=>{const{serverId:r,autoConnect:a}=t;return e[r]?a?Je(Bt(e).map(([n,i])=>[n,{...i,autoConnect:n===r}])):jt(r,{...e[r],autoConnect:a},e):e}},createServers:{prepare:O(ma(fd),Cd,e=>({payload:e})),reducer:(e,{payload:t})=>({...e,...t})}}}),{editServer:Nd,deleteServer:bd,setAutoConnect:Rd,createServers:mn}=Sd,wd=yd,Dd=e=>Array.isArray(e)?e.filter(Gs):[],_d=e=>z("shlink/remoteServers/fetchServers",async(t,{dispatch:r})=>{const a=await e.fetchJson(`${Gt.homepage}/servers.json`),n=Dd(a);r(mn(n))});const Ud=e=>({servers:t,selectedServer:r})=>s(Ke,{children:o("div",{className:"server-error__container flex-column",children:[o(ce,{className:"w-100 mb-3 mb-md-5",type:"error",fullWidth:!0,children:[!ge(r)&&"Could not find this Shlink server.",ge(r)&&o(w,{children:[s("p",{children:"Oops! Could not connect to this Shlink server."}),"Make sure you have internet connection, and the server is properly configured and on-line."]})]}),o(_a,{servers:Object.values(t),children:["These are the Shlink servers currently configured. Choose one of them or ",s($,{to:"/server/create",children:"add a new one"}),"."]}),ge(r)&&s("div",{className:"container mt-3 mt-md-5",children:o("h5",{children:["Alternatively, if you think you may have miss-configured this server, you can ",s(e,{server:r,className:"server-error__delete-btn",children:"remove it"})," or ",s($,{to:`/server/${r.id}/edit`,children:"edit it"}),"."]})})]})});const kd=e=>e?{tag:$,to:e}:{},xt=({children:e,title:t,link:r})=>o(Y,{className:"highlight-card",body:!0,...kd(r),children:[r&&s(y,{size:"3x",className:"highlight-card__link-icon",icon:Mi}),s(Oi,{tag:"h5",className:"highlight-card__title",children:t}),s($i,{tag:"h2",children:e})]}),Td=(e,t)=>Re(({shortUrlsList:r,listShortUrls:a,listTags:n,tagsList:i,selectedServer:c,loadVisitsOverview:l,visitsOverview:d})=>{const{loading:h,shortUrls:u}=r,{loading:p}=i,{loading:m,visitsCount:g,orphanVisitsCount:f}=d,C=lt(c),R=qs(c),_=Fe();return v.useEffect(()=>{a({itemsPerPage:an,orderBy:{field:"dateCreated",dir:"DESC"}}),n(),l()},[]),o(w,{children:[o(Q,{children:[s("div",{className:"col-lg-6 col-xl-3 mb-3",children:s(xt,{title:"Visits",link:R&&`/server/${C}/non-orphan-visits`,children:m?"Loading...":G(g)})}),s("div",{className:"col-lg-6 col-xl-3 mb-3",children:s(xt,{title:"Orphan visits",link:`/server/${C}/orphan-visits`,children:m?"Loading...":G(f)})}),s("div",{className:"col-lg-6 col-xl-3 mb-3",children:s(xt,{title:"Short URLs",link:`/server/${C}/list-short-urls/1`,children:h?"Loading...":G((u==null?void 0:u.pagination.totalItems)??0)})}),s("div",{className:"col-lg-6 col-xl-3 mb-3",children:s(xt,{title:"Tags",link:`/server/${C}/manage-tags`,children:p?"Loading...":G(i.tags.length)})})]}),o(Y,{className:"mb-3",children:[o(rt,{children:[s("span",{className:"d-sm-none",children:"Create a short URL"}),s("h5",{className:"d-none d-sm-inline",children:"Create a short URL"}),s($,{className:"float-end",to:`/server/${C}/create-short-url`,children:"Advanced options »"})]}),s(at,{children:s(t,{basicMode:!0})})]}),o(Y,{children:[o(rt,{children:[s("span",{className:"d-sm-none",children:"Recently created URLs"}),s("h5",{className:"d-none d-sm-inline",children:"Recently created URLs"}),s($,{className:"float-end",to:`/server/${C}/list-short-urls/1`,children:"See all »"})]}),s(at,{children:s(e,{shortUrlsList:r,selectedServer:c,className:"mb-0",onTagClick:N=>_(`/server/${C}/list-short-urls/1?tags=${encodeURIComponent(N)}`)})})]})]})},()=>[J.visits,J.orphanVisits]),xd=4e3,Ld=(e,t,r,a)=>({servers:n})=>{const i=Object.values(n),[c,l]=v.useState(i),d=m=>l(i.filter(({name:g,url:f})=>`${g} ${f}`.toLowerCase().match(m.toLowerCase()))),h=c.some(({autoConnect:m})=>!!m),[u,p]=r(!1,xd);return v.useEffect(()=>{l(Object.values(n))},[n]),o(Ke,{children:[s(mt,{className:"mb-3",onChange:d}),o(Q,{className:"mb-3",children:[o("div",{className:"col-md-6 d-flex d-md-block mb-2 mb-md-0",children:[s(t,{className:"flex-fill",onImportError:p,children:"Import servers"}),i.length>0&&o(V,{outline:!0,className:"ms-2 flex-fill",onClick:async()=>e.exportServers(),children:[s(y,{icon:ua,fixedWidth:!0})," Export servers"]})]}),s("div",{className:"col-md-6 text-md-end d-flex d-md-block",children:o(V,{outline:!0,color:"primary",className:"flex-fill",tag:$,to:"/server/create",children:[s(y,{icon:Es,fixedWidth:!0})," Add a server"]})})]}),s(j,{children:o("table",{className:"table table-hover responsive-table mb-0",children:[s("thead",{className:"responsive-table__header",children:o("tr",{children:[h&&s("th",{"aria-label":"Auto-connect",style:{width:"50px"}}),s("th",{children:"Name"}),s("th",{children:"Base URL"}),s("th",{"aria-label":"Options"})]})}),o("tbody",{children:[!c.length&&s("tr",{className:"text-center",children:s("td",{colSpan:4,children:"No servers found."})}),c.map(m=>s(a,{server:m,hasAutoConnect:h},m.id))]})]})}),u&&s("div",{className:"mt-3",children:s(K,{type:"error",children:"The servers could not be imported. Make sure the format is correct."})})]})},Ed=e=>({server:t,hasAutoConnect:r})=>o("tr",{className:"responsive-table__row",children:[r&&s("td",{className:"responsive-table__cell","data-th":"Auto-connect",children:t.autoConnect&&o(w,{children:[s(y,{icon:it,className:"text-primary",id:"autoConnectIcon"}),s(ee,{target:"autoConnectIcon",placement:"right",children:"Auto-connect to this server"})]})}),s("th",{className:"responsive-table__cell","data-th":"Name",children:s($,{to:`/server/${t.id}`,children:t.name})}),s("td",{className:"responsive-table__cell","data-th":"Base URL",children:t.url}),s("td",{className:"responsive-table__cell text-end",children:s(e,{server:t})})]}),Id=e=>({server:t,setAutoConnect:r})=>{const[a,n]=A(),[i,,c,l]=A(),d=`/server/${t.id}`,{autoConnect:h}=t,u=h?Pi:Bi;return o(ns,{isOpen:a,toggle:n,children:[o(b,{tag:$,to:d,children:[s(y,{icon:Ai,fixedWidth:!0})," Connect"]}),o(b,{tag:$,to:`${d}/edit`,children:[s(y,{icon:Bs,fixedWidth:!0})," Edit server"]}),o(b,{onClick:()=>r(t,!h),children:[s(y,{icon:u,fixedWidth:!0})," ",h?"Do not a":"A","uto-connect"]}),s(b,{divider:!0}),o(b,{className:"dropdown-item--danger",onClick:c,children:[s(y,{icon:js,fixedWidth:!0})," Remove server"]}),s(e,{redirectHome:!1,server:t,isOpen:i,toggle:l})]})},Fd=e=>typeof e.url=="string"&&typeof e.apiKey=="string"&&typeof e.name=="string",Vd=e=>Array.isArray(e)&&e.every(Fd);class Md{constructor(t,r){T(this,"importServersFromFile",async t=>{if(!t)throw new Error("No file provided");const r=this.fileReaderFactory();return new Promise((a,n)=>{r.addEventListener("loadend",async i=>{var c,l;try{const d=((l=(c=i.target)==null?void 0:c.result)==null?void 0:l.toString())??"",h=await this.csvToJson(d);if(!Vd(h))throw new Error("Provided file does not have the right format.");a(h)}catch(d){n(d)}}),r.readAsText(t)})});this.csvToJson=t,this.fileReaderFactory=r}}const Od="shlink-servers.csv";class $d{constructor(t,r,a){T(this,"exportServers",async()=>{const t=We(this.storage.get("servers")??{}).map(Ho);try{const r=this.jsonToCsv(t);Oa(this.window,r,Od)}catch(r){console.error(r)}});this.storage=t,this.window=r,this.jsonToCsv=a}}const Ad=(e,t)=>{e.serviceFactory("ManageServers",Ld,"ServersExporter","ImportServersBtn","useTimeoutToggle","ManageServersRow"),e.decorator("ManageServers",Ht),e.decorator("ManageServers",t(["selectedServer","servers"],["resetSelectedServer"])),e.serviceFactory("ManageServersRow",Ed,"ManageServersRowDropdown"),e.serviceFactory("ManageServersRowDropdown",Id,"DeleteServerModal"),e.decorator("ManageServersRowDropdown",t(null,["setAutoConnect"])),e.serviceFactory("CreateServer",sd,"ImportServersBtn","useTimeoutToggle"),e.decorator("CreateServer",Ht),e.decorator("CreateServer",t(["selectedServer","servers"],["createServers","resetSelectedServer"])),e.serviceFactory("EditServer",id,"ServerError"),e.decorator("EditServer",t(["selectedServer"],["editServer","selectServer","resetSelectedServer"])),e.serviceFactory("ServersDropdown",()=>rd),e.decorator("ServersDropdown",t(["servers","selectedServer"])),e.serviceFactory("DeleteServerModal",()=>ad),e.decorator("DeleteServerModal",t(null,["deleteServer"])),e.serviceFactory("DeleteServerButton",nd,"DeleteServerModal"),e.serviceFactory("ImportServersBtn",od,"ServersImporter"),e.decorator("ImportServersBtn",t(["servers"],["createServers"])),e.serviceFactory("ServerError",Ud,"DeleteServerButton"),e.decorator("ServerError",t(["servers","selectedServer"])),e.serviceFactory("Overview",Td,"ShortUrlsTable","CreateShortUrl"),e.decorator("Overview",t(["shortUrlsList","tagsList","selectedServer","mercureInfo","visitsOverview"],["listShortUrls","listTags","createNewVisits","loadMercureInfo","loadVisitsOverview"])),e.constant("fileReaderFactory",()=>new FileReader),e.service("ServersImporter",Md,"csvToJson","fileReaderFactory"),e.service("ServersExporter",$d,"Storage","window","jsonToCsv"),e.serviceFactory("selectServer",md,"buildShlinkApiClient","loadMercureInfo"),e.serviceFactory("createServers",()=>mn),e.serviceFactory("deleteServer",()=>bd),e.serviceFactory("editServer",()=>Nd),e.serviceFactory("setAutoConnect",()=>Rd),e.serviceFactory("fetchServers",_d,"HttpClient"),e.serviceFactory("resetSelectedServer",()=>er),e.serviceFactory("selectServerListener",gd,"selectServer","loadMercureInfo"),e.serviceFactory("selectedServerReducerCreator",pd,"selectServer"),e.serviceFactory("selectedServerReducer",L("reducer"),"selectedServerReducerCreator")};const Pd=()=>s(Wi,{attribution:'© <a href="https://osm.org/copyright">OpenStreetMap</a> contributors',url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}),Bd=e=>{if(e.length===0)return{};if(e.length>1)return{bounds:e.map(L("latLong"))};const[{latLong:t}]=e;return{zoom:10,center:t}},gn=({toggle:e,isOpen:t,title:r,locations:a=[]})=>s(de,{toggle:e,isOpen:t,className:"map-modal__modal",contentClassName:"map-modal__modal-content",children:o(he,{className:"map-modal__modal-body",children:[o("h3",{className:"map-modal__modal-title",children:[r,s("button",{type:"button",className:"btn-close float-end","aria-label":"Close",onClick:e})]}),o(ji,{...Bd(a),children:[s(Pd,{}),a.map(({cityName:n,latLong:i,count:c},l)=>s(Gi,{position:i,children:o(Hi,{children:[s("b",{children:c})," visit",c>1?"s":""," from ",s("b",{children:n})]})},l))]})]})}),bt=({visits:e,goBack:t,shortUrl:r,children:a,title:n})=>s("header",{children:o(Y,{body:!0,children:[o("h2",{className:"d-flex justify-content-between align-items-center mb-0",children:[s(V,{color:"link",size:"lg",className:"p-0 me-3",onClick:t,children:s(y,{icon:ha})}),s("span",{className:"text-center d-none d-sm-block",children:s("small",{children:n})}),o("span",{className:"badge badge-main ms-3",children:["Visits:"," ",s(tn,{visitsCount:e.length,shortUrl:r})]})]}),s("h3",{className:"text-center d-block d-sm-none mb-0 mt-3",children:s("small",{children:n})}),a&&s("div",{className:"mt-md-2",children:a})]})});const jd=({shortUrlDetail:e,shortUrlVisits:t,goBack:r})=>{const{shortUrl:a,loading:n}=e,{visits:i}=t,c=(a==null?void 0:a.shortUrl)??"",l=(a==null?void 0:a.longUrl)??"",d=a==null?void 0:a.title;return o(bt,{title:o(w,{children:["Visits for ",s(ae,{href:c})]}),goBack:r,visits:i,shortUrl:a,children:[s("hr",{}),o("div",{children:["Created: ",(()=>a?o("span",{children:[s("b",{id:"created",className:"short-url-visits-header__created-at",children:s(zt,{date:a.dateCreated,relative:!0})}),s(ee,{placement:"bottom",target:"created",children:s(zt,{date:a.dateCreated})})]}):s("small",{children:"Loading..."}))()]}),o("div",{className:"long-url-container",children:[`${d?"Title":"Long URL"}: `,n&&s("small",{children:"Loading..."}),!n&&s(ae,{href:l,children:d??l})]})]})};const st=({children:e,...t})=>s(Yr,{className:"nav-pills__nav-link",tag:ra,...t,children:e}),pn=({children:e,fill:t=!1,className:r=""})=>s(Y,{className:`nav-pills__nav p-0 overflow-hidden ${r}`,body:!0,children:s(Jr,{pills:!0,fill:t,children:v.Children.map(e,a=>{if(!v.isValidElement(a)||a.type!==st)throw new Error("Only NavPillItem children are allowed inside NavPills.");return a})})}),Lt="Others",Gd=["Android Browser","Chrome","Chromium","Firefox","Internet Explorer","Microsoft Edge","Opera","Safari","Samsung Internet for Android","Vivaldi","WeChat"],Hd=e=>{if(!se(e))return{browser:Lt,os:Lt};const{browser:{name:t},os:{name:r}}=qi.parse(e);return{os:r??Lt,browser:t&&Gd.includes(t)?t:Lt}},Wd=e=>{var t;return se(e)?((t=e.split("/")[e.includes("://")?2:0])==null?void 0:t.split(":")[0])??"":"Direct"},tr=(e,t)=>Object.values({...ga(t,t.map(()=>0)),...e}),He=e=>s(cn,{type:"switch",...e}),vn=({native:e},[t])=>{if(!(e!=null&&e.target))return;const r=e.target;r.style.cursor=t?"pointer":"default"},fn=({dataset:e,raw:t})=>`${e.label}: ${G(`${t}`)}`,qd=({label:e,raw:t})=>`${e}: ${G(`${t}`)}`;const Er={monthly:"Month",weekly:"Week",daily:"Day",hourly:"Hour"},zd={hourly:e=>({hours:e}),daily:e=>({days:e}),weekly:e=>({weeks:e}),monthly:e=>({months:e})},Qd={hourly:Ji,daily:pa,weekly:Yi,monthly:ws},sr={hourly:e=>Ie(e,"yyyy-MM-dd HH:00"),daily:e=>Ie(e,Ze),weekly(e){const t=Ie(Qi(e),Ze),r=Ie(Ki(e),Ze);return`${t} - ${r}`},monthly:e=>Ie(e,"yyyy-MM")},Kd=e=>{const t=new Date,r=pe(e);return Jt([[()=>pa(t,r)<=2,os("hourly")],[()=>ws(t,r)<=1,os("daily")],[()=>ws(t,r)<=6,os("weekly")]])()??"monthly"},Ir=(e,t)=>va(r=>sr[e](pe(r.date)),t),Xd=(e,t)=>t.reduce((r,a)=>{const n=sr[e](pe(a.date));return r[n]=r[n]??[],r[n].push(a),r},{}),Jd=(e,t)=>{const r=Qd[e],a=sr[e],n=pe(t[0].date),i=pe(t[t.length-1].date),c=r(n,i),l=zd[e];return[a(i),...Ws(c,d=>a(Xi(i,l(d))))]},Yd=(e,t,r,a)=>{if(a)return[Object.keys(t),Object.values(t)];const n=Jd(r,e);return[n,tr(t,n)]},Fr=(e,t,r)=>({label:t,data:e,fill:!1,tension:.2,borderColor:r,backgroundColor:r});let gs=null;const Zd=(e,t,[r],a)=>{if(!a||!r)return;const{index:n}=r;gs===e[n]?(a([]),gs=null):(a(e[n]&&t[e[n]]?t[e[n]]:[]),gs=e[n]??null)},eh=({title:e,visits:t,highlightedVisits:r,highlightedLabel:a="Selected",setSelectedVisits:n})=>{const[i,c]=v.useState(t.length>0?Kd(t[t.length-1].date):"monthly"),[l,d]=A(!0),h=v.useRef(null),u=v.useRef(null),p=v.useMemo(()=>Xd(i,t),[i,t]),m=v.useMemo(()=>Ir(i,Rs(t)),[i,t]),[g,f]=v.useMemo(()=>Yd(t,m,i,l),[t,i,l]),C=v.useMemo(()=>tr(Ir(i,Rs(r)),g),[r,i,g]),R=()=>{const S=Fr(f,"Visits",Hs);if(r.length===0)return[S];const U=Fr(C,a,Ra);return[S,U]},_=()=>({labels:g,datasets:R()}),N={maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{intersect:!1,axis:"x",callbacks:{label:fn}}},scales:{y:{beginAtZero:!0,ticks:{precision:0,callback:G}},x:{title:{display:!0,text:Er[i]}}},onHover:vn},D=S=>s(zi,{ref:S,data:_(),options:N,onClick:U=>Zd(g,p,fa(S.current,U),n)});return o(Y,{children:[o(rt,{role:"heading",children:[e,s("div",{className:"float-end",children:o(Yt,{children:[s(qe,{caret:!0,color:"link",className:"btn-sm p-0",children:"Group by"}),s(Ve,{end:!0,children:Object.entries(Er).map(([S,U])=>s(b,{active:i===S,onClick:()=>c(S),children:U},S))})]})}),s("div",{className:"float-end me-2",children:s(He,{checked:l,onChange:d,children:s("small",{children:"Skip dates with no visits"})})})]}),o(at,{className:"line-chart-card__body",children:[r.length>0&&D(h),r.length===0&&D(u)]})]})};const rr=({pagesCount:e,currentPage:t,setCurrentPage:r,centered:a=!0})=>{if(e<2)return null;const n=i=>()=>!ct(i)&&r(i);return o(ca,{listClassName:x("flex-wrap mb-0 simple-paginator",{"justify-content-center":a}),children:[s(Be,{disabled:t<=1,children:s(je,{previous:!0,tag:"span",onClick:n(t-1)})}),Qa(t,e).map((i,c)=>s(Be,{disabled:ct(i),active:t===i,children:s(je,{role:"link",tag:"span",onClick:n(i),children:Ka(i)})},Xa(i,c))),s(Be,{disabled:t>=e,children:s(je,{next:!0,tag:"span",onClick:n(t+1)})})]})};const Ye=20,th=({browser:e,os:t,referer:r,country:a,city:n,...i},c)=>`${e} ${t} ${r} ${a} ${n} ${i.visitedUrl}`.toLowerCase().includes(c.toLowerCase()),sh=(e,t)=>t.filter(r=>th(r,e)),rh=(e,t)=>Na(t,e),ah=(e,t,r)=>{const a=t?sh(t,e):[...e],n=rh(r,a),i=n.length;return{visitsGroups:nt(Ye,n),total:i}},nh=({visits:e,selectedVisits:t=[],setSelectedVisits:r,matchMedia:a=window.matchMedia,isOrphanVisits:n=!1})=>{var B,I;const i="visits-table__header-cell visits-table__sticky",c=()=>a("(max-width: 767px)").matches,[l,d]=v.useState(c()),[h,u]=v.useState(void 0),[p,m]=v.useState({}),g=v.useMemo(()=>ah(e,h,p),[h,p]),f=v.useRef(!0),[C,R]=v.useState(1),_=C*Ye,N=_-Ye,D=8+Number(n),S=k=>()=>m({field:k,dir:es(k,p.field,p.dir)}),U=k=>s(et,{currentOrder:p,field:k,className:"visits-table__header-icon"});return v.useEffect(()=>{const k=()=>d(c());return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]),v.useEffect(()=>{R(1),!f.current&&r([]),f.current=!1},[h]),s("div",{className:"table-responsive-md",children:o("table",{className:"table table-bordered table-hover table-sm visits-table",children:[o("thead",{className:"visits-table__header",children:[o("tr",{children:[s("th",{className:`${i} text-center`,onClick:()=>r(t.length<g.total?g.visitsGroups.flat():[]),children:s(y,{icon:it,className:x({"text-primary":t.length>0})})}),o("th",{className:`${i} text-center`,onClick:S("potentialBot"),children:[s(y,{icon:mr}),U("potentialBot")]}),o("th",{className:i,onClick:S("date"),children:["Date",U("date")]}),o("th",{className:i,onClick:S("country"),children:["Country",U("country")]}),o("th",{className:i,onClick:S("city"),children:["City",U("city")]}),o("th",{className:i,onClick:S("browser"),children:["Browser",U("browser")]}),o("th",{className:i,onClick:S("os"),children:["OS",U("os")]}),o("th",{className:i,onClick:S("referer"),children:["Referrer",U("referer")]}),n&&o("th",{className:i,onClick:S("visitedUrl"),children:["Visited URL",U("visitedUrl")]})]}),s("tr",{children:s("td",{colSpan:D,className:"p-0",children:s(mt,{noBorder:!0,large:!1,onChange:u})})})]}),o("tbody",{children:[!((B=g.visitsGroups[C-1])!=null&&B.length)&&s("tr",{children:s("td",{colSpan:D,className:"text-center",children:"No visits found with current filtering"})}),(I=g.visitsGroups[C-1])==null?void 0:I.map((k,E)=>{const M=t.includes(k);return o("tr",{style:{cursor:"pointer"},className:x({"table-active":M}),onClick:()=>r(M?t.filter(ue=>ue!==k):[...t,k]),children:[s("td",{className:"text-center",children:M&&s(y,{icon:it,className:"text-primary"})}),s("td",{className:"text-center",children:k.potentialBot&&o(w,{children:[s(y,{icon:mr,id:`botIcon${E}`}),s(ee,{placement:"right",target:`botIcon${E}`,children:"Potentially a visit from a bot or crawler"})]})}),s("td",{children:s(zt,{date:k.date})}),s("td",{children:k.country}),s("td",{children:k.city}),s("td",{children:k.browser}),s("td",{children:k.os}),s("td",{children:k.referer}),n&&s("td",{children:k.visitedUrl})]},E)})]}),g.total>Ye&&s("tfoot",{children:s("tr",{children:s("td",{colSpan:D,className:"visits-table__footer-cell visits-table__sticky",children:o("div",{className:"row",children:[s("div",{className:"col-md-6",children:s(rr,{pagesCount:Math.ceil(g.total/Ye),currentPage:C,setCurrentPage:R,centered:l})}),s("div",{className:x("col-md-6",{"d-flex align-items-center flex-row-reverse":!l,"text-center mt-3":l}),children:o("div",{children:["Visits ",s("b",{children:G(N+1)})," to"," ",s("b",{children:G(oa(_,g.total))})," of"," ",s("b",{children:G(g.total)})]})})]})})})})]})})};const ih=({modalTitle:e,activeCities:t,locations:r=[]})=>{const[a,,n,i]=A(),[c,l,d]=A(),[h,u]=v.useState([]),p=rs(),m=C=>t?C.filter(({cityName:R})=>t==null?void 0:t.includes(R)):C,g=()=>{if(!t){u(r),n();return}d()},f=C=>()=>{u(C?m(r):r),n()};return o(w,{children:[s(V,{color:"link",className:"open-map-modal-btn__btn",id:p,onClick:g,children:s(y,{icon:Ca})}),s(ee,{placement:"left",target:p,children:"Show in map"}),s(aa,{isOpen:c,toggle:l,inNavbar:!0,children:o(Ve,{end:!0,children:[s(b,{onClick:f(!1),children:"Show all locations"}),s(b,{onClick:f(!0),children:"Show locations in current page"})]})}),s(gn,{toggle:i,isOpen:a,title:e,locations:h})]})},ar=e=>e.visitedUrl!==void 0,oh=e=>e.visitedUrl!==void 0,ch=O(Zi(e=>ar(e.visit)?"orphanVisits":"regularVisits"),e=>({orphanVisits:[],regularVisits:[],...e})),Et=(e,t)=>va(L(t),e),Rt=({page:e,itemsPerPage:t,filter:r,dateRange:a})=>{const n=((a==null?void 0:a.startDate)&&fe(a==null?void 0:a.startDate))??void 0,i=((a==null?void 0:a.endDate)&&fe(a==null?void 0:a.endDate))??void 0,c=(r==null?void 0:r.excludeBots)||void 0;return{page:e,itemsPerPage:t,startDate:n,endDate:i,excludeBots:c}},Cn=(e,t)=>!Ce(e)&&se(e[t]),Vr=e=>typeof e=="number"?e:e?parseFloat(e):0,lh=(e,{os:t})=>{e[t]=(e[t]||0)+1},dh=(e,{browser:t})=>{e[t]=(e[t]||0)+1},hh=(e,{referer:t})=>{e[t]=(e[t]||0)+1},Sn=e=>(t,r)=>{const n=Cn(r,e)?r[e]:"Unknown";t[n]=(t[n]||0)+1},uh=Sn("country"),mh=Sn("city"),gh=(e,t)=>{if(!Cn(t,"city")||t.city==="Unknown")return;const{city:r,latitude:a,longitude:n}=t,i=e[r]||{cityName:r,count:0,latLong:[Vr(a),Vr(n)]};i.count+=1,e[r]=i},ph=(e,t)=>{if(!oh(t))return;const{visitedUrl:r}=t;e[r]=(e[r]||0)+1},yn=e=>e.reduce((t,r)=>(lh(t.os,r),dh(t.browsers,r),hh(t.referrers,r),uh(t.countries,r),mh(t.cities,r),gh(t.citiesForMap,r),ph(t.visitedUrls,r),t),{os:{},browsers:{},referrers:{},countries:{},cities:{},citiesForMap:{},visitedUrls:{}}),Nn=ma(e=>{const{userAgent:t,date:r,referer:a,visitLocation:n,potentialBot:i}=e,c={date:r,potentialBot:i,...Hd(t),referer:Wd(a),country:(n==null?void 0:n.countryName)||"Unknown",city:(n==null?void 0:n.cityName)||"Unknown",latitude:n==null?void 0:n.latitude,longitude:n==null?void 0:n.longitude};return ar(e)?{...c,type:e.type,visitedUrl:e.visitedUrl}:c}),vh=Object.freeze(Object.defineProperty({__proto__:null,processStatsFromVisits:yn,normalizeVisits:Nn},Symbol.toStringTag,{value:"Module"})),fh=({onChange:e,selected:t={},className:r,isOrphanVisits:a})=>{const{orphanVisitsType:n,excludeBots:i=!1}=t,c=d=>({active:n===d,onClick:()=>e({...t,orphanVisitsType:d===(t==null?void 0:t.orphanVisitsType)?void 0:d})});return o(be,{text:"Filters",dropdownClassName:r,className:"me-3",right:!0,minWidth:250,children:[s(b,{header:!0,children:"Bots:"}),s(b,{active:i,onClick:()=>e({...t,excludeBots:!(t!=null&&t.excludeBots)}),children:"Exclude potential bots"}),a&&o(w,{children:[s(b,{divider:!0}),s(b,{header:!0,children:"Orphan visits type:"}),s(b,{...c("base_url"),children:"Base URL"}),s(b,{...c("invalid_short_url"),children:"Invalid short URL"}),s(b,{...c("regular_404"),children:"Regular 404"})]}),s(b,{divider:!0}),s(b,{disabled:!se(t),onClick:()=>e({excludeBots:!1,orphanVisitsType:void 0}),children:s("i",{children:"Clear filters"})})]})};const Ch=({chart:e})=>{const{config:t}=e,{labels:r=[],datasets:a=[]}=t.data??{},[{backgroundColor:n}]=a,{defaultColor:i}=t.options??{};return s("ul",{className:"doughnut-chart-legend",children:r.map((c,l)=>o("li",{className:"doughnut-chart-legend__item d-flex",children:[s("div",{className:"doughnut-chart-legend__item-color",style:{backgroundColor:n[l]??i}}),s("small",{className:"doughnut-chart-legend__item-text flex-fill",children:c})]},c))})},Sh=e=>[{data:e,backgroundColor:["#97BBCD","#F7464A","#46BFBD","#FDB45C","#949FB1","#57A773","#414066","#08B2E3","#B6C454","#DCDCDC","#463730"],borderColor:gc()?mc:uc,borderWidth:2}],yh=(e,t)=>({labels:e,datasets:Sh(t)}),Nh=v.memo(({stats:e})=>{const[t,r]=v.useState(),a=Ds(e),n=We(e),i={plugins:{legend:{display:!1},tooltip:{intersect:!0,callbacks:{label:qd}}}},c=yh(a,n);return o("div",{className:"row",children:[s("div",{className:"col-sm-12 col-md-7",children:s(eo,{height:300,data:c,options:i,ref:l=>{r(l??void 0)}})}),s("div",{className:"col-sm-12 col-md-5",children:t&&s(Ch,{chart:t})})]})});const bn=({title:e,footer:t,children:r})=>o(Y,{role:"document",children:[s(rt,{className:"chart-card__header",children:typeof e=="function"?e():e}),s(at,{children:r}),t&&s(to,{className:"chart-card__footer--sticky",children:t})]}),Mr=({title:e,stats:t})=>s(bn,{title:e,children:s(Nh,{stats:t})}),bh=({toggleClassName:e,ranges:t,value:r,setValue:a})=>o(Yt,{children:[s(qe,{caret:!0,color:"link",className:e,children:"Paginate"}),o(Ve,{end:!0,children:[t.map(n=>o(b,{active:n===r,onClick:()=>a(n),children:[s("b",{children:n})," items per page"]},n)),s(b,{divider:!0}),s(b,{disabled:r===1/0,onClick:()=>a(1/0),children:s("i",{children:"Clear pagination"})})]})]}),Rh=e=>e.startsWith("hidden")?"":e,wh=e=>!!e&&Object.keys(e).length>0,Dh=e=>e.length>20?e.length*10:void 0,_h=(e,t,r)=>{const a={data:e,label:r?"Non-selected":"Visits",backgroundColor:dc,borderColor:Hs,borderWidth:2};return t.every(i=>i===0)?[a]:[a,{label:r??"Selected",data:t,backgroundColor:hc,borderColor:Ra,borderWidth:2}]},Uh=(e,t,r,a)=>({labels:e,datasets:_h(t,r,a)}),kh=(e,[t],r)=>{!r||!t||r(e[t.index])},Th=({stats:e,highlightedStats:t,highlightedLabel:r,onClick:a,max:n})=>{const i=Ds(e).map(Rh),c=We(wh(t)?Ds(t).reduce((f,C)=>(f[C]&&(f[C]-=t[C]),f),{...e}):e),l=tr(t??{},i),d=v.useRef(null),h=v.useRef(null),u={plugins:{legend:{display:!1},tooltip:{mode:"y",filter:({label:f})=>f!=="",callbacks:{label:fn}}},scales:{x:{beginAtZero:!0,stacked:!0,max:n,ticks:{precision:0,callback:G}},y:{stacked:!0}},onHover:vn,indexAxis:"y"},p=Uh(i,c,l,r),m=Dh(i),g=(f,C)=>s(so,{ref:C,data:p,options:u,height:m,onClick:R=>kh(i,fa(C.current,R),a)},`${m}_${f}`);return o(w,{children:[t!==void 0&&g("with_stats",d),t===void 0&&g("without_stats",h)]})},xh=e=>ao(e)==="String"?no(e):e,Or=([e])=>e,$r=([,e])=>e,It=({stats:e,highlightedStats:t,title:r,sortingItems:a,extraHeaderContent:n,withPagination:i=!0,...c})=>{const[l,d]=v.useState({}),[h,u]=v.useState(1),[p,m]=v.useState(50),g=(I,k)=>{const E=Bt(I),M=l.field?ro(O(l.field===Object.keys(k)[0]?Or:$r,xh),E):E;return!l.dir||l.dir==="ASC"?M:Rs(M)},f=I=>{const k=I[h-1];if(h<I.length)return k;const E=I[0].length;return[...k,...Ws(E-k.length,M=>[`hidden_${M}`,0])]},C=I=>s(rr,{currentPage:h,pagesCount:I,setCurrentPage:u}),R=(I,k,E)=>{const M=g(I,k),ue=M.map(Or),me=E&&Bt({...ga(ue,ue.map(()=>0)),...E});if(M.length<=p)return{currentPageStats:Je(M),currentPageHighlightedStats:me&&Je(me)};const De=nt(p,M),_e=me&&nt(p,me);return{currentPageStats:Je(f(De)),currentPageHighlightedStats:_e&&Je(f(_e)),pagination:C(De.length),max:hl(Math.max(...M.map($r)))}},{currentPageStats:_,currentPageHighlightedStats:N,pagination:D,max:S}=R(e,a,t&&Object.keys(t).length>0?t:void 0),U=Object.keys(_);return s(bn,{title:()=>o(w,{children:[r,s("div",{className:"float-end",children:s(vt,{isButton:!1,right:!0,items:a,order:l,onChange:(I,k)=>{d({field:I,dir:k}),u(1)}})}),i&&Object.keys(e).length>50&&s("div",{className:"float-end",children:s(bh,{toggleClassName:"btn-sm p-0 me-3",ranges:[50,100,200,500],value:p,setValue:I=>{m(I),u(1)}})}),n&&s("div",{className:"float-end",children:n(D?U:void 0)})]}),footer:D,children:s(Th,{stats:_,highlightedStats:N,max:S,...c})})},Lh=()=>{const e=Fe(),{search:t}=Z(),{filtering:r,domain:a}=v.useMemo(O(()=>Qe(t),({startDate:i,endDate:c,orphanVisitsType:l,excludeBots:d,domain:h})=>({domain:h,filtering:{dateRange:i!=null||c!=null?Ga(i,c):void 0,visitsFilter:{orphanVisitsType:l,excludeBots:Ce(d)?void 0:d==="true"}}})),[t]);return[r,i=>{const{dateRange:c,visitsFilter:l}=ia(r,i),{excludeBots:d,orphanVisitsType:h}=l,u={startDate:(c==null?void 0:c.startDate)&&fe(c.startDate)||"",endDate:(c==null?void 0:c.endDate)&&fe(c.endDate)||"",excludeBots:d===void 0?void 0:ka(d),orphanVisitsType:h,domain:a},p=dt(u),m=H(p)?"":`?${p}`;e(m,{replace:!0,relative:"route"})}]},Pe={byTime:{title:"By time",subPath:"by-time",icon:oo},byContext:{title:"By context",subPath:"by-context",icon:Ps},byLocation:{title:"By location",subPath:"by-location",icon:Ca},list:{title:"List",subPath:"list",icon:ta}};let Ft;const wt=({children:e,visitsInfo:t,getVisits:r,cancelGetVisits:a,settings:n,exportCsv:i,isOrphanVisits:c=!1})=>{var dr;const{visits:l,loading:d,loadingLarge:h,error:u,errorData:p,progress:m,fallbackInterval:g}=t,[{dateRange:f,visitsFilter:C},R]=Lh(),_=O(({startDate:P,endDate:ke})=>({dateRange:{startDate:P??void 0,endDate:ke??void 0}}),R),N=v.useRef(f??g??((dr=n.visits)==null?void 0:dr.defaultInterval)??"last30Days"),[D,S]=v.useState([]),[U,B]=v.useState(),I=v.useRef(!0),{search:k}=Z(),E=P=>P?`${P}${k}`:k,M=v.useMemo(()=>Nn(l),[l]),{os:ue,browsers:me,referrers:De,countries:_e,cities:Dt,citiesForMap:q,visitedUrls:Ue}=v.useMemo(()=>yn(M),[M]),cr=v.useMemo(()=>{var P;return{...C,excludeBots:C.excludeBots??((P=n.visits)==null?void 0:P.excludeBots)}},[C]),lr=We(q),is=P=>{Ft=void 0,S(P)},_t=P=>ke=>{const Ut=`${P}_${ke}`;Ft===Ut?(S([]),B(void 0),Ft=void 0):(S(M.filter(co(P,ke))),B(ke),Ft=Ut)};v.useEffect(()=>a,[]),v.useEffect(()=>{const P=I.current?f??qc(N.current):f;r({dateRange:P,filter:cr},I.current),I.current=!1},[f,C]),v.useEffect(()=>{var P;g&&N.current===(((P=n.visits)==null?void 0:P.defaultInterval)??"last30Days")&&(N.current=g)},[g]);const Mn=()=>h?o(ce,{loading:!0,children:["This is going to take a while... :S",s(io,{value:m,striped:m===100,className:"mt-3"})]}):d?s(ce,{loading:!0}):u?s(K,{type:"error",children:s(le,{errorData:p,fallbackMessage:"An error occurred while loading visits :("})}):H(l)?s(ce,{children:"There are no visits matching current filter"}):o(w,{children:[s(pn,{fill:!0,children:Object.values(Pe).map(({title:P,icon:ke,subPath:Ut},On)=>o(st,{to:E(Ut),replace:!0,children:[s(y,{icon:ke}),s("span",{className:"ms-2 d-none d-sm-inline",children:P})]},On))}),s(Q,{children:o(Xt,{children:[s(F,{path:Pe.byTime.subPath,element:s("div",{className:"col-12 mt-3",children:s(eh,{title:"Visits during time",visits:M,highlightedVisits:D,highlightedLabel:U,setSelectedVisits:is})})}),s(F,{path:Pe.byContext.subPath,element:o(w,{children:[s("div",{className:x("mt-3 col-lg-6",{"col-xl-4":!c}),children:s(Mr,{title:"Operating systems",stats:ue})}),s("div",{className:x("mt-3 col-lg-6",{"col-xl-4":!c}),children:s(Mr,{title:"Browsers",stats:me})}),s("div",{className:x("mt-3",{"col-xl-4":!c,"col-lg-6":c}),children:s(It,{title:"Referrers",stats:De,withPagination:!1,highlightedStats:Et(D,"referer"),highlightedLabel:U,sortingItems:{name:"Referrer name",amount:"Visits amount"},onClick:_t("referer")})}),c&&s("div",{className:"mt-3 col-lg-6",children:s(It,{title:"Visited URLs",stats:Ue,highlightedLabel:U,highlightedStats:Et(D,"visitedUrl"),sortingItems:{visitedUrl:"Visited URL",amount:"Visits amount"},onClick:_t("visitedUrl")})})]})}),s(F,{path:Pe.byLocation.subPath,element:o(w,{children:[s("div",{className:"col-lg-6 mt-3",children:s(It,{title:"Countries",stats:_e,highlightedStats:Et(D,"country"),highlightedLabel:U,sortingItems:{name:"Country name",amount:"Visits amount"},onClick:_t("country")})}),s("div",{className:"col-lg-6 mt-3",children:s(It,{title:"Cities",stats:Dt,highlightedStats:Et(D,"city"),highlightedLabel:U,extraHeaderContent:P=>lr.length>0&&s(ih,{modalTitle:"Cities",locations:lr,activeCities:P}),sortingItems:{name:"City name",amount:"Visits amount"},onClick:_t("city")})})]})}),s(F,{path:Pe.list.subPath,element:s("div",{className:"col-12",children:s(nh,{visits:M,selectedVisits:D,setSelectedVisits:is,isOrphanVisits:c})})}),s(F,{path:"*",element:s(Fs,{replace:!0,to:E(Pe.byTime.subPath)})})]})})]});return o(w,{children:[e,s("section",{className:"mt-3",children:o("div",{className:"row flex-md-row-reverse",children:[s("div",{className:"col-lg-7 col-xl-6",children:o("div",{className:"d-md-flex",children:[s("div",{className:"flex-fill",children:s(qa,{updatable:!0,disabled:d,initialDateRange:N.current,defaultText:"All visits",onDatesChange:_})}),s(fh,{className:"ms-0 ms-md-2 mt-3 mt-md-0",isOrphanVisits:c,selected:cr,onChange:P=>R({visitsFilter:P})})]})}),l.length>0&&s("div",{className:"col-lg-5 col-xl-6 mt-3 mt-lg-0",children:o("div",{className:"d-flex",children:[s(dn,{className:"btn-md-block",amount:M.length,onClick:()=>i(M)}),o(V,{outline:!0,disabled:D.length===0,className:"btn-md-block ms-2",onClick:()=>is([]),children:["Clear selection ",D.length>0&&o(w,{children:["(",G(D.length),")"]})]})]})})]})}),s("section",{className:"mt-3",children:Mn()})]})},Eh=({exportVisits:e})=>Re(({shortUrlVisits:t,shortUrlDetail:r,getShortUrlVisits:a,getShortUrlDetail:n,cancelGetShortUrlVisits:i,settings:c})=>{const{shortCode:l=""}=Se(),{search:d}=Z(),h=Ne(),{domain:u}=Qe(d),p=(g,f)=>a({shortCode:$t(l),query:{...Rt(g),domain:u},doIntervalFallback:f}),m=g=>{var f;return e(`short-url_${(f=r.shortUrl)==null?void 0:f.shortUrl.replace(/https?:\/\//g,"")}_visits.csv`,g)};return v.useEffect(()=>{n({shortCode:$t(l),domain:u})},[]),s(wt,{getVisits:p,cancelGetVisits:i,visitsInfo:t,settings:c,exportCsv:m,children:s(jd,{shortUrlDetail:r,shortUrlVisits:t,goBack:h})})},(t,r)=>r.shortCode?[J.shortUrlVisits($t(r.shortCode))]:[]),Ih=({tagVisits:e,goBack:t,colorGenerator:r})=>{const{visits:a,tag:n}=e;return s(bt,{title:o("span",{className:"d-flex align-items-center justify-content-center",children:[s("span",{className:"me-2",children:"Visits for"}),s(Js,{text:n,colorGenerator:r})]}),goBack:t,visits:a})},Fh=(e,{exportVisits:t})=>Re(({getTagVisits:r,tagVisits:a,cancelGetTagVisits:n,settings:i})=>{const c=Ne(),{tag:l=""}=Se();return s(wt,{getVisits:(u,p)=>r({tag:l,query:Rt(u),doIntervalFallback:p}),cancelGetVisits:n,visitsInfo:a,settings:i,exportCsv:u=>t(`tag_${l}_visits.csv`,u),children:s(Ih,{tagVisits:a,goBack:c,colorGenerator:e})})},()=>[J.visits]),Vh=({exportVisits:e})=>Re(({getOrphanVisits:t,orphanVisits:r,cancelGetOrphanVisits:a,settings:n})=>{const i=Ne();return s(wt,{getVisits:(d,h)=>{var u;return t({query:Rt(d),orphanVisitsType:(u=d.filter)==null?void 0:u.orphanVisitsType,doIntervalFallback:h})},cancelGetVisits:a,visitsInfo:r,settings:n,exportCsv:d=>e("orphan_visits.csv",d),isOrphanVisits:!0,children:s(bt,{title:"Orphan visits",goBack:i,visits:r.visits})})},()=>[J.orphanVisits]),Mh=({exportVisits:e})=>Re(({getNonOrphanVisits:t,nonOrphanVisits:r,cancelGetNonOrphanVisits:a,settings:n})=>{const i=Ne();return s(wt,{getVisits:(d,h)=>t({query:Rt(d),doIntervalFallback:h}),cancelGetVisits:a,visitsInfo:r,settings:n,exportCsv:d=>e("non_orphan_visits.csv",d),children:s(bt,{title:"Non-orphan visits",goBack:i,visits:r.visits})})},()=>[J.visits]),Rn="shlink/shortUrlVisits",Oh={visits:[],shortCode:"",domain:void 0,loading:!1,loadingLarge:!1,error:!1,cancelLoad:!1,progress:0},$h=e=>Ct({typePrefix:`${Rn}/getShortUrlVisits`,createLoaders:({shortCode:t,query:r={},doIntervalFallback:a=!1},n)=>{const{getShortUrlVisits:i}=e(n),c=async(d,h)=>i(t,{...r,page:d,itemsPerPage:h}),l=St(a,async d=>i(t,{...d,domain:r.domain}));return[c,l]},getExtraFulfilledPayload:({shortCode:t,query:r={}})=>({shortCode:t,query:r,domain:r.domain}),shouldCancel:t=>t().shortUrlVisits.cancelLoad}),Ah=e=>yt({name:Rn,initialState:Oh,asyncThunkCreator:e,filterCreatedVisits:({shortCode:t,domain:r,query:a={}},n)=>{const{startDate:i,endDate:c}=a;return n.filter(({shortUrl:l,visit:d})=>l&&tt(l,t,r)&>(d.date,i,c))}}),wn="shlink/tagVisits",Ph={visits:[],tag:"",loading:!1,loadingLarge:!1,error:!1,cancelLoad:!1,progress:0},Bh=e=>Ct({typePrefix:`${wn}/getTagVisits`,createLoaders:({tag:t,query:r={},doIntervalFallback:a=!1},n)=>{const{getTagVisits:i}=e(n),c=async(d,h)=>i(t,{...r,page:d,itemsPerPage:h}),l=St(a,async d=>i(t,d));return[c,l]},getExtraFulfilledPayload:({tag:t,query:r={}})=>({tag:t,query:r}),shouldCancel:t=>t().tagVisits.cancelLoad}),jh=e=>yt({name:wn,initialState:Ph,asyncThunkCreator:e,filterCreatedVisits:({tag:t,query:r={}},a)=>{const{startDate:n,endDate:i}=r;return a.filter(({shortUrl:c,visit:l})=>(c==null?void 0:c.tags.includes(t))&>(l.date,n,i))}}),Dn="shlink/orphanVisits",Gh={visits:[],loading:!1,loadingLarge:!1,error:!1,cancelLoad:!1,progress:0},Hh=(e,t)=>!t||t===e.type,Wh=e=>Ct({typePrefix:`${Dn}/getOrphanVisits`,createLoaders:({orphanVisitsType:t,query:r={},doIntervalFallback:a=!1},n)=>{const{getOrphanVisits:i}=e(n),c=async(d,h)=>i({...r,page:d,itemsPerPage:h}).then(u=>{const p=u.data.filter(m=>ar(m)&&Hh(m,t));return{...u,data:p}}),l=St(a,i);return[c,l]},getExtraFulfilledPayload:({query:t={}})=>({query:t}),shouldCancel:t=>t().orphanVisits.cancelLoad}),qh=e=>yt({name:Dn,initialState:Gh,asyncThunkCreator:e,filterCreatedVisits:({query:t={}},r)=>{const{startDate:a,endDate:n}=t;return r.filter(({visit:i,shortUrl:c})=>!c&>(i.date,a,n))}}),_n="shlink/orphanVisits",zh={visits:[],loading:!1,loadingLarge:!1,error:!1,cancelLoad:!1,progress:0},Qh=e=>Ct({typePrefix:`${_n}/getNonOrphanVisits`,createLoaders:({query:t={},doIntervalFallback:r=!1},a)=>{const{getNonOrphanVisits:n}=e(a),i=async(l,d)=>n({...t,page:l,itemsPerPage:d}),c=St(r,n);return[i,c]},getExtraFulfilledPayload:({query:t={}})=>({query:t}),shouldCancel:t=>t().orphanVisits.cancelLoad}),Kh=e=>yt({name:_n,initialState:zh,asyncThunkCreator:e,filterCreatedVisits:({query:t={}},r)=>{const{startDate:a,endDate:n}=t;return r.filter(({visit:i})=>gt(i.date,a,n))}}),Un="shlink/visitsOverview",Vt={visitsCount:0,orphanVisitsCount:0,loading:!1,error:!1},Xh=e=>z(`${Un}/loadVisitsOverview`,(t,{getState:r})=>e(r).getVisitsOverview()),Jh=e=>W({name:Un,initialState:Vt,reducers:{},extraReducers:t=>{t.addCase(e.pending,()=>({...Vt,loading:!0})),t.addCase(e.rejected,()=>({...Vt,error:!0})),t.addCase(e.fulfilled,(r,{payload:a})=>({...Vt,...a})),t.addCase(ft,({visitsCount:r,orphanVisitsCount:a=0,...n},{payload:i})=>{const{createdVisits:c}=i,{regularVisits:l,orphanVisits:d}=ch(c);return{...n,visitsCount:r+l.length,orphanVisitsCount:a+d.length}})}}),Yh=({exportVisits:e})=>Re(({getDomainVisits:t,domainVisits:r,cancelGetDomainVisits:a,settings:n})=>{const i=Ne(),{domain:c=""}=Se(),[l,d=l]=c.split("_");return s(wt,{getVisits:(p,m)=>t({domain:d,query:Rt(p),doIntervalFallback:m}),cancelGetVisits:a,visitsInfo:r,settings:n,exportCsv:p=>e(`domain_${l}_visits.csv`,p),children:s(bt,{goBack:i,visits:r.visits,title:`"${l}" visits`})})},()=>[J.visits]),Zh=(e,t)=>{e.serviceFactory("MapModal",()=>gn),e.serviceFactory("ShortUrlVisits",Eh,"ReportExporter"),e.decorator("ShortUrlVisits",t(["shortUrlVisits","shortUrlDetail","mercureInfo","settings"],["getShortUrlVisits","getShortUrlDetail","cancelGetShortUrlVisits","createNewVisits","loadMercureInfo"])),e.serviceFactory("TagVisits",Fh,"ColorGenerator","ReportExporter"),e.decorator("TagVisits",t(["tagVisits","mercureInfo","settings"],["getTagVisits","cancelGetTagVisits","createNewVisits","loadMercureInfo"])),e.serviceFactory("DomainVisits",Yh,"ReportExporter"),e.decorator("DomainVisits",t(["domainVisits","mercureInfo","settings"],["getDomainVisits","cancelGetDomainVisits","createNewVisits","loadMercureInfo"])),e.serviceFactory("OrphanVisits",Vh,"ReportExporter"),e.decorator("OrphanVisits",t(["orphanVisits","mercureInfo","settings"],["getOrphanVisits","cancelGetOrphanVisits","createNewVisits","loadMercureInfo"])),e.serviceFactory("NonOrphanVisits",Mh,"ReportExporter"),e.decorator("NonOrphanVisits",t(["nonOrphanVisits","mercureInfo","settings"],["getNonOrphanVisits","cancelGetNonOrphanVisits","createNewVisits","loadMercureInfo"])),e.serviceFactory("VisitsParser",()=>vh),e.serviceFactory("getShortUrlVisits",$h,"buildShlinkApiClient"),e.serviceFactory("cancelGetShortUrlVisits",L("cancelGetVisits"),"shortUrlVisitsReducerCreator"),e.serviceFactory("getTagVisits",Bh,"buildShlinkApiClient"),e.serviceFactory("cancelGetTagVisits",L("cancelGetVisits"),"tagVisitsReducerCreator"),e.serviceFactory("getDomainVisits",fl,"buildShlinkApiClient"),e.serviceFactory("cancelGetDomainVisits",L("cancelGetVisits"),"domainVisitsReducerCreator"),e.serviceFactory("getOrphanVisits",Wh,"buildShlinkApiClient"),e.serviceFactory("cancelGetOrphanVisits",L("cancelGetVisits"),"orphanVisitsReducerCreator"),e.serviceFactory("getNonOrphanVisits",Qh,"buildShlinkApiClient"),e.serviceFactory("cancelGetNonOrphanVisits",L("cancelGetVisits"),"nonOrphanVisitsReducerCreator"),e.serviceFactory("createNewVisits",()=>ft),e.serviceFactory("loadVisitsOverview",Xh,"buildShlinkApiClient"),e.serviceFactory("visitsOverviewReducerCreator",Jh,"loadVisitsOverview"),e.serviceFactory("visitsOverviewReducer",L("reducer"),"visitsOverviewReducerCreator"),e.serviceFactory("domainVisitsReducerCreator",Cl,"getDomainVisits"),e.serviceFactory("domainVisitsReducer",L("reducer"),"domainVisitsReducerCreator"),e.serviceFactory("nonOrphanVisitsReducerCreator",Kh,"getNonOrphanVisits"),e.serviceFactory("nonOrphanVisitsReducer",L("reducer"),"nonOrphanVisitsReducerCreator"),e.serviceFactory("orphanVisitsReducerCreator",qh,"getOrphanVisits"),e.serviceFactory("orphanVisitsReducer",L("reducer"),"orphanVisitsReducerCreator"),e.serviceFactory("shortUrlVisitsReducerCreator",Ah,"getShortUrlVisits"),e.serviceFactory("shortUrlVisitsReducer",L("reducer"),"shortUrlVisitsReducerCreator"),e.serviceFactory("tagVisitsReducerCreator",jh,"getTagVisits"),e.serviceFactory("tagVisitsReducer",L("reducer"),"tagVisitsReducerCreator")};const kn=({tag:e,colorGenerator:t})=>s("div",{style:{backgroundColor:t.getColorForKey(e)},className:"tag-bullet"}),Ar=e=>({id:e,name:e}),eu=e=>({selectedTags:t,onChange:r,placeholder:a,listTags:n,tagsList:i,settings:c,allowNew:l=!0})=>{var p;v.useEffect(()=>{n()},[]);const d=((p=c.shortUrlCreation)==null?void 0:p.tagFilteringMode)??"startsWith",h=({tag:m,onDelete:g})=>s(Js,{colorGenerator:e,text:m.name,clearable:!0,className:"react-tags__tag",onClose:g}),u=({item:m})=>o(w,{children:[s(kn,{tag:`${m.name}`,colorGenerator:e}),m.name]});return s(lo,{tags:t.map(Ar),tagComponent:h,suggestions:i.tags.filter(m=>!t.includes(m)).map(Ar),suggestionComponent:u,allowNew:l,addOnBlur:!0,placeholderText:a??"Add tags to the URL",minQueryLength:1,delimiters:["Enter","Tab",","],suggestionsTransform:d==="includes"?(m,g)=>g.filter(({name:f})=>f.includes(m)):void 0,onDelete:m=>{const g=[...t];g.splice(m,1),r(g)},onAddition:({name:m})=>r([...new Set([...t,...m.toLowerCase().split(",")])])})},tu=({tag:e,toggle:t,isOpen:r,deleteTag:a,tagDelete:n,tagDeleted:i})=>{const{deleting:c,error:l,deleted:d,errorData:h}=n;return o(de,{toggle:t,isOpen:r,centered:!0,onClosed:()=>d&&i(e),children:[s(ye,{toggle:t,className:"text-danger",children:"Delete tag"}),o(he,{children:["Are you sure you want to delete tag ",s("b",{children:e}),"?",l&&s(K,{type:"error",small:!0,className:"mt-2",children:s(le,{errorData:h,fallbackMessage:"Something went wrong while deleting the tag :("})})]}),o(ze,{children:[s(V,{color:"link",onClick:t,children:"Cancel"}),s(V,{color:"danger",disabled:c,onClick:async()=>{await a(e),t()},children:c?"Deleting tag...":"Delete tag"})]})]})};const su=({getColorForKey:e})=>({tag:t,editTag:r,toggle:a,tagEdited:n,isOpen:i,tagEdit:c})=>{const[l,d]=v.useState(t),[h,u]=v.useState(e(t)),[p,m,,g]=A(),{editing:f,error:C,edited:R,errorData:_}=c,N=ht(async()=>{await r({oldName:t,newName:l,color:h}),a()}),D=O(g,()=>R&&n({oldName:t,newName:l,color:h}));return s(de,{isOpen:i,toggle:a,centered:!0,onClosed:D,children:o("form",{name:"editTag",onSubmit:N,children:[s(ye,{toggle:a,children:"Edit tag"}),o(he,{children:[o($s,{children:[s("div",{id:"colorPickerBtn",className:"input-group-text edit-tag-modal__color-picker-toggle",style:{backgroundColor:h,borderColor:h},onClick:m,children:s(y,{icon:ho,className:"edit-tag-modal__color-icon"})}),s(uo,{isOpen:p,toggle:m,target:"colorPickerBtn",placement:"right",hideArrow:!0,popperClassName:"edit-tag-modal__popover",children:s(mo,{color:h,onChange:u})}),s(ot,{value:l,placeholder:"Tag",required:!0,onChange:({target:S})=>d(S.value)})]}),C&&s(K,{type:"error",small:!0,className:"mt-2",children:s(le,{errorData:_,fallbackMessage:"Something went wrong while editing the tag :("})})]}),o(ze,{children:[s(V,{type:"button",color:"link",onClick:a,children:"Cancel"}),s(V,{color:"primary",disabled:f,children:f?"Saving...":"Save"})]})]})})},Tn={tag:"Tag",shortUrls:"Short URLs",visits:"Visits"},ru=e=>Re(({filterTags:t,forceListTags:r,tagsList:a,selectedServer:n,settings:i})=>{var p;const[c,l]=v.useState(((p=i.tags)==null?void 0:p.defaultOrdering)??{}),d=O(()=>a.filteredTags.map(m=>{var g,f;return{tag:m,shortUrls:((g=a.stats[m])==null?void 0:g.shortUrlsCount)??0,visits:((f=a.stats[m])==null?void 0:f.visitsCount)??0}}),m=>Na(m,c));if(v.useEffect(()=>{r()},[]),a.loading)return s(ce,{loading:!0});if(a.error)return s(K,{type:"error",children:s(le,{errorData:a.errorData,fallbackMessage:"Error loading tags :("})});const h=m=>()=>{const g=es(m,c.field,c.dir);l({field:g?m:void 0,dir:g})};return o(w,{children:[s(mt,{className:"mb-3",onChange:t}),s(Q,{className:"mb-3",children:s("div",{className:"col-lg-6 offset-lg-6",children:s(vt,{items:Tn,order:c,onChange:(m,g)=>l({field:m,dir:g})})})}),(()=>{if(a.filteredTags.length<1)return s(ce,{children:"No tags found"});const m=d();return s(e,{sortedTags:m,selectedServer:n,currentOrder:c,orderByColumn:h})})()]})},()=>[J.visits]),Ts="shlink/tagDelete",au={deleting:!1,deleted:!1,error:!1},xn=ie(`${Ts}/tagDeleted`),nu=e=>{const t=z(`${Ts}/deleteTag`,async(a,{getState:n})=>{const{deleteTags:i}=e(n);await i([a])}),{reducer:r}=W({name:Ts,initialState:au,reducers:{},extraReducers:a=>{a.addCase(t.pending,()=>({deleting:!0,deleted:!1,error:!1})),a.addCase(t.rejected,(n,{error:i})=>({deleting:!1,deleted:!1,error:!0,errorData:oe(i)})),a.addCase(t.fulfilled,()=>({deleting:!1,deleted:!0,error:!1}))}});return{reducer:r,deleteTag:t}},nr="shlink/tagEdit",iu={editing:!1,edited:!1,error:!1},Ln=ie(`${nr}/tagEdited`),ou=(e,t)=>z(`${nr}/editTag`,async({oldName:r,newName:a,color:n},{getState:i})=>(await e(i).editTag(r,a),t.setColorForKey(a,n),{oldName:r,newName:a,color:n})),cu=e=>W({name:nr,initialState:iu,reducers:{},extraReducers:t=>{t.addCase(e.pending,()=>({editing:!0,edited:!1,error:!1})),t.addCase(e.rejected,(r,{error:a})=>({editing:!1,edited:!1,error:!0,errorData:oe(a)})),t.addCase(e.fulfilled,(r,{payload:a})=>({...Sa(["oldName","newName"],a),editing:!1,edited:!0,error:!1}))}}),ir="shlink/tagsList",ps={tags:[],filteredTags:[],stats:{},loading:!1,error:!1},Pr=(e,t)=>r=>r===e?t:r,Br=(e,t)=>Qt(r=>r===t,e),lu=(e,t)=>e.reduce((r,[a,n])=>{if(!r[a])return r;const i=r[a];return{...r,[a]:{...i,visitsCount:i.visitsCount+n}}},{...t}),du=e=>Object.entries(e.reduce((t,{shortUrl:r})=>(r==null||r.tags.forEach(a=>{t[a]=(t[a]||0)+1}),t),{})),hu=(e,t=!0)=>z(`${ir}/listTags`,async(r,{getState:a})=>{const{tagsList:n}=a();if(!t&&!H(n.tags))return n;const{listTags:i}=e(a),{tags:c,stats:l=[]}=await i(),d=l.reduce((h,{tag:u,shortUrlsCount:p,visitsCount:m})=>(h[u]={shortUrlsCount:p,visitsCount:m},h),{});return{tags:c,stats:d}}),En=ie(`${ir}/filterTags`),uu=(e,t)=>W({name:ir,initialState:ps,reducers:{},extraReducers:r=>{r.addCase(En,(a,{payload:n})=>({...a,filteredTags:a.tags.filter(i=>i.toLowerCase().match(n.toLowerCase()))})),r.addCase(e.pending,a=>({...a,loading:!0,error:!1})),r.addCase(e.rejected,(a,{error:n})=>({...ps,error:!0,errorData:oe(n)})),r.addCase(e.fulfilled,(a,{payload:n})=>({...ps,stats:n.stats,tags:n.tags,filteredTags:n.tags})),r.addCase(xn,({tags:a,filteredTags:n,...i},{payload:c})=>({...i,tags:Br(a,c),filteredTags:Br(n,c)})),r.addCase(Ln,({tags:a,filteredTags:n,stats:i,...c},{payload:l})=>({...c,stats:{...i,[l.newName]:i[l.oldName]},tags:a.map(Pr(l.oldName,l.newName)).sort(),filteredTags:n.map(Pr(l.oldName,l.newName)).sort()})),r.addCase(ft,(a,{payload:n})=>({...a,stats:lu(du(n.createdVisits),a.stats)})),r.addCase(t.fulfilled,({tags:a,...n},{payload:i})=>({...n,tags:a.concat(i.tags.filter(c=>!a.includes(c)))}))}});const mu=20,gu=e=>({sortedTags:t,selectedServer:r,orderByColumn:a,currentOrder:n})=>{const i=v.useRef(!0),{search:c}=Z(),{page:l=1}=Qe(c),[d,h]=cc("page",Number(l)),u=nt(mu,t),p=u.length>1,m=u[d-1]??[];return v.useEffect(()=>{!i.current&&h(1),i.current=!1},[t]),v.useEffect(()=>{scrollTo(0,0)},[d]),o(j,{bodyClassName:p?"pb-1":"",children:[o("table",{className:"table table-hover responsive-table mb-0",children:[o("thead",{className:"responsive-table__header",children:[o("tr",{children:[o("th",{className:"tags-table__header-cell",onClick:a("tag"),children:["Tag ",s(et,{currentOrder:n,field:"tag"})]}),o("th",{className:"tags-table__header-cell text-lg-end",onClick:a("shortUrls"),children:["Short URLs ",s(et,{currentOrder:n,field:"shortUrls"})]}),o("th",{className:"tags-table__header-cell text-lg-end",onClick:a("visits"),children:["Visits ",s(et,{currentOrder:n,field:"visits"})]}),s("th",{"aria-label":"Options",className:"tags-table__header-cell"})]}),s("tr",{children:s("th",{"aria-label":"Separator",colSpan:4,className:"p-0 border-top-0"})})]}),o("tbody",{children:[m.length===0&&s("tr",{children:s("td",{colSpan:4,className:"text-center",children:"No results found"})}),m.map(g=>s(e,{tag:g,selectedServer:r},g.tag))]})]}),p&&s("div",{className:"sticky-card-paginator",children:s(rr,{pagesCount:u.length,currentPage:d,setCurrentPage:h})})]},d)},pu=(e,t,r)=>({tag:a,selectedServer:n})=>{const[i,c]=A(),[l,d]=A(),[h,u]=A(),p=lt(n);return o("tr",{className:"responsive-table__row",children:[o("th",{className:"responsive-table__cell","data-th":"Tag",children:[s(kn,{tag:a.tag,colorGenerator:r})," ",a.tag]}),s("td",{className:"responsive-table__cell text-lg-end","data-th":"Short URLs",children:s($,{to:`/server/${p}/list-short-urls/1?tags=${encodeURIComponent(a.tag)}`,children:G(a.shortUrls)})}),s("td",{className:"responsive-table__cell text-lg-end","data-th":"Visits",children:s($,{to:`/server/${p}/tag/${a.tag}/visits`,children:G(a.visits)})}),s("td",{className:"responsive-table__cell text-lg-end",children:o(ns,{toggle:u,isOpen:h,children:[o(b,{onClick:d,children:[s(y,{icon:go,fixedWidth:!0,className:"me-1"})," Edit"]}),o(b,{onClick:c,children:[s(y,{icon:po,fixedWidth:!0,className:"me-1"})," Delete"]})]})}),s(t,{tag:a.tag,toggle:d,isOpen:l}),s(e,{tag:a.tag,toggle:c,isOpen:i})]})},vu=(e,t)=>{e.serviceFactory("TagsSelector",eu,"ColorGenerator"),e.decorator("TagsSelector",t(["tagsList","settings"],["listTags"])),e.serviceFactory("DeleteTagConfirmModal",()=>tu),e.decorator("DeleteTagConfirmModal",t(["tagDelete"],["deleteTag","tagDeleted"])),e.serviceFactory("EditTagModal",su,"ColorGenerator"),e.decorator("EditTagModal",t(["tagEdit"],["editTag","tagEdited"])),e.serviceFactory("TagsTableRow",pu,"DeleteTagConfirmModal","EditTagModal","ColorGenerator"),e.serviceFactory("TagsTable",gu,"TagsTableRow"),e.serviceFactory("TagsList",ru,"TagsTable"),e.decorator("TagsList",t(["tagsList","selectedServer","mercureInfo","settings"],["forceListTags","filterTags","createNewVisits","loadMercureInfo"])),e.serviceFactory("tagEditReducerCreator",cu,"editTag"),e.serviceFactory("tagEditReducer",L("reducer"),"tagEditReducerCreator"),e.serviceFactory("tagDeleteReducerCreator",nu,"buildShlinkApiClient"),e.serviceFactory("tagDeleteReducer",L("reducer"),"tagDeleteReducerCreator"),e.serviceFactory("tagsListReducerCreator",uu,"listTags","createShortUrl"),e.serviceFactory("tagsListReducer",L("reducer"),"tagsListReducerCreator");const r=a=>({buildShlinkApiClient:n})=>hu(n,a);e.factory("listTags",r(!1)),e.factory("forceListTags",r(!0)),e.serviceFactory("filterTags",()=>En),e.serviceFactory("deleteTag",L("deleteTag"),"tagDeleteReducerCreator"),e.serviceFactory("tagDeleted",()=>xn),e.serviceFactory("editTag",ou,"buildShlinkApiClient","ColorGenerator"),e.serviceFactory("tagEdited",()=>Ln)},fu="shlink",jr=e=>`${fu}.${e}`;class Cu{constructor(t){T(this,"get",t=>{const r=this.localStorage.getItem(jr(t));return r?JSON.parse(r):void 0});T(this,"set",(t,r)=>this.localStorage.setItem(jr(t),JSON.stringify(r)));this.localStorage=t}}const Su=6,Gr="0123456789ABCDEF",yu=128,{floor:Nu,random:bu,sqrt:Ru,round:wu}=Math,Du=()=>`#${Ws(Su,()=>Gr[Nu(bu()*Gr.length)]).join("")}`,Hr=e=>e.toLowerCase().trim(),_u=e=>(e.match(/../g)??[]).map(t=>parseInt(t,16)||0),Uu=(e=0,t=0,r=0)=>wu(Ru(.299*e**2+.587*t**2+.114*r**2));class ku{constructor(t){T(this,"colors");T(this,"lights");T(this,"getColorForKey",t=>{const r=Hr(t),a=this.colors[r];return a||this.setColorForKey(r,Du())});T(this,"setColorForKey",(t,r)=>{const a=Hr(t);return this.colors[a]=r,this.storage.set("colors",this.colors),r});T(this,"isColorLightForKey",t=>{const r=this.getColorForKey(t).substring(1);if(Ce(this.lights[r])){const a=_u(r);this.lights[r]=Uu(...a)>=yu}return this.lights[r]});this.storage=t,this.colors=this.storage.get("colors")??{},this.lights={}}}const Tu=e=>new Promise(t=>{fo().fromString(e).then(t)}),xu=new vo,Lu=e=>xu.parse(e),Eu=e=>{e.constant("localStorage",window.localStorage),e.service("Storage",Cu,"localStorage"),e.service("ColorGenerator",ku,"Storage"),e.constant("csvToJson",Tu),e.constant("jsonToCsv",Lu),e.constant("setTimeout",window.setTimeout),e.constant("clearTimeout",window.clearTimeout),e.serviceFactory("useTimeoutToggle",ic,"setTimeout","clearTimeout")},Wr="shlink/mercure",Iu={loading:!0,error:!1},Fu=e=>{const t=z(`${Wr}/loadMercureInfo`,(a,{getState:n})=>{const{settings:i}=n();if(!i.realTimeUpdates.enabled)throw new Error("Real time updates not enabled");return e(n).mercureInfo()}),{reducer:r}=W({name:Wr,initialState:Iu,reducers:{},extraReducers:a=>{a.addCase(t.pending,n=>({...n,loading:!0,error:!1})),a.addCase(t.rejected,n=>({...n,loading:!1,error:!0})),a.addCase(t.fulfilled,(n,{payload:i})=>({...i,loading:!1,error:!1}))}});return{loadMercureInfo:t,reducer:r}},Vu=e=>{e.serviceFactory("mercureInfoReducerCreator",Fu,"buildShlinkApiClient"),e.serviceFactory("mercureInfoReducer",L("reducer"),"mercureInfoReducerCreator"),e.serviceFactory("loadMercureInfo",L("loadMercureInfo"),"mercureInfoReducerCreator")},Ge=({children:e})=>s("small",{className:"form-text text-muted d-block",children:e}),Mu=e=>e?`${e}`:"",Ou=({settings:{realTimeUpdates:e},toggleRealTimeUpdates:t,setRealTimeUpdatesInterval:r})=>{const a=rs();return o(j,{title:"Real-time updates",className:"h-100",children:[s(ne,{children:o(He,{checked:e.enabled,onChange:t,children:["Enable or disable real-time updates.",o(Ge,{children:["Real-time updates are currently being ",s("b",{children:e.enabled?"processed":"ignored"}),"."]})]})}),o(Xe,{noMargin:!0,label:"Real-time updates frequency (in minutes):",labelClassName:x("form-label",{"text-muted":!e.enabled}),id:a,children:[s(ot,{type:"number",min:0,placeholder:"Immediate",disabled:!e.enabled,value:Mu(e.interval),id:a,onChange:({target:n})=>r(Number(n.value))}),e.enabled&&o(Ge,{children:[e.interval!==void 0&&e.interval>0&&o("span",{children:["Updates will be reflected in the UI every ",s("b",{children:e.interval})," minute",e.interval>1&&"s","."]}),!e.interval&&"Updates will be reflected in the UI as soon as they happen."]})]})]})},vs=({items:e})=>s(w,{children:e.map((t,r)=>s("div",{className:"mb-3",children:t},r))}),$u=(e,t,r,a,n,i)=>()=>o(Ke,{children:[o(pn,{className:"mb-3",children:[s(st,{to:"general",children:"General"}),s(st,{to:"short-urls",children:"Short URLs"}),s(st,{to:"other-items",children:"Other items"})]}),o(Xt,{children:[s(F,{path:"general",element:s(vs,{items:[s(a,{}),s(e,{})]})}),s(F,{path:"short-urls",element:s(vs,{items:[s(t,{}),s(r,{})]})}),s(F,{path:"other-items",element:s(vs,{items:[s(i,{}),s(n,{})]})}),s(F,{path:"*",element:s(Fs,{replace:!0,to:"general"})})]})]}),fs=e=>e==="includes"?"Suggest tags including input":"Suggest tags starting with input",Au=e=>e==="includes"?o(w,{children:["The list of suggested tags will contain those ",s("b",{children:"including"})," provided input."]}):o(w,{children:["The list of suggested tags will contain those ",s("b",{children:"starting with"})," provided input."]}),Pu=({settings:e,setShortUrlCreationSettings:t})=>{const r=e.shortUrlCreation??{validateUrls:!1},a=n=>()=>t({...r??{validateUrls:!1},tagFilteringMode:n});return o(j,{title:"Short URLs form",className:"h-100",children:[s(ne,{children:o(He,{checked:r.validateUrls??!1,onChange:n=>t({...r,validateUrls:n}),children:["Request validation on long URLs when creating new short URLs.",o(Ge,{children:["The initial state of the ",s("b",{children:"Validate URL"})," checkbox will be ",s("b",{children:r.validateUrls?"checked":"unchecked"}),"."]})]})}),s(ne,{children:o(He,{checked:r.forwardQuery??!0,onChange:n=>t({...r,forwardQuery:n}),children:["Make all new short URLs forward their query params to the long URL.",o(Ge,{children:["The initial state of the ",s("b",{children:"Forward query params on redirect"})," checkbox will be ",s("b",{children:r.forwardQuery??!0?"checked":"unchecked"}),"."]})]})}),o(Xe,{noMargin:!0,label:"Tag suggestions search mode:",children:[o(be,{text:fs(r.tagFilteringMode),children:[s(b,{active:!r.tagFilteringMode||r.tagFilteringMode==="startsWith",onClick:a("startsWith"),children:fs("startsWith")}),s(b,{active:r.tagFilteringMode==="includes",onClick:a("includes"),children:fs("includes")})]}),s(Ge,{children:Au(r.tagFilteringMode)})]})]})};const Bu=({settings:{ui:e},setUiSettings:t})=>o(j,{title:"User interface",className:"h-100",children:[s(y,{icon:(e==null?void 0:e.theme)==="dark"?Co:So,className:"user-interface__theme-icon"}),s(He,{checked:(e==null?void 0:e.theme)==="dark",onChange:r=>{const a=r?"dark":"light";t({...e,theme:a}),wa(a)},children:"Use dark theme."})]}),ju=({onChange:e,active:t,allText:r})=>s(be,{text:Ks(t)??r,children:s(Wa,{allText:r,active:t,onChange:e})}),qr=e=>{var t;return((t=e.visits)==null?void 0:t.defaultInterval)??"last30Days"},Gu=({settings:e,setVisitsSettings:t})=>{var r,a;return o(j,{title:"Visits",className:"h-100",children:[s(ne,{children:o(He,{checked:!!((r=e.visits)!=null&&r.excludeBots),onChange:n=>t({defaultInterval:qr(e),excludeBots:n}),children:["Exclude bots wherever possible (this option‘s effect might depend on Shlink server‘s version).",o(Ge,{children:["The visits coming from potential bots will be ",s("b",{children:(a=e.visits)!=null&&a.excludeBots?"excluded":"included"}),"."]})]})}),s(Xe,{noMargin:!0,label:"Default interval to load on visits sections:",children:s(ju,{allText:"All visits",active:qr(e),onChange:n=>t({defaultInterval:n})})})]})},Hu=({settings:{tags:e},setTagsSettings:t})=>s(j,{title:"Tags",className:"h-100",children:s(Xe,{noMargin:!0,label:"Default ordering for tags list:",children:s(vt,{items:Tn,order:(e==null?void 0:e.defaultOrdering)??{},onChange:(r,a)=>t({...e,defaultOrdering:{field:r,dir:a}})})})}),Wu=({settings:{shortUrlsList:e},setShortUrlsListSettings:t})=>s(j,{title:"Short URLs list",className:"h-100",children:s(Xe,{noMargin:!0,label:"Default ordering for short URLs list:",children:s(vt,{items:za,order:(e==null?void 0:e.defaultOrdering)??Xs,onChange:(r,a)=>t({defaultOrdering:{field:r,dir:a}})})})}),qu=(e,t)=>{e.serviceFactory("Settings",$u,"RealTimeUpdatesSettings","ShortUrlCreationSettings","ShortUrlsListSettings","UserInterfaceSettings","VisitsSettings","TagsSettings"),e.decorator("Settings",Ht),e.decorator("Settings",t(null,["resetSelectedServer"])),e.serviceFactory("RealTimeUpdatesSettings",()=>Ou),e.decorator("RealTimeUpdatesSettings",t(["settings"],["toggleRealTimeUpdates","setRealTimeUpdatesInterval"])),e.serviceFactory("ShortUrlCreationSettings",()=>Pu),e.decorator("ShortUrlCreationSettings",t(["settings"],["setShortUrlCreationSettings"])),e.serviceFactory("UserInterfaceSettings",()=>Bu),e.decorator("UserInterfaceSettings",t(["settings"],["setUiSettings"])),e.serviceFactory("VisitsSettings",()=>Gu),e.decorator("VisitsSettings",t(["settings"],["setVisitsSettings"])),e.serviceFactory("TagsSettings",()=>Hu),e.decorator("TagsSettings",t(["settings"],["setTagsSettings"])),e.serviceFactory("ShortUrlsListSettings",()=>Wu),e.decorator("ShortUrlsListSettings",t(["settings"],["setShortUrlsListSettings"])),e.serviceFactory("toggleRealTimeUpdates",()=>tl),e.serviceFactory("setRealTimeUpdatesInterval",()=>sl),e.serviceFactory("setShortUrlCreationSettings",()=>rl),e.serviceFactory("setShortUrlsListSettings",()=>al),e.serviceFactory("setUiSettings",()=>nl),e.serviceFactory("setVisitsSettings",()=>il),e.serviceFactory("setTagsSettings",()=>ol)},zu=(e,t)=>{const[r,a]=e.split("://"),[,...n]=a.split("/"),i=n.length?`/${n.join("/")}`:"";return`${r}://${t}${i}`},Mt="shlink/domainsList",Ot={domains:[],filteredDomains:[],loading:!1,error:!1},zr=({domain:e,redirects:t})=>r=>r.domain!==e?r:{...r,redirects:t},Qr=(e,t)=>r=>r.domain!==e?r:{...r,status:t},Qu=(e,t)=>{const r=z(`${Mt}/listDomains`,async(c,{getState:l})=>{const{listDomains:d}=e(l),{data:h,defaultRedirects:u}=await d();return{domains:h.map(p=>({...p,status:"validating"})),defaultRedirects:u}}),a=z(`${Mt}/checkDomainHealth`,async(c,{getState:l})=>{const{selectedServer:d}=l();if(!Gs(d))return{domain:c,status:"invalid"};try{const{url:h,...u}=d,{health:p}=e({...u,url:zu(h,c)}),{status:m}=await p();return{domain:c,status:m==="pass"?"valid":"invalid"}}catch{return{domain:c,status:"invalid"}}}),n=ie(`${Mt}/filterDomains`),{reducer:i}=W({name:Mt,initialState:Ot,reducers:{},extraReducers:c=>{c.addCase(r.pending,()=>({...Ot,loading:!0})),c.addCase(r.rejected,(l,{error:d})=>({...Ot,error:!0,errorData:oe(d)})),c.addCase(r.fulfilled,(l,{payload:d})=>({...Ot,...d,filteredDomains:d.domains})),c.addCase(a.fulfilled,({domains:l,filteredDomains:d,...h},{payload:u})=>({...h,domains:l.map(Qr(u.domain,u.status)),filteredDomains:d.map(Qr(u.domain,u.status))})),c.addCase(n,(l,{payload:d})=>({...l,filteredDomains:l.domains.filter(({domain:h})=>h.toLowerCase().match(d.toLowerCase()))})),c.addCase(t.fulfilled,(l,{payload:d})=>({...l,domains:l.domains.map(zr(d)),filteredDomains:l.filteredDomains.map(zr(d))}))}});return{reducer:i,listDomains:r,checkDomainHealth:a,filterDomains:n}};const Ku=({listDomains:e,value:t,domainsList:r,onChange:a})=>{const[n,,i,c]=A(),{domains:l}=r,d=H(t),h=()=>a("");return v.useEffect(()=>{e()},[]),n?o($s,{children:[s(ot,{value:t??"",placeholder:"Domain",onChange:u=>a(u.target.value)}),s(V,{id:"backToDropdown",outline:!0,type:"button",className:"domains-dropdown__back-btn","aria-label":"Back to domains list",onClick:O(h,c),children:s(y,{icon:yo})}),s(ee,{target:"backToDropdown",placement:"left",trigger:"hover",children:"Existing domains"})]}):o(be,{text:d?"Domain":`Domain: ${t}`,className:d?"domains-dropdown__toggle-btn":"domains-dropdown__toggle-btn--active",children:[l.map(({domain:u,isDefault:p})=>o(b,{active:(t===u||p)&&d,onClick:()=>a(u),children:[u,p&&s("span",{className:"float-end text-muted",children:"default"})]},u)),s(b,{divider:!0}),s(b,{onClick:O(h,i),children:s("i",{children:"New domain"})})]})},Xu=({status:e,matchMedia:t=window.matchMedia})=>{const r=v.useRef(),a=()=>t("(max-width: 991px)").matches,[n,i]=v.useState(a());return v.useEffect(()=>{const c=()=>i(a());return window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)},[]),e==="validating"?s(y,{fixedWidth:!0,icon:Zr,spin:!0}):o(w,{children:[s("span",{ref:Nt(r),children:e==="valid"?s(y,{fixedWidth:!0,icon:it,className:"text-muted"}):s(y,{fixedWidth:!0,icon:bs,className:"text-danger"})}),s(ee,{target:()=>r.current,placement:n?"top-start":"left",autohide:e==="valid",children:e==="valid"?"Congratulations! This domain is properly configured.":o("span",{children:["Oops! There is some missing configuration, and short URLs shared with this domain will not work.",s("br",{}),"Check the ",s(ae,{href:"https://slnk.to/multi-domain-docs",children:"documentation"})," in order to find out what is missing."]})})]})},Cs=({isLast:e,...t})=>s(Pt,{...t,required:!1,type:"url",placeholder:"No redirect",className:e?"mb-0":""}),Ju=({isOpen:e,toggle:t,domain:r,editDomainRedirects:a})=>{var p,m,g;const[n,i]=v.useState(((p=r.redirects)==null?void 0:p.baseUrlRedirect)??""),[c,l]=v.useState(((m=r.redirects)==null?void 0:m.regular404Redirect)??""),[d,h]=v.useState(((g=r.redirects)==null?void 0:g.invalidShortUrlRedirect)??""),u=ht(async()=>a({domain:r.domain,redirects:{baseUrlRedirect:ls(n),regular404Redirect:ls(c),invalidShortUrlRedirect:ls(d)}}).then(t));return s(de,{isOpen:e,toggle:t,centered:!0,children:o("form",{name:"domainRedirectsModal",onSubmit:u,children:[o(ye,{toggle:t,children:["Edit redirects for ",s("b",{children:r.domain})]}),o(he,{children:[o(Cs,{value:n,onChange:i,children:[o(At,{className:"me-2",placement:"bottom",children:["Visitors accessing the base url, as in ",o("b",{children:["https://",r.domain,"/"]}),", will be redirected to this URL."]}),"Base URL"]}),o(Cs,{value:c,onChange:l,children:[o(At,{className:"me-2",placement:"bottom",children:["Visitors accessing a url not matching a short URL pattern, as in ",o("b",{children:["https://",r.domain,"/???/[...]"]}),", will be redirected to this URL."]}),"Regular 404"]}),o(Cs,{value:d,isLast:!0,onChange:h,children:[s(At,{className:"me-2",placement:"bottom",children:"Visitors accessing a url matching a short URL pattern, but not matching an existing short code, will be redirected to this URL."}),"Invalid short URL"]})]}),o(ze,{children:[s(V,{color:"link",type:"button",onClick:t,children:"Cancel"}),s(V,{color:"primary",children:"Save"})]})]})})},Yu=({domain:e,editDomainRedirects:t,selectedServer:r})=>{const[a,n]=A(),[i,c]=A(),{isDefault:l}=e,d=!l||bc(r),h=Ia(r),u=lt(r);return o(ns,{isOpen:a,toggle:n,children:[h&&o(b,{tag:$,to:`/server/${u}/domain/${e.domain}${e.isDefault?`_${Za}`:""}/visits`,children:[s(y,{icon:Ps,fixedWidth:!0})," Visit stats"]}),o(b,{disabled:!d,onClick:d?c:void 0,children:[s(y,{fixedWidth:!0,icon:Bs})," Edit redirects"]}),s(Ju,{domain:e,isOpen:i,toggle:c,editDomainRedirects:t})]})},Ss=({fallback:e})=>o("span",{className:"text-muted",children:[!e&&s("small",{children:"No redirect"}),e&&o(w,{children:[e," ",s("small",{children:"(as fallback)"})]})]}),Zu=()=>o(w,{children:[s(y,{fixedWidth:!0,icon:No,className:"text-primary",id:"defaultDomainIcon"}),s(ee,{target:"defaultDomainIcon",placement:"right",children:"Default domain"})]}),em=({domain:e,editDomainRedirects:t,checkDomainHealth:r,defaultRedirects:a,selectedServer:n})=>{const{domain:i,isDefault:c,redirects:l,status:d}=e;return v.useEffect(()=>{r(e.domain)},[]),o("tr",{className:"responsive-table__row",children:[s("td",{className:"responsive-table__cell","data-th":"Is default domain",children:c&&s(Zu,{})}),s("th",{className:"responsive-table__cell","data-th":"Domain",children:i}),s("td",{className:"responsive-table__cell","data-th":"Base path redirect",children:(l==null?void 0:l.baseUrlRedirect)??s(Ss,{fallback:a==null?void 0:a.baseUrlRedirect})}),s("td",{className:"responsive-table__cell","data-th":"Regular 404 redirect",children:(l==null?void 0:l.regular404Redirect)??s(Ss,{fallback:a==null?void 0:a.regular404Redirect})}),s("td",{className:"responsive-table__cell","data-th":"Invalid short URL redirect",children:(l==null?void 0:l.invalidShortUrlRedirect)??s(Ss,{fallback:a==null?void 0:a.invalidShortUrlRedirect})}),s("td",{className:"responsive-table__cell text-lg-center","data-th":"Status",children:s(Xu,{status:d})}),s("td",{className:"responsive-table__cell text-end",children:s(Yu,{domain:e,editDomainRedirects:t,selectedServer:n})})]})},Kr=["","Domain","Base path redirect","Regular 404 redirect","Invalid short URL redirect","",""],tm=({listDomains:e,domainsList:t,filterDomains:r,editDomainRedirects:a,checkDomainHealth:n,selectedServer:i})=>{var g;const{filteredDomains:c,defaultRedirects:l,loading:d,error:h,errorData:u}=t,p=l??((g=c.find(({isDefault:f})=>f))==null?void 0:g.redirects);return v.useEffect(()=>{e()},[]),d?s(ce,{loading:!0}):o(w,{children:[s(mt,{className:"mb-3",onChange:r}),(()=>h?s(K,{type:"error",children:s(le,{errorData:u,fallbackMessage:"Error loading domains :("})}):s(j,{children:o("table",{className:"table table-hover responsive-table mb-0",children:[s("thead",{className:"responsive-table__header",children:s("tr",{children:Kr.map((f,C)=>s("th",{children:f},C))})}),o("tbody",{children:[c.length<1&&s("tr",{children:s("td",{colSpan:Kr.length,className:"text-center",children:"No results found"})}),c.map(f=>s(em,{domain:f,editDomainRedirects:a,checkDomainHealth:n,defaultRedirects:p,selectedServer:i},f.domain))]})]})}))()]})},sm="shlink/domainRedirects/EDIT_DOMAIN_REDIRECTS",rm=e=>z(sm,async({domain:t,redirects:r},{getState:a})=>{const{editDomainRedirects:n}=e(a),i=await n({domain:t,...r});return{domain:t,redirects:i}}),am=(e,t)=>{e.serviceFactory("DomainSelector",()=>Ku),e.decorator("DomainSelector",t(["domainsList"],["listDomains"])),e.serviceFactory("ManageDomains",()=>tm),e.decorator("ManageDomains",t(["domainsList","selectedServer"],["listDomains","filterDomains","editDomainRedirects","checkDomainHealth"])),e.serviceFactory("domainsListReducerCreator",Qu,"buildShlinkApiClient","editDomainRedirects"),e.serviceFactory("domainsListReducer",L("reducer"),"domainsListReducerCreator"),e.serviceFactory("listDomains",L("listDomains"),"domainsListReducerCreator"),e.serviceFactory("filterDomains",L("filterDomains"),"domainsListReducerCreator"),e.serviceFactory("editDomainRedirects",rm,"buildShlinkApiClient"),e.serviceFactory("checkDomainHealth",L("checkDomainHealth"),"domainsListReducerCreator")},{actions:nm,reducer:im}=W({name:"shlink/appUpdates",initialState:!1,reducers:{appUpdateAvailable:()=>!0,resetAppUpdate:()=>!1}}),{appUpdateAvailable:om,resetAppUpdate:cm}=nm,lm=im;const dm=({isOpen:e,toggle:t,forceUpdate:r})=>{const[a,,n]=A();return o(bo,{className:"app-update-banner",isOpen:e,toggle:t,tag:j,color:"secondary",children:[s("h4",{className:"mb-4",children:"This app has just been updated!"}),o("p",{className:"mb-0",children:["Restart it to enjoy the new features.",o(V,{role:"button",disabled:a,className:"ms-2",color:"secondary",size:"sm",onClick:()=>{n(),r()},children:[!a&&o(w,{children:["Restart now ",s(y,{icon:Ro,className:"ms-1"})]}),a&&s(w,{children:"Restarting..."})]})]})]})},hm=async()=>{var t;(await((t=navigator.serviceWorker)==null?void 0:t.getRegistrations())??[]).forEach(({waiting:r})=>{r==null||r.addEventListener("statechange",a=>{var n;((n=a.target)==null?void 0:n.state)==="activated"&&window.location.reload()}),r==null||r.postMessage({type:"SKIP_WAITING"})})};const um=(e,t,r,a,n,i,c,l)=>({fetchServers:d,servers:h,settings:u,appUpdated:p,resetAppUpdate:m})=>{const f=Z().pathname==="/";return v.useEffect(()=>{var C;Object.keys(h).length===0&&d(),wa(((C=u.ui)==null?void 0:C.theme)??"light")},[]),o("div",{className:"container-fluid app-container",children:[s(e,{}),o("div",{className:"app",children:[s("div",{className:x("shlink-wrapper",{"d-flex d-md-block align-items-center":f}),children:o(Xt,{children:[s(F,{index:!0,element:s(t,{})}),s(F,{path:"/settings/*",element:s(i,{})}),s(F,{path:"/manage-servers",element:s(c,{})}),s(F,{path:"/server/create",element:s(a,{})}),s(F,{path:"/server/:serverId/edit",element:s(n,{})}),s(F,{path:"/server/:serverId/*",element:s(r,{})}),s(F,{path:"*",element:s(Va,{})})]})}),s("div",{className:"shlink-footer",children:s(l,{})})]}),s(dm,{isOpen:p,toggle:m,forceUpdate:hm})]})},mm=(e,t)=>{e.serviceFactory("App",um,"MainHeader","Home","MenuLayout","CreateServer","EditServer","Settings","ManageServers","ShlinkVersionsContainer"),e.decorator("App",t(["servers","settings","appUpdated"],["fetchServers","resetAppUpdate"])),e.serviceFactory("appUpdateAvailable",()=>om),e.serviceFactory("resetAppUpdate",()=>cm)},te=new wo,{container:or}=te,gm=(e,t)=>(...r)=>e[t](...r),pm=(e,t)=>({...e,[t]:gm(or,t)}),we=(e,t=[])=>Do(e?Sa(e):null,t.reduce(pm,{}));mm(te,we);Bc(te,we);rc(te);td(te,we);Ad(te,we);vu(te,we);Zh(te,we);Eu(te);Vu(te);qu(te,we);am(te,we);const vm=e=>_o({servers:wd,selectedServer:e.selectedServerReducer,shortUrlsList:e.shortUrlsListReducer,shortUrlCreation:e.shortUrlCreationReducer,shortUrlDeletion:e.shortUrlDeletionReducer,shortUrlEdition:e.shortUrlEditionReducer,shortUrlDetail:e.shortUrlDetailReducer,shortUrlVisits:e.shortUrlVisitsReducer,tagVisits:e.tagVisitsReducer,domainVisits:e.domainVisitsReducer,orphanVisits:e.orphanVisitsReducer,nonOrphanVisits:e.nonOrphanVisitsReducer,tagsList:e.tagsListReducer,tagDelete:e.tagDeleteReducer,tagEdit:e.tagEditReducer,mercureInfo:e.mercureInfoReducer,settings:cl,domainsList:e.domainsListReducer,visitsOverview:e.visitsOverviewReducer,appUpdated:lm,sidebar:Oc}),fm=e=>{var t;return e.settings&&((t=e.settings.visits)==null?void 0:t.defaultInterval)==="last180days"&&e.settings.visits&&(e.settings.visits.defaultInterval="last180Days"),e},Cm=!0,In={states:["settings","servers"],namespace:"shlink",namespaceSeparator:".",debounce:300},Sm=fm(ya.load(In)),ym=e=>Uo({devTools:!Cm,reducer:vm(e),preloadedState:Sm,middleware:t=>t({immutableCheck:!1,serializableCheck:!1}).prepend(e.selectServerListener.middleware).concat(ya.save(In))}),Nm=()=>{delete gr.Icon.Default.prototype._getIconUrl,gr.Icon.Default.mergeOptions({iconRetinaUrl:ko,iconUrl:To,shadowUrl:xo})},bm=Boolean(window.location.hostname==="localhost"||window.location.hostname==="[::1]"||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));function Rm(e){if("serviceWorker"in navigator){if(new URL(Gt.homepage,window.location.href).origin!==window.location.origin)return;window.addEventListener("load",()=>{const r=`${Gt.homepage}/service-worker.js`;bm?(wm(r,e),navigator.serviceWorker.ready.then(()=>{console.log("This web app is being served cache-first by a service worker. To learn more, visit https://cra.link/PWA")})):Fn(r,e)})}}function Fn(e,t){navigator.serviceWorker.register(e).then(r=>{r.onupdatefound=()=>{const a=r.installing;a!=null&&(a.onstatechange=()=>{a.state==="installed"&&(navigator.serviceWorker.controller?(console.log("New content is available and will be used when all tabs for this page are closed. See https://cra.link/PWA."),t&&t.onUpdate&&t.onUpdate(r)):(console.log("Content is cached for offline use."),t&&t.onSuccess&&t.onSuccess(r)))})}}).catch(r=>{console.error("Error during service worker registration:",r)})}function wm(e,t){fetch(e,{headers:{"Service-Worker":"script"}}).then(r=>{const a=r.headers.get("content-type");r.status===404||a!=null&&a.indexOf("javascript")===-1?navigator.serviceWorker.ready.then(n=>{n.unregister().then(()=>{window.location.reload()})}):Fn(e,t)}).catch(()=>{console.log("No internet connection found. App is running in offline mode.")})}Nm();const Vn=ym(or),{App:Dm,ScrollToTop:_m,ErrorHandler:Um,appUpdateAvailable:km}=or;Lo(document.getElementById("root")).render(s(Eo,{store:Vn,children:s(Io,{basename:Gt.homepage,children:s(Um,{children:s(_m,{children:s(Dm,{})})})})}));Rm({onUpdate(){Vn.dispatch(km())}});
|