/// <reference types="react" />

import {CardProps} from '@sanity/ui'
import {CardTone} from '@sanity/ui'
import type {ImageUrlBuilder} from 'sanity'
import {JSX as JSX_2} from 'react'
import {ListenQueryOptions} from 'sanity'
import {ListenQueryParams} from 'sanity'
import type {PropsWithChildren} from 'react'
import type {ReactNode} from 'react'
import type {SanityImageSource} from '@sanity/asset-utils'
import type {SourceClientOptions} from 'sanity'

export declare function Cell(props: TableCellProps): JSX_2.Element

declare interface Config<V> {
  params?: ListenQueryParams
  options?: ListenQueryOptions
  initialValue?: null | V
}

export declare function Feedback(props: FeedbackProps): JSX_2.Element

declare type FeedbackChildren = {
  children?: ReactNode
  title?: never
  description?: never
}

declare type FeedbackProps = (FeedbackChildren | FeedbackTextProps) & {
  tone?: CardTone
  icon?: ReactNode
}

declare type FeedbackTextProps = {
  title?: string
  description?: ReactNode
  children?: never
}

declare type HookConfig = {
  apiVersion?: string
}

declare type Labels = {
  addMe?: string
  removeMe?: string
  clear?: string
  searchPlaceholder?: string
  notFound?: string
}

declare interface Return<V = Value> {
  loading: boolean
  error: boolean | unknown | ProgressEvent
  data: unknown | V
  initialValue?: Value
}

export declare function Row(props: TableRowProps): JSX_2.Element

export declare function Table(props: TableProps): JSX_2.Element

declare type TableCellProps = PropsWithChildren<
  CardProps & {
    colSpan?: number
    rowSpan?: number
  }
>

declare type TableProps = PropsWithChildren<CardProps>

declare type TableRowProps = PropsWithChildren<CardProps>

export declare function useImageUrlBuilder(
  clientOptions?: SourceClientOptions
): ImageUrlBuilder | null

export declare function useImageUrlBuilderImage(
  source: SanityImageSource,
  clientOptions?: SourceClientOptions
): ImageUrlBuilder | null

export declare function useListeningQuery<V>(
  query:
    | string
    | {
        fetch: string
        listen: string
      },
  {params, options, initialValue}: Config<V>
): Return<V>

export declare function useOpenInNewPane(id?: string, type?: string): () => void

export declare function useProjectUsers({
  apiVersion,
}: HookConfig): UserExtended[]

export declare type UserExtended = {
  createdAt: string
  displayName: string
  email: string
  familyName: string
  givenName: string
  id: string
  imageUrl: string
  isCurrentUser: boolean
  middleName: string
  projectId: string
  provider: string
  sanityUserId: string
  updatedAt: string
}

export declare function UserSelectMenu(
  props: UserSelectMenuProps
): JSX_2.Element

declare type UserSelectMenuProps = {
  value: string[]
  userList: UserExtended[]
  onAdd: (userId: string) => void
  onRemove: (userId: string) => void
  onClear: () => void
  labels?: Labels
  style?: React.CSSProperties
}

declare type Value = unknown

export {}
