/// <reference types="vite/client" />

/**
 * LuckyExcel 타입 선언
 */
declare module "luckyexcel" {
  interface LuckyExcelOptions {
    container?: string;
    title?: string;
    lang?: string;
    data?: any[];
    options?: {
      showtoolbar?: boolean;
      showinfobar?: boolean;
      showsheetbar?: boolean;
      showstatisticBar?: boolean;
      allowCopy?: boolean;
      allowEdit?: boolean;
      enableAddRow?: boolean;
      enableAddCol?: boolean;
    };
  }

  interface LuckySheetData {
    name: string;
    index: string;
    celldata: any[];
    status: number;
    order: number;
    row: number;
    column: number;
  }

  interface LuckyExcelResult {
    sheets: Array<{
      name: string;
      row: number;
      column: number;
      celldata: Array<{
        r: number;
        c: number;
        v: {
          v: any;
          m: string;
          ct?: any;
        };
      }>;
    }>;
  }

  function transformExcelToLucky(
    arrayBuffer: ArrayBuffer,
    fileName: string,
    callback: (exportJson: LuckyExcelResult, luckysheetfile: any) => void,
  ): void;

  export {
    transformExcelToLucky,
    LuckyExcelOptions,
    LuckySheetData,
    LuckyExcelResult,
  };
}

/**
 * Luckysheet 타입 선언
 */
declare module "luckysheet" {
  interface LuckysheetConfig {
    container?: string;
    title?: string;
    lang?: string;
    data?: any[];
    myFolderUrl?: string;
    plugins?: string[];
    fontList?: Array<{
      fontFamily: string;
      name: string;
    }>;
    options?: {
      showtoolbar?: boolean;
      showinfobar?: boolean;
      showsheetbar?: boolean;
      showstatisticBar?: boolean;
      allowCopy?: boolean;
      allowEdit?: boolean;
      enableAddRow?: boolean;
      enableAddCol?: boolean;
      sheetRightClickConfig?: {
        delete?: boolean;
        copy?: boolean;
        rename?: boolean;
        color?: boolean;
        hide?: boolean;
        move?: boolean;
      };
      cellRightClickConfig?: {
        copy?: boolean;
        copyAs?: boolean;
        paste?: boolean;
        insertRow?: boolean;
        insertColumn?: boolean;
        deleteRow?: boolean;
        deleteColumn?: boolean;
        deleteCell?: boolean;
        hideRow?: boolean;
        hideColumn?: boolean;
        rowHeight?: boolean;
        columnWidth?: boolean;
        clear?: boolean;
        matrix?: boolean;
        sort?: boolean;
        filter?: boolean;
        chart?: boolean;
        image?: boolean;
        link?: boolean;
        data?: boolean;
        cellFormat?: boolean;
      };
    };
    hook?: {
      cellMousedown?: (cell: any, postion: any, sheetFile: any) => void;
      cellClick?: (cell: any, postion: any, sheetFile: any) => void;
      sheetActivate?: (
        index: number,
        isPivotInitial: boolean,
        isInitialLoad: boolean,
      ) => void;
      updated?: (operate: any) => void;
    };
  }

  interface LuckysheetAPI {
    create: (config: LuckysheetConfig) => void;
    destroy: () => void;
    refreshFormula: () => void;
    setSheetData: (data: any[]) => void;
    getAllSheets: () => any[];
    getSheet: (index?: number) => any;
    setActiveSheet: (index: number) => void;
    getCellValue: (r: number, c: number, data?: any) => any;
    setCellValue: (r: number, c: number, d: any, isRefresh?: boolean) => void;
    getRange: () => any[];
    setRange: (range: any[]) => void;
    scroll: (settings: { scrollLeft?: number; scrollTop?: number }) => void;
    resize: () => void;
    undo: () => void;
    redo: () => void;
    copy: () => void;
    paste: () => void;
    cut: () => void;
    insertRow: (index?: number) => void;
    insertColumn: (index?: number) => void;
    deleteRow: (start: number, end?: number) => void;
    deleteColumn: (start: number, end?: number) => void;
    hideRow: (rowIndexes: number[]) => void;
    showRow: (rowIndexes: number[]) => void;
    hideColumn: (columnIndexes: number[]) => void;
    showColumn: (columnIndexes: number[]) => void;
    setRowHeight: (rowInfo: { [key: number]: number }) => void;
    setColumnWidth: (columnInfo: { [key: number]: number }) => void;
    getRowHeight: (rowIndexes: number[]) => { [key: number]: number };
    getColumnWidth: (columnIndexes: number[]) => { [key: number]: number };
    setWorkbookName: (name: string) => void;
    getWorkbookName: () => string;
    exitEditMode: () => void;
    enterEditMode: (cell?: any) => void;
    updateCell: (r: number, c: number, value: any) => void;
    refreshCanvas: () => void;
  }

  const luckysheet: LuckysheetAPI;
  export = luckysheet;
}

/**
 * Luckysheet 전역 변수 타입 선언
 */
declare global {
  interface Window {
    luckysheet: {
      create: (options: {
        container: string;
        data: any[];
        title?: string;
        userInfo?: string;
        [key: string]: any;
      }) => void;
      destroy: () => void;
      resize?: () => void;
      [key: string]: any;
    };
    LuckyExcel: {
      transformExcelToLucky: (
        file: File | ArrayBuffer,
        successCallback: (exportJson: any, luckysheetfile: any) => void,
        errorCallback: (error: any) => void,
      ) => void;
      [key: string]: any;
    };
    $: any; // jQuery
    Store?: any; // Luckysheet Store
    luckysheet_function?: any; // Luckysheet function list
    functionlist?: any[]; // 글로벌 functionlist
    luckysheetConfigsetting?: any; // Luckysheet 설정 객체
    luckysheetPostil?: any; // Luckysheet 포스틸 객체
  }
}

export {};
