import {ComponentType} from 'react'
import {ConditionalProperty} from 'sanity'
import {NumberOptions} from 'sanity'
import {ObjectDefinition} from 'sanity'
import {ObjectOptions} from 'sanity'
import {Plugin as Plugin_2} from 'sanity'
import {ReactNode} from 'react'
import {StringOptions} from 'sanity'

export declare const defaultI18nFieldsConfigUI: I18nFieldsConfigUI

declare interface FilteredInternalLocale
  extends Omit<
    InternalLocale,
    | 'label'
    | 'title'
    | 'default'
    | 'hasError'
    | 'hasWarning'
    | 'isReadOnly'
    | 'isHidden'
    | 'isChanged'
  > {}

export declare const I18nFields: Plugin_2<I18nFieldsConfig>

export declare interface I18nFieldsConfig {
  prefix?: string
  locales: Locale[]
  ui?: I18nFieldsConfigUI
}

export declare interface I18nFieldsConfigUI {
  type?: 'slider' | 'dropdown'
  position?: 'top' | 'bottom'
  selected?: 'background' | 'border'
}

export declare type I18nFieldType = 'string' | 'text' | 'number'

export declare type I18nNumberDefinition = Omit<
  ObjectDefinition,
  'type' | 'fields' | 'components' | 'options'
> & {
  type: 'i18n.number'
  options?: I18nNumberOptions & Omit<ObjectOptions, 'columns'>
}

export declare interface I18nNumberLocale extends FilteredInternalLocale {
  options?: NumberOptions
}

export declare interface I18nNumberOptions {
  locales?: I18nNumberLocale[]
  ui?: I18nFieldsConfigUI
}

export declare type I18nStringDefinition = Omit<
  ObjectDefinition,
  'type' | 'fields' | 'components' | 'options'
> & {
  type: 'i18n.string'
  options?: I18nStringOptions & Omit<ObjectOptions, 'columns'>
}

export declare interface I18nStringLocale extends FilteredInternalLocale {
  options?: StringOptions
}

export declare interface I18nStringOptions {
  locales?: I18nStringLocale[]
  ui?: I18nFieldsConfigUI
}

export declare type I18nTextDefinition = Omit<
  ObjectDefinition,
  'type' | 'fields' | 'components' | 'options'
> & {
  type: 'i18n.text'
  options?: I18nTextOptions & Omit<ObjectOptions, 'columns'>
}

export declare interface I18nTextLocale extends FilteredInternalLocale {
  options?: {
    rows?: number
  }
}

export declare interface I18nTextOptions {
  rows?: number
  locales?: I18nTextLocale[]
  ui?: I18nFieldsConfigUI
}

export declare interface InternalLocale extends Locale {
  hasError?: boolean
  hasWarning?: boolean
  isChanged?: boolean
  isReadOnly?: boolean
  isHidden?: boolean
  readOnly?: ConditionalProperty
  hidden?: ConditionalProperty
  options?: any
}

export declare interface Locale {
  code: string
  label: ReactNode | ComponentType
  title: string
  default?: boolean
  visibleFor?: string[]
  editableFor?: string[]
}

export {}

declare module 'sanity' {
  interface IntrinsicDefinitions {
    'i18n.string': I18nStringDefinition
  }
  interface IntrinsicDefinitions {
    'i18n.number': I18nNumberDefinition
  }
  interface IntrinsicDefinitions {
    'i18n.text': I18nTextDefinition
  }
}
