import React, { createContext, type ReactNode, useSyncExternalStore } from 'react'
import { c as _c } from 'react/compiler-runtime'

import {
  getTerminalFocused,
  getTerminalFocusState,
  subscribeTerminalFocus,
  type TerminalFocusState
} from '../terminal-focus-state.js'
export type { TerminalFocusState }
export type TerminalFocusContextProps = {
  readonly isTerminalFocused: boolean
  readonly terminalFocusState: TerminalFocusState
}

const TerminalFocusContext = createContext<TerminalFocusContextProps>({
  isTerminalFocused: true,
  terminalFocusState: 'unknown'
})

TerminalFocusContext.displayName = 'TerminalFocusContext'

// Separate component so App.tsx doesn't re-render on focus changes.
// Children are a stable prop reference, so they don't re-render either —
// only components that consume the context will re-render.
export function TerminalFocusProvider(t0: { readonly children: ReactNode }) {
  const $ = _c(6)

  const { children } = t0

  const isTerminalFocused = useSyncExternalStore(subscribeTerminalFocus, getTerminalFocused)
  const terminalFocusState = useSyncExternalStore(subscribeTerminalFocus, getTerminalFocusState)
  let t1

  if ($[0] !== isTerminalFocused || $[1] !== terminalFocusState) {
    t1 = {
      isTerminalFocused,
      terminalFocusState
    }
    $[0] = isTerminalFocused
    $[1] = terminalFocusState
    $[2] = t1
  } else {
    t1 = $[2]
  }

  const value = t1
  let t2

  if ($[3] !== children || $[4] !== value) {
    t2 = <TerminalFocusContext.Provider value={value}>{children}</TerminalFocusContext.Provider>
    $[3] = children
    $[4] = value
    $[5] = t2
  } else {
    t2 = $[5]
  }

  return t2
}

export default TerminalFocusContext
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZWFjdCIsImNyZWF0ZUNvbnRleHQiLCJ1c2VNZW1vIiwidXNlU3luY0V4dGVybmFsU3RvcmUiLCJnZXRUZXJtaW5hbEZvY3VzZWQiLCJnZXRUZXJtaW5hbEZvY3VzU3RhdGUiLCJzdWJzY3JpYmVUZXJtaW5hbEZvY3VzIiwiVGVybWluYWxGb2N1c1N0YXRlIiwiVGVybWluYWxGb2N1c0NvbnRleHRQcm9wcyIsImlz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