import{j as e,r as a}from"./vendor-react-Dp9pL_Wn.js";import{aT as t,bj as s,bk as r,w as l,bl as n,bm as u}from"./c6eedc03a-CsEFTfjy.js";import{bv as c}from"./index-CBEPphRm.js";import{u as o,M as i}from"./vendor-intl-D2wGIp4M.js";import{S as d,T as p}from"./vendor-ant-cds-bBedrtIN.js";const f=a=>e.jsx(t,{...a,children:e.jsx("path",{d:"M10 15a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2a.5.5 0 0 1 .5-.5m-4.242-1.465a.5.5 0 0 1 .707.707L5.05 15.657a.5.5 0 0 1-.707-.707zm7.777 0a.5.5 0 0 1 .707 0l1.415 1.414a.501.501 0 0 1-.707.708l-1.415-1.415a.5.5 0 0 1 0-.707M10 6a4 4 0 1 1 0 8 4 4 0 0 1 0-8m0 1a3 3 0 1 0 0 6 3 3 0 0 0 0-6M4.5 9.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1zm13 0a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1zM4.343 4.343a.5.5 0 0 1 .707 0l1.415 1.414a.501.501 0 0 1-.707.708L4.343 5.05a.5.5 0 0 1 0-.707m10.607 0a.5.5 0 0 1 .707.707l-1.415 1.415a.5.5 0 0 1-.707-.707zM10 2a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 10 2"})}),b=[300,1e3,3e3];function h(){const[e,t]=a.useState(null),[l,n]=a.useState(!0),u=a.useRef(null),o=a.useRef([]),i=a.useRef(!0),d=a.useRef(void 0),p=a.useRef(null),f=a.useCallback(()=>{null!==u.current&&(clearTimeout(u.current),u.current=null)},[]),h=a.useCallback(()=>{for(const e of o.current)clearTimeout(e);o.current=[]},[]),k=a.useCallback(async()=>{if(s?.getStatus)try{const e=await s.getStatus();if(!i.current)return;t(e),p.current=e.status,n(!1),e.status===c.RequiresApproval?(h(),f(),u.current=setTimeout(()=>{i.current&&k()},5e3)):f()}catch{if(!i.current)return;n(!1),p.current===c.RequiresApproval&&(f(),u.current=setTimeout(()=>{i.current&&k()},5e3))}else n(!1)},[f,h]),m=a.useCallback(()=>{f(),h(),k(),o.current=b.map(e=>setTimeout(()=>{i.current&&k()},e))},[f,h,k]);return a.useEffect(()=>{i.current=!0,k();const e=r?.onPreferencesChanged?.(e=>{const a=e.wakeSchedulerEnabled,t=d.current;d.current=a,i.current&&(void 0!==t?a!==t&&m():!0===a&&m())});return()=>{i.current=!1,f(),h(),e?.()}},[k,m,f,h]),{status:e?.status??null,requiresSetup:e?.requiresSetup??!1,approvedThisCycle:e?.approvedThisCycle??!1,supported:e?.supported??!1,isLoading:l,refetch:m}}const k={sm:{textClass:"font-small",iconSize:16,switchSize:"sm"},md:{textClass:"font-base",iconSize:20,switchSize:void 0}};function m({size:t="sm",fullWidth:b=!1,context:m="bridge",controlOnly:v=!1,"aria-labelledby":g,"aria-describedby":C,_storybook:w}){const x=l(),y=o(),{textClass:S,iconSize:j,switchSize:z}=k[t],[E,R]=a.useState();a.useEffect(()=>(r?.getPreferences?.().then(e=>{R(e)}),r?.onPreferencesChanged?.(e=>{R(e)})),[]);const{status:T}=function(e){const t=l(),o=h(),i=e?.supported??o.supported,d=e?e.status:o.status,p=o.refetch,[f,b]=a.useState(!1),[k,m]=a.useState(!1),[v]=n(()=>"nest"===u(navigator.userAgent)?.variant?"Claude Nest":"Claude","Claude"),g=a.useCallback(()=>{d!==c.RequiresApproval?(r?.setPreference?.("wakeSchedulerEnabled",!0),t.track({event_key:"claudeai.desktop.wake_scheduler_toggled",enabled:!0}),m(!0),p()):b(!0)},[d,t,p]),C=a.useCallback(()=>{r?.setPreference?.("wakeSchedulerEnabled",!1),t.track({event_key:"claudeai.desktop.wake_scheduler_toggled",enabled:!1}),p()},[t,p]),w=a.useCallback(()=>{s?.openSettings?.()},[]),x=a.useCallback(()=>{b(!1)},[]);return a.useEffect(()=>{if(!k)return;if(d===c.RequiresApproval)return m(!1),void b(!0);if(d===c.Enabled)return void m(!1);const e=setTimeout(()=>m(!1),4e3);return()=>clearTimeout(e)},[k,d]),a.useEffect(()=>{f&&null!==d&&d!==c.RequiresApproval&&b(!1)},[f,d]),{status:d,supported:i,approvedThisCycle:o.approvedThisCycle,isDialogOpen:f,enableInFlight:k,appDisplayName:v,handleEnable:g,handleDisable:C,handleCloseDialog:x,handleOpenLoginItems:w}}(w?{supported:w.supported,status:w.status}:void 0),M=void 0!==w||void 0!==E?.keepAwakeEnabled,A=w?.legacyOn??!0===E?.keepAwakeEnabled;c.Enabled;const _=a.useCallback(()=>{const e=!A;r?.setPreference?.("keepAwakeEnabled",e),x.track({event_key:"claudeai.desktop.keep_awake_toggled",enabled:e})},[A,x]);return M?v?e.jsx(d,{"aria-label":g?void 0:y.formatMessage({defaultMessage:"Keep awake",id:"LyhK7RvVf3"}),"aria-labelledby":g,"aria-describedby":C,checked:A,onCheckedChange:_,size:z}):e.jsx(p,{multiline:!0,content:e.jsx(i,{defaultMessage:"When enabled, Claude will prevent your computer from going to sleep.",id:"pkPdf3LvZO"}),side:"bottom",children:e.jsx("span",{className:b?"block w-full":void 0,children:e.jsxs("span",{className:"flex items-center gap-2 select-none text-text-300 "+(b?"w-full":""),children:[e.jsx(f,{size:j}),e.jsx("span",{className:`${S} ${b?"flex-1":""}`,children:e.jsx(i,{defaultMessage:"Keep awake",id:"LyhK7RvVf3"})}),e.jsx(d,{"aria-label":y.formatMessage({defaultMessage:"Keep awake",id:"LyhK7RvVf3"}),checked:A,onCheckedChange:_,size:z})]})})}):null}export{m as K,h as u};
