import { Chess } from 'chess.js';
import { CSSProperties } from 'react';
import { default as default_2 } from 'react';
import { MouseEvent as MouseEvent_2 } from 'react';
import { ReactElement } from 'react';
import { ReactNode } from 'react';

export declare interface BoardProps {
    position?: string | Record<string, PieceSymbol>;
    onPieceDrop?: (source: string, target: string, piece: string) => boolean;
    onPieceClick?: (square: string, piece: PieceSymbol) => void;
    onSquareClick?: (square: string) => void;
    onMove?: (move: MoveEvent) => void;
    orientation?: 'white' | 'black';
    customSquareStyles?: Record<string, CSSProperties>;
    theme?: string;
    size?: number | string;
    draggable?: boolean;
    responsive?: boolean;
    darkSquareStyle?: CSSProperties;
    lightSquareStyle?: CSSProperties;
    animationDuration?: number;
    soundEnabled?: boolean;
    accessibilityMode?: boolean;
}

export declare function ChessBoard({ onPieceDrop, orientation, customSquareStyles }: BoardProps): ReactElement;

/** Chess game context interface defining the core chess functionality */
declare interface ChessContextType {
    game: Chess;
    position: string;
    isCheck: boolean;
    isCheckmate: boolean;
    isStalemate: boolean;
    isDraw: boolean;
    isThreefoldRepetition: boolean;
    isFiftyMoveRule: boolean;
    isInsufficientMaterial: boolean;
    turn: 'w' | 'b';
    history: string[];
    moveNumber: number;
    pgn: string;
    makeMove: (from: string, to: string, promotion?: PieceSymbol) => boolean;
    undo: () => boolean;
    redo: () => boolean;
    reset: () => void;
    getPossibleMoves: (square: string) => string[];
    exportPGN: () => string;
    importPGN: (pgn: string) => boolean;
    getGameState: () => GameState;
    validateFen: (fen: string) => boolean;
}

export declare function ChessProvider({ children, initialPosition, enableUndo, onPositionChange, onGameEnd, persistState, defaultTheme, customPieces, preloadThemes }: ChessProviderProps): ReactElement;

declare interface ChessProviderProps {
    children: ReactNode;
    initialPosition?: string;
    enableUndo?: boolean;
    onPositionChange?: (fen: string) => void;
    onGameEnd?: (result: GameResult) => void;
    persistState?: boolean;
    defaultTheme?: string;
    customPieces?: Record<PieceSymbol, string>;
    preloadThemes?: boolean;
}

/** Combined context type that includes both chess and piece functionality */
declare interface CombinedContextType extends ChessContextType {
    currentTheme: string;
    themes: Record<string, PieceTheme>;
    loadTheme: (name: string) => Promise<void>;
    getPieceSvg: (piece: PieceSymbol) => string | null;
    setCustomPiece: (piece: PieceSymbol, url: string) => void;
    resetTheme: () => void;
    preloadTheme: (name: string) => Promise<void>;
    getThemeNames: () => string[];
    isThemeLoaded: (name: string) => boolean;
}

declare interface GameResult {
    winner: 'white' | 'black' | 'draw' | null;
    reason: 'checkmate' | 'stalemate' | 'insufficient-material' | 'threefold-repetition' | 'fifty-move-rule' | 'draw-agreement' | null;
    score: string;
}

export declare interface GameState {
    isCheck: boolean;
    isCheckmate: boolean;
    isStalemate: boolean;
    isDraw: boolean;
    turn: 'white' | 'black';
    moveNumber: number;
    halfMoves: number;
    fen: string;
    pgn: string;
}

export declare const generateFEN: (_position: Record<string, string>) => string;

export declare const isValidMove: (_from: string, _to: string, _piece: string, _position: Record<string, string>) => boolean;

export declare interface Move {
    from: string;
    to: string;
    piece: PieceSymbol;
    captured?: PieceSymbol;
    promotion?: PieceSymbol;
    san: string;
    timestamp?: number;
    evaluation?: number;
}

declare interface MoveEvent {
    from: string;
    to: string;
    piece: PieceSymbol;
    san: string;
    captured?: PieceSymbol;
    promotion?: PieceSymbol;
}

export declare const Piece: default_2.FC<PieceProps>;

export declare type PieceColor = 'w' | 'b';

declare interface PieceContextType {
    currentTheme: string;
    themes: Record<string, PieceTheme>;
    loadTheme: (name: string) => Promise<void>;
    getPieceSvg: (piece: PieceSymbol) => string | null;
    setCustomPiece: (piece: PieceSymbol, url: string) => void;
    resetTheme: () => void;
    preloadTheme: (name: string) => Promise<void>;
    getThemeNames: () => string[];
    isThemeLoaded: (name: string) => boolean;
}

export declare interface PieceProps {
    piece: PieceSymbol;
    square: string;
    isDragging: boolean;
    _theme?: string;
    onClick?: (event: MouseEvent_2<HTMLDivElement>) => void;
    onDragStart?: (event: MouseEvent_2<HTMLDivElement>) => void;
    style?: CSSProperties;
}

export declare function PieceProvider({ children, defaultTheme, customPieces, preloadThemes }: PieceProviderProps): ReactElement;

declare interface PieceProviderProps {
    children: ReactNode;
    defaultTheme?: string;
    customPieces?: Record<PieceSymbol, string>;
    preloadThemes?: boolean;
}

export declare type PieceSymbol = `${PieceColor}${PieceType}`;

export declare interface PieceTheme {
    name: string;
    pieces: Record<PieceSymbol, string>;
}

export declare type PieceType = 'p' | 'n' | 'b' | 'r' | 'q' | 'k';

export declare interface Square {
    file: string;
    rank: number;
    color: 'light' | 'dark';
    piece?: PieceSymbol;
    highlighted?: boolean;
    selected?: boolean;
    lastMove?: boolean;
}

export declare const useChess: () => CombinedContextType;

export declare const useChessGame: (initialPosition?: string) => {
    position: string;
    gameState: GameState;
    makeMove: (from: string, to: string) => boolean;
};

export declare const usePieces: () => PieceContextType;

export { }
