import React, { Component } from "react";
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
import Images from "../../assets/Images";
import MUIDataTable from "mui-datatables";
import { InputBase } from "@material-ui/core";
import { ExcelRenderer } from 'react-excel-renderer';
import UploadFile from "../../library/Upload";
import CreateReportItems from "./formReportItems/CreateReportItems";
import EditReportItems from "./formReportItems/EditReportItems";
import VisualReportItems from "./formReportItems/VisualReportItems";
import api from "../../api";
import ReactTooltip from "react-tooltip";
import PopUpFailedSave from "../../library/PopUpFailedSave";

var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());
const options = ct.customOptions();
const options2 = ct.customOptions2();

export default class ReportItems extends Component {
    constructor(props) {
        super(props)
        this.state = {
            dataTable: [],
            listData: [],
            data: [],
            search: "",
            itemReport: true,
            visualisasi: false,
            add: false,
            edit: false,
            dataLoaded: false,
            cols: null,
            rows: null,
            popupError: false
        }

        this.fileHandler = this.fileHandler.bind(this);
    }

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
            if (err) {
                console.log(err);
            }
            else {
                let judul = resp.rows[0]
                let isi = resp.rows.slice(3)
                let payload = []
                isi.map((item, index) => {
                    if (item.length > 0) {
                        payload.push({
                            id: index + 1,
                            report: item[0],
                            company: item[1],
                            orders: item[2],
                            description: item[3],
                            parent: item[4],
                            uom: item[5],
                            weight: String(item[6]),
                            type_report: item[7],
                            formula: item[8],
                            condition_it_should_be: item[9],
                            condition_if_wrong: item[10],
                            start_date: item[11],
                            end_date: item[12],
                        })
                    }
                })
                let body = {
                    item_report: payload
                }
                this.setState({ payload: body, buttonError: false })
                api.create().checkUploadReportItems(body).then(response => {
                    if (response.data.status === "success") {
                        console.log(response)
                        let dataRow = response.data.data.map((item, index) => {

                            return [
                                index + 1,
                                item.report,
                                item.company,
                                item.orders,
                                item.description,
                                item.parent,
                                item.uom,
                                item.weight,
                                item.type_report,
                                item.formula,
                                item.condition_it_should_be,
                                item.condition_if_wrong,
                                item.start_date,
                                item.end_date,
                                item.error
                            ]
                        })
                        let columns = [
                            "Data Ke-",
                            {
                                name: "Jenis Laporan",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('report'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="reportname">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="reportname" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Perusahaan",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('company'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="companyname">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="companyname" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Order",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('orders'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="order">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="order" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Deskripsi",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('description'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="desc">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="desc" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Parent ID",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('parent'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="parents">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="parents" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "UOM",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('uom'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="uoms">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="uoms" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Weight",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('weight'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="weights">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="weights" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Tipe Data",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('type_report'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="datatype">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="datatype" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Formula",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('formula'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="formulas">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="formulas" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Nilai Seharusnya",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('condition_it_should_be'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="values">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="values" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Kondisi Jika Salah",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('condition_if_wrong'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="conditions">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="conditions" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Berlaku Mulai",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('start_date'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="startdate">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Berakhir Hingga",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[14] != null) {
                                            check = tableMeta.rowData[14].findIndex((val) => val.field.includes('end_date'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[14] != null && check > -1 ?
                                                    <a data-tip={tableMeta.rowData[14][check].message} data-for="enddate">
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    </a> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                }
                                                <ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "",
                                options: {
                                    display: false
                                }
                            }
                        ]

                        console.log(dataRow);
                        this.setState({
                            dataLoaded: true,
                            cols: columns,
                            rows: dataRow
                        });
                    }
                    console.log(response);
                })
            }
        });
    }

    componentDidMount() {
        this.getData()
    }

    getData() {
        api.create().getReportItems().then((response) => {
            console.log(response)
            if (response.data.status == 'success') {
                let data = response.data.data
                let listData = data.sort((a, b) => a.item_report_id - b.item_report_id).map((item, index) => {
                    return [index, item.item_report_id, item.report_name, item.company_name, item.order, item.description, item.parent, item.uom, item.weight, item.type_report_name, item.status]
                })
                this.setState({ dataTable: listData, listData: response.data.data })
            } else {
                alert(response.data.message)
            }
        })
    }

    openPopUp(index, type) {
        if (type === 'edit') {
            this.setState({
                rowData: index,
                edit: true
            })
        } else {
            this.setState({
                add: true
            })
        }
    }

    handleInputChange(e) {
        this.setState({ search: e })
        let body = {
            "keyword": e
        }
        api.create().searchReportItems(body).then(response => {
            // console.log(response.data);
            if (response.data.status == 'success') {
                let data = response.data.data
                let listData = data.map((item, index) => {
                    return [index, item.item_report_id, item.report_name, item.company_name, item.order, item.description, item.parent, item.uom, item.weight, item.type_report_name, item.status]
                })
                this.setState({ dataTable: listData, listData: response.data.data })
            } else {
                alert(response.data.message)
            }
        })
    }

    createReportItems = (payload) => {
        this.setState({ add: false })
        api.create().createReportItems(payload).then(response => {
            if (response.data.status == 'success') {
                this.getData()
            } else {
                alert(response.data.message)
            }
        })
    }

    downloadFile = async () => {
        let res = await fetch(
            "https://tia.eksad.com/tia-reporting-dev/public/attachment/download_file?fileName=ItemReportTemplate&&fileType=xlsx"
        )
        res = await res.blob()
        console.log(res)
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
            a.download = 'Template Report Item.xlsx';
            a.click();
        }
    }

    downloadDataTable = async () => {
        let res = await fetch(
            "https://tia.eksad.com/tia-reporting-dev/public/item_report/export_item_report"
        )
        res = await res.blob()
        console.log(res)
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
            a.download = 'Item Report.xlsx';
            a.click();
        }
    }

    updateReportItems = (payload) => {
        this.setState({ edit: false })
        api.create().updateReportItems(payload).then(response => {
            if (response.data.status == 'success') {
                this.getData()
            } else {
                alert(response.data.message)
            }
        })
    }

    uploadReportItems() {
        api.create().uploadReportItems(this.state.payload).then(response => {
            if (response.data) {
                if (response.data.status === "success") {
                    console.log(response)
                    alert(response.data.message)
                    this.getData()
                    this.setState({ itemReport: true })
                }
            }
        })
    }

    render() {
        const columns = [{
            name: "Action",
            options: {
                sort: false,
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <button
                                style={{
                                    backgroundColor: 'transparent',
                                    cursor: 'pointer',
                                    borderColor: 'transparent'
                                }}
                                onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}

                            >
                                <img src={Images.editCopy} />
                            </button>
                        </div >
                    );
                }
            }
        },
        {
            name: "ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Jenis Laporan",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Perusahaan",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Order",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Deskripsi",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Parent ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "UOM",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Weight",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Tipe Data",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        },
        {
            name: "Status",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[10] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }
        ]
        const data = [
            ["", "1", "KPI", "TIA", "1", "Financial Perspective", "0", "-", "35%", "Formula", "Aktif"],
            ["", "2", "KPI", "TIA", "2", "Trading Profit", "1", "Rp Bio", "35%", "Formula", "Aktif"],
            ["", "3", "KPI", "TIA", "3", "Revenue", "1", "Rp Bio", "0%", "Formula", "Aktif"],
            ["", "4", "KPI", "TIA", "4", "EBITDA", "1", "Rp Bio", "0%", "Formula", "Non Aktif"],
            ["", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"],
        ]

        return (
            <div style={{ height: this.props.height }}>
                {/* <Row> */}
                <div className={"main-color"} style={{ height: 199, width: '100%' }} />
                {this.state.itemReport === true ?
                    <div>
                        <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -150 }}>
                            <label style={{ color: 'white', fontSize: 16, alignSelf: 'center', width: '20%', }}>Master Data - Item Report</label>
                            <div style={{ color: 'white', width: '50%', height: 37, display: 'flex', backgroundColor: 'white', borderWidth: 2, alignItems: 'center', borderRadius: 6, paddingLeft: 5, paddingRight: 5, alignSelf: 'center' }}>
                                <img src={Images.searchBlack} style={{ marginRight: 10 }} />
                                <InputBase
                                    style={{ width: '100%' }}
                                    placeholder="Search"
                                    value={this.state.search}
                                    onChange={(e) => this.handleInputChange(e.target.value)}
                                    inputProps={{ 'aria-label': 'naked' }}
                                />
                            </div>
                            <div style={{ width: '30%', justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
                                <a data-tip={'Download Template'} data-for="template">
                                    <button
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            margin: 5
                                        }}
                                        onClick={() => this.downloadFile()}
                                    >
                                        <img src={Images.template} />
                                    </button>
                                </a>
                                <ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" />
                                <a data-tip={'Upload'} data-for="upload">
                                    <button
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            margin: 5
                                        }}
                                        onClick={() => null}
                                    >
                                        <img src={Images.upload} onClick={() => this.setState({ visibleUpload: true })} />
                                    </button>
                                </a>
                                <ReactTooltip border={true} id="upload" place="bottom" type="light" effect="solid" />
                                <a data-tip={'Download'} data-for="download">
                                    <button
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            margin: 5
                                        }}
                                        onClick={() => this.downloadDataTable()}
                                    >
                                        <img src={Images.download} />
                                    </button>
                                </a>
                                <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                <a data-tip={'Visualisasi'} data-for="visualisasi">
                                    <button
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            margin: 5
                                        }}
                                        onClick={() => this.setState({ visualisasi: true, itemReport: false })}
                                    >
                                        <img src={Images.visualisasi} />
                                    </button>
                                </a>
                                <ReactTooltip border={true} id="visualisasi" place="bottom" type="light" effect="solid" />
                                <a data-tip={'Tambah'} data-for="tambah">
                                    <button
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            margin: 5
                                        }}
                                    >
                                        <img src={Images.add} onClick={() => this.setState({ add: true })} />
                                    </button>
                                </a>
                                <ReactTooltip border={true} id="tambah" place="bottom" type="light" effect="solid" />

                            </div>
                        </div>
                        <div style={{ padding: 25 }}>
                            <MuiThemeProvider theme={getMuiTheme()}>
                                <MUIDataTable
                                    theme={getMuiTheme()}
                                    data={this.state.dataTable}
                                    columns={columns}
                                    options={options}
                                />
                            </MuiThemeProvider>
                        </div>
                    </div>
                    :
                    this.state.visualisasi == true ?
                        <VisualReportItems
                            onClickClose={() => this.setState({ visualisasi: false, itemReport: true })}
                            height={this.props.height}
                        />
                        :
                        <div style={{ height: this.props.height }}>
                            <div style={{ height: 199, width: '100%' }} className={"main-color"} />
                            <div>
                                <div>
                                    <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -150 }}>
                                        <label style={{ color: 'white', fontSize: 16, alignSelf: 'center' }}>Preview Data</label>
                                    </div>
                                    <div style={{ padding: 25 }}>
                                        {this.state.dataLoaded && (
                                            <MuiThemeProvider theme={getMuiTheme()}>
                                                <MUIDataTable
                                                    theme={getMuiTheme()}
                                                    data={this.state.rows}
                                                    columns={this.state.cols}
                                                    options={options}
                                                />
                                            </MuiThemeProvider>
                                        )}
                                    </div>
                                    <div style={{ display: 'flex', width: '100%', placeContent: 'flex-end', padding: 20 }}>
                                        <button
                                            type="button"
                                            onClick={() => this.setState({ itemReport: true })}
                                            style={{ marginRight: 20 }}
                                        >
                                            <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                                <span style={{ color: '#354960', fontSize: 11 }}>Batal</span>
                                            </div>
                                        </button>
                                        <button
                                            type="button"
                                            onClick={() => this.state.buttonError ? this.setState({ popupError: true }) : this.uploadReportItems()}
                                            style={{}}
                                        >
                                            <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                                <span style={{ color: '#fff', fontSize: 11 }}>Simpan</span>
                                            </div>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                }
                {this.state.add && (
                    <CreateReportItems
                        onClickClose={() => this.setState({ add: false })}
                        data={this.state.listData}
                        refresh={this.getData.bind(this)}
                        createReportItems={this.createReportItems.bind(this)}
                    />
                )}
                {this.state.edit && (
                    <EditReportItems
                        onClickClose={() => this.setState({ edit: false })}
                        data={this.state.rowData}
                        refresh={this.getData.bind(this)}
                        updateReportItems={this.updateReportItems.bind(this)}
                    />
                )}
                {this.state.popupError && (
                    <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
                )}
                {this.state.visibleUpload && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
                                <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                                    <div className="popup-title">
                                        <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Upload File</span>
                                    </div>
                                </div>
                                <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        className="btn btn-circle btn-white"
                                        onClick={() => this.setState({ visibleUpload: false })}
                                    >
                                        <img src={Images.close} />
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
                                acceptedFiles={["xlsx"]}
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
                                onUpload={() => this.setState({ visibleUpload: false, itemReport: false })}
                            />
                        </div>
                    </div>
                )}
            </div>
        );
    }
}
