; Detect JSX usage (component/page/layout)
[(jsx_element) (jsx_self_closing_element)] @has_jsx

; Detect React hooks (function name starts with use)
(function_declaration
  name: (identifier) @hook_decl
  (#match? @hook_decl "^use[A-Z]"))

(lexical_declaration
  (variable_declarator
    name: (identifier) @hook_const
    (#match? @hook_const "^use[A-Z]")))

; Detect useState/useEffect usage (consumer of hooks)
(call_expression
  function: (identifier) @hook_call
  (#match? @hook_call "^use[A-Z]"))

; Detect React.createContext
(call_expression
  function: (member_expression
    object: (identifier) @_react
    property: (property_identifier) @_createCtx)
  (#eq? @_react "React")
  (#eq? @_createCtx "createContext")) @has_create_context

(call_expression
  function: (identifier) @_createCtx2
  (#eq? @_createCtx2 "createContext")) @has_create_context_bare

; Detect HTTP method exports (API endpoint)
(export_statement
  declaration: (lexical_declaration
    (variable_declarator
      name: (identifier) @http_export
      (#match? @http_export "^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$"))))

(export_statement
  declaration: (function_declaration
    name: (identifier) @http_export_fn
    (#match? @http_export_fn "^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$")))

; export const { GET, POST } = handlers  (Auth.js v5 / NextAuth pattern)
(export_statement
  declaration: (lexical_declaration
    (variable_declarator
      name: (object_pattern
        (shorthand_property_identifier_pattern) @http_export
        (#match? @http_export "^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$")))))

; Detect Next.js Server Action directive: 'use server' at file top.
; Tree-sitter represents the directive as an expression_statement whose only
; child is a string literal — and it must be at program level.
(program
  (expression_statement
    (string (string_fragment) @use_server_directive)
    (#eq? @use_server_directive "use server")))
