import{o as e}from"./rolldown-runtime-iuO8RvI4.js";import{Bc as a,Cc as s,Ov as t,bi as r,rv as l,uc as n}from"./shared-0-C4kdVF7Y.js";import{Mi as u,ki as o}from"./vendor-frame-CwiylG4Y.js";import{nn as i,rn as c}from"./vendor-all-2-BJdkbLSj.js";import{V as d,u as p}from"./shared-frame-DbQbH4Yr.js";import{t as f}from"./cef6572e4-C51h7Qqe.js";var h=e(u()),b=[300,1e3,3e3];function k(){const[e,t]=(0,h.useState)(null),[r,l]=(0,h.useState)(!0),u=(0,h.useRef)(null),o=(0,h.useRef)([]),i=(0,h.useRef)(!0),c=(0,h.useRef)(void 0),d=(0,h.useRef)(null),p=(0,h.useCallback)(()=>{null!==u.current&&(clearTimeout(u.current),u.current=null)},[]),f=(0,h.useCallback)(()=>{for(const e of o.current)clearTimeout(e);o.current=[]},[]),k=(0,h.useCallback)(async()=>{if(s?.getStatus)try{const e=await s.getStatus();if(!i.current)return;t(e),d.current=e.status,l(!1),e.status===a.RequiresApproval?(f(),p(),u.current=setTimeout(()=>{i.current&&k()},5e3)):p()}catch{if(!i.current)return;l(!1),d.current===a.RequiresApproval&&(p(),u.current=setTimeout(()=>{i.current&&k()},5e3))}else l(!1)},[p,f]),m=(0,h.useCallback)(()=>{p(),f(),k(),o.current=b.map(e=>setTimeout(()=>{i.current&&k()},e))},[p,f,k]);return(0,h.useEffect)(()=>{i.current=!0,k();const e=n?.onPreferencesChanged?.(e=>{const a=e.wakeSchedulerEnabled,s=c.current;c.current=a,i.current&&(void 0!==s?a!==s&&m():!0===a&&m())});return()=>{i.current=!1,p(),f(),e?.()}},[k,m,p,f]),{status:e?.status??null,requiresSetup:e?.requiresSetup??!1,approvedThisCycle:e?.approvedThisCycle??!1,supported:e?.supported??!1,isLoading:r,refetch:m}}var m=o(),g={sm:{textClass:"font-small",iconSize:16,switchSize:"sm"},md:{textClass:"font-base",iconSize:20,switchSize:void 0}};function v({size:e="sm",fullWidth:u=!1,context:o="bridge",controlOnly:b=!1,"aria-labelledby":v,"aria-describedby":C,_storybook:y}){const w=r(),S=c(),{textClass:x,iconSize:j,switchSize:E}=g[e],[R,T]=(0,h.useState)();(0,h.useEffect)(()=>(n?.getPreferences?.().then(e=>{T(e)}),n?.onPreferencesChanged?.(e=>{T(e)})),[]);const{status:z,supported:_,isDialogOpen:A,enableInFlight:D,appDisplayName:O,handleEnable:q,handleDisable:L,handleCloseDialog:M,handleOpenLoginItems:P}=function(e){const u=r(),o=k(),i=e?.supported??o.supported,c=e?e.status:o.status,d=o.refetch,[p,f]=(0,h.useState)(!1),[b,m]=(0,h.useState)(!1),[g]=l(()=>"nest"===t(navigator.userAgent)?.variant?"Claude Nest":"Claude","Claude"),v=(0,h.useCallback)(()=>{c!==a.RequiresApproval?(n?.setPreference?.("wakeSchedulerEnabled",!0),u.track({event_key:"claudeai.desktop.wake_scheduler_toggled",enabled:!0}),m(!0),d()):f(!0)},[c,u,d]),C=(0,h.useCallback)(()=>{n?.setPreference?.("wakeSchedulerEnabled",!1),u.track({event_key:"claudeai.desktop.wake_scheduler_toggled",enabled:!1}),d()},[u,d]),y=(0,h.useCallback)(()=>{s?.openSettings?.()},[]),w=(0,h.useCallback)(()=>{f(!1)},[]);return(0,h.useEffect)(()=>{if(!b)return;if(c===a.RequiresApproval)return m(!1),void f(!0);if(c===a.Enabled)return void m(!1);const e=setTimeout(()=>m(!1),4e3);return()=>clearTimeout(e)},[b,c]),(0,h.useEffect)(()=>{p&&null!==c&&c!==a.RequiresApproval&&f(!1)},[p,c]),{status:c,supported:i,approvedThisCycle:o.approvedThisCycle,isDialogOpen:p,enableInFlight:b,appDisplayName:g,handleEnable:v,handleDisable:C,handleCloseDialog:w,handleOpenLoginItems:y}}(y?{supported:y.supported,status:y.status}:void 0),K=void 0!==y||void 0!==R?.keepAwakeEnabled,N=y?.legacyOn??!0===R?.keepAwakeEnabled;a.Enabled;const I=(0,h.useCallback)(()=>{const e=!N;n?.setPreference?.("keepAwakeEnabled",e),w.track({event_key:"claudeai.desktop.keep_awake_toggled",enabled:e})},[N,w]);return K?b?(0,m.jsx)(p,{"aria-label":v?void 0:S.formatMessage({defaultMessage:"Keep awake",id:"LyhK7RvVf3"}),"aria-labelledby":v,"aria-describedby":C,checked:N,onCheckedChange:I,size:E}):(0,m.jsx)(d,{multiline:!0,content:(0,m.jsx)(i,{defaultMessage:"When enabled, Claude will prevent your computer from going to sleep.",id:"pkPdf3LvZO"}),side:"bottom",children:(0,m.jsx)("span",{className:u?"block w-full":void 0,children:(0,m.jsxs)("span",{className:"flex items-center gap-2 select-none text-text-300 "+(u?"w-full":""),children:[(0,m.jsx)(f,{size:j}),(0,m.jsx)("span",{className:`${x} ${u?"flex-1":""}`,children:(0,m.jsx)(i,{defaultMessage:"Keep awake",id:"LyhK7RvVf3"})}),(0,m.jsx)(p,{"aria-label":S.formatMessage({defaultMessage:"Keep awake",id:"LyhK7RvVf3"}),checked:N,onCheckedChange:I,size:E})]})})}):null}export{k as n,v as t};