import React from "react";
// @ts-ignore
import ReactExport from "react-export-excel";
import { isEmpty } from "../../utils/utils";
import { IButtonProps } from '../button/Button';
import { JDbutton } from '../components';

const ExcelFile = ReactExport.ExcelFile;
const ExcelSheet = ReactExport.ExcelFile.ExcelSheet;

export type TMultiColumnData = {
    value: string;
    style?: any;
}[];

export type TMultiColumns = {
    columns: string[];
    data: TMultiColumnData[];
};

export interface IExcelProps {
    data: TMultiColumns[];
    element?: JSX.Element;
    btnProp?: IButtonProps;
}

// const EXAMPLE DATA = [
//     {
//       columns: [
//         { value: "Name", widthPx: 50 }, // width in pixels
//         { value: "Salary", widthCh: 20 }, // width in charachters
//         { value: "Sex", widthPx: 60, widthCh: 20 }, // will check for width in pixels first
//       ],
//       data: [
//         ["Johnson", 30000, "Male"],
//         ["Monika", 355000, "Female"],
//         ["Konstantina", 20000, "Female"],
//         ["John", 250000, "Male"],
//         ["Josef", 450500, "Male"],
//       ],
//     },
//     {
//       xSteps: 1, // Will start putting cell with 1 empty cell on left most
//       ySteps: 5, //will put space of 5 rows,
//       columns: ["Name", "Department"],
//       data: [
//         ["Johnson", "Finance"],
//         ["Monika", "IT"],
//         ["Konstantina", "IT Billing"],
//         ["John", "HR"],
//         ["Josef", "Testing"],
//       ],
//     },
//   ];

export const Excel: React.FC<IExcelProps> = ({ data: datas, element, btnProp }) => {
    return (
        <ExcelFile
            element={
                element || (
                    <JDbutton
                        disabled={isEmpty(datas)}
                        mode="flat"
                        thema="primary"
                        label={"엑셀출력"}
                        {...btnProp}
                    />
                )
            }
        >
            <ExcelSheet dataSet={datas} name="Organization" />
        </ExcelFile>
    );
};

// 데이터 예시
export default Excel;




