import{j as e,r as a}from"./vendor-react-Dp9pL_Wn.js";import{bw as t,bx as s,by as r,I as n,bz as l,bA as u}from"./c2ee0272b-DPDuX889.js";import{u as c,M as o}from"./vendor-intl-D2wGIp4M.js";import{bz as i}from"./index-XoaBlZfC.js";import{S as d,T as p}from"./vendor-ant-cds-BLsR_p72.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 k(){const[e,t]=a.useState(null),[n,l]=a.useState(!0),u=a.useRef(null),c=a.useRef([]),o=a.useRef(!0),d=a.useRef(void 0),p=a.useRef(null),f=a.useCallback(()=>{null!==u.current&&(clearTimeout(u.current),u.current=null)},[]),k=a.useCallback(()=>{for(const e of c.current)clearTimeout(e);c.current=[]},[]),m=a.useCallback(async()=>{if(s?.getStatus)try{const e=await s.getStatus();if(!o.current)return;t(e),p.current=e.status,l(!1),e.status===i.RequiresApproval?(k(),f(),u.current=setTimeout(()=>{o.current&&m()},5e3)):f()}catch{if(!o.current)return;l(!1),p.current===i.RequiresApproval&&(f(),u.current=setTimeout(()=>{o.current&&m()},5e3))}else l(!1)},[f,k]),h=a.useCallback(()=>{f(),k(),m(),c.current=b.map(e=>setTimeout(()=>{o.current&&m()},e))},[f,k,m]);return a.useEffect(()=>{o.current=!0,m();const e=r?.onPreferencesChanged?.(e=>{const a=e.wakeSchedulerEnabled,t=d.current;d.current=a,o.current&&(void 0!==t?a!==t&&h():!0===a&&h())});return()=>{o.current=!1,f(),k(),e?.()}},[m,h,f,k]),{status:e?.status??null,requiresSetup:e?.requiresSetup??!1,approvedThisCycle:e?.approvedThisCycle??!1,supported:e?.supported??!1,isLoading:n,refetch:h}}const m={sm:{textClass:"font-small",iconSize:16,switchSize:"sm"},md:{textClass:"font-base",iconSize:20,switchSize:void 0}};function h({size:t="sm",fullWidth:b=!1,context:h="bridge",controlOnly:v=!1,"aria-labelledby":g,"aria-describedby":C,_storybook:x}){const w=n(),y=c(),{textClass:S,iconSize:j,switchSize:z}=m[t],[R,M]=a.useState();a.useEffect(()=>(r?.getPreferences?.().then(e=>{M(e)}),r?.onPreferencesChanged?.(e=>{M(e)})),[]),function(e){const t=n(),c=k(),o=e?.supported??c.supported,d=e?e.status:c.status,p=c.refetch,[f,b]=a.useState(!1),[m,h]=a.useState(!1),[v]=l(()=>"nest"===u(navigator.userAgent)?.variant?"Claude Nest":"Claude","Claude"),g=a.useCallback(()=>{d!==i.RequiresApproval?(r?.setPreference?.("wakeSchedulerEnabled",!0),t.track({event_key:"claudeai.desktop.wake_scheduler_toggled",enabled:!0}),h(!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]),x=a.useCallback(()=>{s?.openSettings?.()},[]),w=a.useCallback(()=>{b(!1)},[]);a.useEffect(()=>{if(!m)return;if(d===i.RequiresApproval)return h(!1),void b(!0);if(d===i.Enabled)return void h(!1);const e=setTimeout(()=>h(!1),4e3);return()=>clearTimeout(e)},[m,d]),a.useEffect(()=>{f&&null!==d&&d!==i.RequiresApproval&&b(!1)},[f,d]),c.approvedThisCycle}(x?{supported:x.supported,status:x.status}:void 0);const A=void 0!==x||void 0!==R?.keepAwakeEnabled,E=x?.legacyOn??!0===R?.keepAwakeEnabled,T=a.useCallback(()=>{const e=!E;r?.setPreference?.("keepAwakeEnabled",e),w.track({event_key:"claudeai.desktop.keep_awake_toggled",enabled:e})},[E,w]);return A?v?e.jsx(d,{"aria-label":g?void 0:y.formatMessage({defaultMessage:"Keep awake",id:"LyhK7RvVf3"}),"aria-labelledby":g,"aria-describedby":C,checked:E,onCheckedChange:T,size:z}):e.jsx(p,{multiline:!0,content:e.jsx(o,{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(o,{defaultMessage:"Keep awake",id:"LyhK7RvVf3"})}),e.jsx(d,{"aria-label":y.formatMessage({defaultMessage:"Keep awake",id:"LyhK7RvVf3"}),checked:E,onCheckedChange:T,size:z})]})})}):null}export{h as K,k as u};
