import{a as e,i as t,s as n}from"./graphql-Dsv3IYEA.js";import{t as r}from"./jsx-runtime-BKZ-v_4m.js";import{n as i}from"./not-found-i5RsCZif.js";import{t as a}from"./useTranslation-l30fIyqu.js";import{n as o}from"./close-CPZmVgdl.js";import{n as s,r as c,t as l}from"./LastActive-BP86a6jL.js";import{n as u,r as d,t as f}from"./Heading-DoTcf-3Y.js";import{H as p,S as m,V as h,W as g,c as _,l as v,s as y}from"./main-CxGi0fIe.js";import{t as b}from"./Separator-BYkx3-r6.js";import"./Separator-CGzvtLp7.js";import{t as x}from"./ButtonLink-BcHfDxZ3.js";import{c as S,d as C,f as w,i as T,l as E,o as D,s as O,u as k}from"./EndBrowserSessionButton-JiSgCdmR.js";import{i as A,n as j,t as M}from"./Filter-Chj7kh4P.js";import{i as N,n as P,r as F,t as I}from"./EndOAuth2SessionButton-DE6voiWG.js";import{t as L}from"./Link-Dw1UBuD0.js";var R=r(),z=t(`
  fragment CompatSession_session on CompatSession {
    id
    createdAt
    deviceId
    finishedAt
    lastActiveIp
    lastActiveAt
    humanName
    ...EndCompatSessionButton_session
    userAgent {
      name
      os
      model
      deviceType
    }
    ssoLogin {
      id
      redirectUri
    }
  }
`),B=({session:t})=>{let{t:n}=a(),r=e(z,t),i=r.humanName??(r.ssoLogin?.redirectUri?N(r.ssoLogin.redirectUri):void 0),o=r.userAgent?.deviceType??`UNKNOWN`,u=r.userAgent?.model??(r.userAgent?.name?r.userAgent?.os?n(`frontend.session.name_for_platform`,{name:r.userAgent.name,platform:r.userAgent.os}):r.userAgent.name:n(`frontend.session.unknown_device`)),d=c(r.createdAt),f=r.lastActiveAt?c(r.lastActiveAt):void 0;return(0,R.jsxs)(w,{children:[(0,R.jsxs)(E,{to:`/sessions/$id`,params:{id:r.id},disabled:!!r.finishedAt,children:[(0,R.jsxs)(O,{type:o,children:[(0,R.jsx)(C,{name:u}),i&&(0,R.jsx)(D,{name:i,logoUri:A(r.userAgent?.name??void 0)})]}),(0,R.jsxs)(k,{children:[f&&(0,R.jsx)(S,{label:n(`frontend.session.last_active_label`),children:(0,R.jsx)(l,{lastActive:f})}),(0,R.jsx)(S,{label:n(`frontend.session.signed_in_label`),children:(0,R.jsx)(s,{datetime:d})}),(0,R.jsx)(S,{label:n(`frontend.session.device_id_label`),children:r.deviceId})]})]}),!r.finishedAt&&(0,R.jsx)(T,{children:(0,R.jsx)(F,{session:r,size:`md`})})]})},V=t(`
  fragment OAuth2Session_session on Oauth2Session {
    id
    scope
    createdAt
    finishedAt
    lastActiveIp
    lastActiveAt
    humanName

    ...EndOAuth2SessionButton_session

    userAgent {
      name
      model
      os
      deviceType
    }

    client {
      id
      clientId
      clientName
      applicationType
      logoUri
    }
  }
`),H=e=>e===`WEB`?`PC`:e===`NATIVE`?`MOBILE`:`UNKNOWN`,U=({session:t})=>{let{t:n}=a(),r=e(V,t),i=P(r.scope),o=c(r.createdAt),u=r.lastActiveAt?c(r.lastActiveAt):void 0,d=(r.userAgent?.deviceType===`UNKNOWN`?null:r.userAgent?.deviceType)??H(r.client.applicationType),f=r.client.clientName||r.client.clientId,p=r.humanName??r.userAgent?.model??(r.userAgent?.name?r.userAgent?.os?n(`frontend.session.name_for_platform`,{name:r.userAgent.name,platform:r.userAgent.os}):r.userAgent.name:n(`frontend.session.unknown_device`));return(0,R.jsxs)(w,{children:[(0,R.jsxs)(E,{to:`/sessions/$id`,params:{id:r.id},disabled:!!r.finishedAt,children:[(0,R.jsxs)(O,{type:d,children:[(0,R.jsx)(C,{name:p}),(0,R.jsx)(D,{name:f,logoUri:r.client.logoUri??void 0})]}),(0,R.jsxs)(k,{children:[u&&(0,R.jsx)(S,{label:n(`frontend.session.last_active_label`),children:(0,R.jsx)(l,{lastActive:u})}),(0,R.jsx)(S,{label:n(`frontend.session.signed_in_label`),children:(0,R.jsx)(s,{datetime:o})}),i&&(0,R.jsx)(S,{label:n(`frontend.session.device_id_label`),children:i})]})]}),!r.finishedAt&&(0,R.jsx)(T,{children:(0,R.jsx)(I,{session:r,size:`md`})})]})},W={browserSessionsOverview:`_browser-sessions-overview_xlk0o_8`},G=t(`
  fragment BrowserSessionsOverview_user on User {
    browserSessions(first: 0, state: ACTIVE) {
      totalCount
    }
  }
`),K=({user:t})=>{let n=e(G,t),{t:r}=a();return(0,R.jsxs)(`div`,{className:W.browserSessionsOverview,children:[(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col`,children:[(0,R.jsx)(d,{children:r(`frontend.browser_sessions_overview.heading`)}),(0,R.jsx)(g,{children:r(`frontend.browser_sessions_overview.body`,{count:n.browserSessions.totalCount})})]}),(0,R.jsx)(L,{to:`/sessions/browsers`,children:r(`frontend.browser_sessions_overview.view_all_button`)})]})},q=e=>{throw Error(`Unknown session type: ${e}`)};function J(){let{t:e}=a(),{inactive:t,pagination:r}=y.useLoaderDeps(),{data:{viewer:s,siteConfig:c}}=n(v);if(s.__typename!==`User`)throw i();let{sessionLimit:l}=c,{data:d}=n(_(r,t));if(d.viewer.__typename!==`User`)throw i();let g=d.viewer.appSessions,[S,C]=m(r,g.pageInfo,6),w=[...g.edges].reverse(),T=e(`frontend.user_sessions_overview.num_sessions_header`,{count:g.totalCount});if(s.unfilteredAppSessions.totalCount!==g.totalCount){let t=e(`frontend.user_sessions_overview.num_sessions_filtered_header.unfiltered_session_total`,{count:s.unfilteredAppSessions.totalCount});T=e(`frontend.user_sessions_overview.num_sessions_filtered_header.header`,{count:g.totalCount,unfiltered_session_total:t})}let E=null;l&&(E=(0,R.jsx)(o,{label:e(`frontend.user_sessions_overview.session_limit_info`,{count:s.unfilteredAppSessions.totalCount,limit:l.softLimit}),children:(0,R.jsx)(p,{})}));let D=null;return l&&s.unfilteredAppSessions.totalCount>=l.softLimit?D=(0,R.jsx)(h,{type:`critical`,title:e(`frontend.user_sessions_overview.hit_session_limit_warning_header`),"data-testid":`device-limit-error`,children:e(`frontend.user_sessions_overview.hit_session_limit_warning_description`,{count:l.softLimit,num_sessions:s.unfilteredAppSessions.totalCount})}):l&&s.unfilteredAppSessions.totalCount>0&&s.unfilteredAppSessions.totalCount+Math.ceil(l.softLimit*.2)>=l.softLimit&&(D=(0,R.jsx)(h,{type:`info`,title:e(`frontend.user_sessions_overview.approaching_session_limit_warning_header`),"data-testid":`device-limit-warning`,children:e(`frontend.user_sessions_overview.approaching_session_limit_warning_description`,{count:l.softLimit,num_sessions:s.unfilteredAppSessions.totalCount})})),(0,R.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,R.jsx)(f,{children:e(`frontend.user_sessions_overview.heading`)}),(0,R.jsx)(K,{user:s}),(0,R.jsxs)(u,{className:`flex gap-1 items-center`,children:[T,E]}),(0,R.jsx)(b,{kind:`section`}),D,(0,R.jsx)(`div`,{className:`flex gap-2 justify-start items-center`,children:(0,R.jsx)(M,{to:`/sessions`,enabled:t,search:{inactive:t?void 0:!0},children:e(`frontend.last_active.inactive_90_days`)})}),w.map(e=>{let t=e.node.__typename;switch(t){case`Oauth2Session`:return(0,R.jsx)(U,{session:e.node},e.cursor);case`CompatSession`:return(0,R.jsx)(B,{session:e.node},e.cursor);default:return q(t)}}),g.totalCount===0&&(0,R.jsx)(j,{children:e(t?`frontend.user_sessions_overview.no_active_sessions.inactive_90_days`:`frontend.user_sessions_overview.no_active_sessions.default`)}),(C||S)&&(0,R.jsxs)(`div`,{className:`flex *:flex-1`,children:[(0,R.jsx)(x,{kind:`secondary`,size:`md`,disabled:!C,to:`/sessions`,search:{inactive:t,...C||r},resetScroll:!0,children:e(`common.previous`)}),(0,R.jsx)(`div`,{}),(0,R.jsx)(x,{kind:`secondary`,size:`md`,disabled:!S,to:`/sessions`,search:{inactive:t,...S||r},resetScroll:!0,children:e(`common.next`)})]})]})}export{J as component};
//# sourceMappingURL=_account.sessions.index-B7YH2CMP.js.map