import * as React from "react";
const FieldContext = React.createContext(null);
function useFieldContext() {
  return React.useContext(FieldContext);
}
const FieldSurfaceContext = React.createContext(null);
function useFieldSurface() {
  const surfaceCtx = React.useContext(FieldSurfaceContext);
  if (surfaceCtx) return surfaceCtx;
  const fieldCtx = React.useContext(FieldContext);
  return (fieldCtx == null ? void 0 : fieldCtx.surface) ?? "form";
}
function FieldSurfaceProvider({
  surface,
  children
}) {
  return React.createElement(FieldSurfaceContext.Provider, { value: surface }, children);
}
const TableScrollContext = React.createContext(false);
function useTableIsScrolling() {
  return React.useContext(TableScrollContext);
}
function TableScrollProvider({
  isScrolling,
  children
}) {
  return React.createElement(TableScrollContext.Provider, { value: isScrolling }, children);
}
const FieldSurfaceSizeContext = React.createContext(null);
function useResolvedFieldSize(sizeProp, fallback) {
  const fieldCtx = React.useContext(FieldContext);
  const surfaceSize = React.useContext(FieldSurfaceSizeContext);
  return sizeProp ?? (fieldCtx == null ? void 0 : fieldCtx.size) ?? surfaceSize ?? fallback ?? "md";
}
function useResolvedFieldDisabled(disabledProp) {
  const fieldCtx = React.useContext(FieldContext);
  return disabledProp ?? (fieldCtx == null ? void 0 : fieldCtx.disabled) ?? false;
}
function useResolvedFieldMode({
  mode,
  disabled,
  readOnly
}) {
  const fieldCtx = React.useContext(FieldContext);
  if (mode) return mode;
  if ((disabled ?? (fieldCtx == null ? void 0 : fieldCtx.disabled)) === true) return "disabled";
  if (fieldCtx == null ? void 0 : fieldCtx.mode) return fieldCtx.mode;
  if (readOnly) return "readonly";
  return "edit";
}
function useResolvedFieldVariant(variantProp) {
  const fieldCtx = React.useContext(FieldContext);
  return variantProp ?? (fieldCtx == null ? void 0 : fieldCtx.variant) ?? "default";
}
function useResolvedFieldInvalid(errorProp) {
  const fieldCtx = React.useContext(FieldContext);
  return Boolean(errorProp) || ((fieldCtx == null ? void 0 : fieldCtx.invalid) ?? false);
}
function FieldSurfaceSizeProvider({
  size,
  children
}) {
  return React.createElement(FieldSurfaceSizeContext.Provider, { value: size }, children);
}
export {
  FieldContext,
  FieldSurfaceProvider,
  FieldSurfaceSizeProvider,
  TableScrollProvider,
  useFieldContext,
  useFieldSurface,
  useResolvedFieldDisabled,
  useResolvedFieldInvalid,
  useResolvedFieldMode,
  useResolvedFieldSize,
  useResolvedFieldVariant,
  useTableIsScrolling
};
//# sourceMappingURL=field-context.js.map
