import React, { Component } from 'react';
import { Typography, Paper, createMuiTheme, ThemeProvider, MuiThemeProvider, TableCell, FormControlLabel, TextField, Input, withStyles, makeStyles, Snackbar } from '@material-ui/core';
import MUIDataTable from 'mui-datatables';
import NumberFormat from 'react-number-format';
import api from '../../api';
import AddIcon from '@material-ui/icons/Add';
import { values } from 'ramda';
import PropagateLoader from "react-spinners/PropagateLoader"
import Images from '../../assets/Images';
import ReactTooltip from 'react-tooltip';
import Tooltip from '@material-ui/core/Tooltip';
import { titleCase } from '../../library/Utils';
import Constant from '../../library/Constant';
import { Alert, Autocomplete } from '@material-ui/lab';
import UploadFile from "../../library/Upload";
import { ExcelRenderer } from 'react-excel-renderer';

const LightTooltip = withStyles((theme) => ({
  tooltip: {
    backgroundColor: theme.palette.common.white,
    color: 'rgba(0, 0, 0, 0.87)',
    boxShadow: theme.shadows[1],
    fontSize: 11,
  },
}))(Tooltip);
var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable3());

const options = ct.customOptionsFixedColumn();
const style = {
    position: "sticky",
    left: 0,
    background: "white",
    zIndex: 101,
};
const style2 = {
    position: "sticky",
    background: "white",
    zIndex: 100
};

const theme = createMuiTheme({
    overrides: {
      // Style sheet name ⚛️
      MuiInputBase: {
          input: {
              color: '#5198ea'
          }
      }
    },
  });

export default class CorporateAnnualTarget extends Component {
    constructor(props) {
        super(props)
        this.state = {
            dataTable: [
                // ["FINANCIAL PERSPECTIVE", "9,884,181", "9,884,181", "9,884,181", "9,884,181", "9,884,181", "9,884,181", "9,884,181", "9,884,181", "9,884,181", "9,884,181"],
                // ["Control", "-", "-"],
                // ["Accumulated Depreciation (negative value)", "2,647,647", "2,058,898"],
                // ["Control", "-", "-"],
                // ["Gain / (Loss) on Fixed Assets", "-", "-"],
                // ["Control", "-", "-"]
            ],
            loading: false,
            uomList: [],
            formulaYtdList: {
                options: [{value: 'SUM'}, {value: 'AVG'}, {value: 'LAST'}],
                getOptionLabel: (option) => titleCase(option.value),
            },
            kpiTypeList: [],
            maxAchList: [],
            visibleCAT: true,
            buttonError: true,
            // formulaYTDList: null,,
            dataDelete: [],
            dataReal: []
        }
        this.fileHandler = this.fileHandler.bind(this);

    }

    componentDidMount() {
        this.getItemHierarki()
        console.log(this.props);
        this.getKPIType(
        this.getMaxAch()
        )
    }

    getItemHierarki() {
        this.setState({ loading: true })
        let payload = {
            "report_id": this.props.report_id,
            "revision": Number(this.props.revision),
            "periode": this.props.periode,
            "company_id": this.props.company.company_id,
            "submission_id": this.props.submissionID
        }
        console.log(JSON.stringify(payload))
        api.create().getDetailReportMB(payload).then(response => {
            let dataTable = []
            console.log(response)
            let res = response.data.data
            const handlePushChild = (item) => {
                let indexIDzz = dataTable.findIndex((val) => val[1] === item.id)
                if (indexIDzz === -1) {
                    dataTable.push([
                        item.type_report_id,
                        item.id,
                        item.parent,
                        item.formula,
                        item.level,
                        "",
                        item.description,
                        item.type_report_id == 1? `${Number(item.weight) * 100}%` : item.cat.weight,
                        item.cat.uom,
                        item.cat.kpi_type == "" ? null : {value: item.cat.kpi_type},
                        item.cat.max_ach == "" ? null : {value: item.cat.max_ach},
                        item.cat.formula == "" ? null : {value: item.cat.formula},
                        item.cat.total_actual_before,
                        item.cat.january,
                        item.cat.february,
                        item.cat.march,
                        item.cat.april,
                        item.cat.may,
                        item.cat.june,
                        item.cat.july,
                        item.cat.august,
                        item.cat.september,
                        item.cat.october,
                        item.cat.november,
                        item.cat.december,
                        item.cat.total_current_year,
                        item.cat.total_next_year,
                        item.cat.total_more_year,
                        item.cat.strategic,
                        item.cat.pic
                    ])
                }
                if (item.children !== null) {
                    if (item.children.length > 0) {
                        item.children.map((items,indexs) => {
                            handlePushChild(items)
                        })
                    }
                }
            }
            res.map((item,index) => {
                dataTable.push([
                    item.type_report_id,
                    item.id,
                    item.parent,
                    item.formula,
                    item.level,
                    "",
                    item.description,
                    item.type_report_id == 1? `${Number(item.weight) * 100}%` : item.cat.weight,
                    item.cat.uom,
                    item.cat.kpi_type == "" ? null : {value: item.cat.kpi_type},
                    item.cat.max_ach == "" ? null : {value: item.cat.max_ach},
                    item.cat.formula == "" ? null : {value: item.cat.formula},
                    item.cat.total_actual_before,
                    item.cat.january,
                    item.cat.february,
                    item.cat.march,
                    item.cat.april,
                    item.cat.may,
                    item.cat.june,
                    item.cat.july,
                    item.cat.august,
                    item.cat.september,
                    item.cat.october,
                    item.cat.november,
                    item.cat.december,
                    item.cat.total_current_year,
                    item.cat.total_next_year,
                    item.cat.total_more_year,
                    item.cat.strategic,
                    item.cat.pic
                ])
                if (item.children !== null) {
                    if (item.children.length > 0) {
                        item.children.map((items,indexs) => {
                            handlePushChild(items)
                        })
                    }
                }
            })
            this.setState({dataTable, loading: false, dataReal: res})
        })
    }

    downloadTemplate = async () => {
        let res = await fetch(
            `https://tia.eksad.com/tia-reporting-dev/public/transaction/master_budget/download_template?report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}`
        )
        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 Master Budget CAT.xlsx';
            a.click();
        }
    }

    async downloadAllData() {
        console.log('masuk')
        let bram = [this.props.submissionID,this.props.report_id,this.props.company.company_id,this.props.periode,this.props.revision]
        console.log(bram)
        let res = await fetch(
            `https://tia.eksad.com/tia-reporting-dev/public/transaction/master_budget/export_master_budget?submission_id=${this.props.submissionID}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}`
        )
        
        res = await res.blob()
        console.log(res)
        this.setState({ loading: false })
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
            a.download = 'CAT.xlsx';
            a.click();
        }
    }

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
            // console.log(resp)
            if (err) {
                console.log(err);
            }
            else {
                let isi = resp.rows.slice(3)
                console.log(isi);
                let payload = []
                let reg = /^\d+$/;
                isi.map((i, index) => {
                    if (i.length > 0) {
                        payload.push({
                            item_report_id: i[0] === undefined ? "0" : reg.test(String(i[0])) === false ? "0" : String(i[0]).trim(),
                            item_report: i[1] === undefined ? "" : String(i[1]).trim(),
                            weight: i[2] === undefined ? "0" : reg.test(String(i[2])) === false ? "0" : String(i[2]).trim(),
                            uom: i[3] === undefined ? "0" : reg.test(String(i[3])) === false ? "0" : String(i[3]).trim(),
                            kpi_type: i[4] === undefined ? "" : reg.test(String(i[4])) === false ? "0" : String(i[4]).trim(),
                            formula: i[5] === undefined ? "" : reg.test(String(i[5])) === false ? "0" : String(i[5]).trim(),
                            total_actual_before: i[6] === undefined ? "0" : reg.test(String(i[6])) === false ? "0" : String(i[6]).trim(),
                            january: i[7] === undefined ? "0" : reg.test(String(i[7])) === false ? "0" : String(i[7]).trim(),
                            february: i[8] === undefined ? "0" : reg.test(String(i[8])) === false ? "0" : String(i[8]).trim(),
                            march: i[9] === undefined ? "0" : reg.test(String(i[9])) === false ? "0" : String(i[9]).trim(),
                            april: i[10] === undefined ? "0" : reg.test(String(i[10])) === false ? "0" : String(i[10]).trim(),
                            may: i[11] === undefined ? "0" : reg.test(String(i[11])) === false ? "0" : String(i[11]).trim(),
                            june: i[12] === undefined ? "0" : reg.test(String(i[12])) === false ? "0" : String(i[12]).trim(),
                            july: i[13] === undefined ? "0" : reg.test(String(i[13])) === false ? "0" : String(i[13]).trim(),
                            august: i[14] === undefined ? "0" : reg.test(String(i[14])) === false ? "0" : String(i[14]).trim(),
                            september: i[15] === undefined ? "0" : reg.test(String(i[15])) === false ? "0" : String(i[15]).trim(),
                            october: i[16] === undefined ? "0" : reg.test(String(i[16])) === false ? "0" : String(i[16]).trim(),
                            november: i[17] === undefined ? "0" : reg.test(String(i[17])) === false ? "0" : String(i[17]).trim(),
                            december: i[18] === undefined ? "0" : reg.test(String(i[18])) === false ? "0" : String(i[18]).trim(),
                            total_current_year: i[19] === undefined ? "0" : reg.test(String(i[19])) === false ? "0" : String(i[19]).trim(),
                            total_next_year: i[20] === undefined ? "0" : reg.test(String(i[20])) === false ? "0" : String(i[20]).trim(),
                            total_more_year: i[21] === undefined ? "0" : reg.test(String(i[21])) === false ? "0" : String(i[21]).trim(),
                            strategic: i[22] === undefined ? "0" : reg.test(String(i[22])) === false ? "0" : String(i[22]).trim(),
                            pic: i[23] === undefined ? "0" : reg.test(String(i[23])) === false ? "0" : String(i[23]).trim()
                        })
                    }
                })
                let body = {
                    company_id: this.props.company.company_id,
                    periode: this.props.periode,
                    report_id: this.props.report_id,
                    cat: payload
                }
                console.log(body)
                this.setState({ payload: body, judul: resp.rows[1][0] })
            }
        });
    }

    checkUpload() {
        api.create().checkUploadMB(this.state.payload).then(response => {
            // console.log(JSON.stringify(this.state.payload));
            console.log(response)
            if (response.data) {
                if (response.data.status === 'success') {
                    // this.setState({ visibleUpload: false, visibleCAT: false })
                    this.setState({ visibleUpload: false, visibleCAT: false, loading: true })
                    let dataTable = response.data.data.map((item, index) => {
                        return [
                            item.type_report_id,
                            item.item_report_id,
                            item.parent,
                            item.formula,
                            item.level,
                            "",
                            item.item_report,
                            item.weight,
                            item.uom,
                            item.kpi_type == "" ? null : item.kpi_type,
                            item.max_ach == "" ? null : item.max_ach,
                            item.formula == "" ? null : item.formula,
                            item.total_actual_before,
                            item.january,
                            item.february,
                            item.march,
                            item.april,
                            item.may,
                            item.june,
                            item.july,
                            item.august,
                            item.september,
                            item.october,
                            item.november,
                            item.december,
                            item.total_current_year,
                            item.total_next_year,
                            item.total_more_year,
                            item.strategic,
                            item.pic,
                            item.error
                        ]
                    })
                    console.log(dataTable)
                    console.log(this.state.buttonError)
                    this.setState({ dataTable, dataLoaded: true, loading: false, buttonError: false }, () => {
                        this.state.dataTable.map(item => {
                            if (item[30].length > 0) {
                                console.log('masuk')
                                this.setState({ buttonError: true, errorPreview: true })
                            }
                        })
                        // console.log(this.state.dataTable);
                    })
                }
            }
        })
    }

    uploadCAT() {
        let data = []
        console.log(this.state.dataTable)
        this.state.dataTable.map(i => {
            data.push({
                "item_report_id": i[0],
                "item_report": String(i[6]),
                "weight": String(i[7]),
                "uom": String(i[8]),
                "kpi_type": i[9] == null? "" : i[9].value,
                "max_ach": i[10] == null? "" : i[10].value,
                "formula": i[11] == null? "" : i[11].value,
                "total_actual_before": String(i[12]),
                "january": String(i[13]),
                "february": String(i[14]),
                "march": String(i[15]),
                "april": String(i[16]),
                "may": String(i[17]),
                "june": String(i[18]),
                "july": String(i[19]),
                "august": String(i[20]),
                "september": String(i[21]),
                "october": String(i[22]),
                "november": String(i[23]),
                "december": String(i[24]),
                "total_current_year": String(i[25]),
                "total_next_year": String(i[26]),
                "total_more_year": String(i[27]),
                "strategic": String(i[28]),
                "pic": String(i[29])
            })
        })
        let body = {
            "report_id": this.props.report_id,
            // "revision": Number(this.props.revision),
            "periode": this.props.periode,
            "company_id": this.props.company.company_id,
            "submission_id": this.props.submissionID,
            // "status": "submitted",
            "cat": data
        }
        console.log(data);
        api.create('UPLOAD').uploadMasterBudget(body).then(response => {
            console.log(response);
            if (response.data) {
                if (response.data.status === "success") {
                    this.props.onClickClose()
                    this.props.getReport()
                } else {
                    alert(response.data.status)
                }
            } else {
                alert(response.problem)
            }
        })
    }

    handleValidate() {
        let data = []
        console.log(this.state.dataTable)
        this.state.dataTable.map(i => {
            // console.log(i[9] == null? "" : i[9].value)
            data.push({
                "item_report_id": i[1],
                "item_name": i[1] !== ""? null : String(i[6]),
                "parent": i[1] !== ""? null : i[2],
                "weight": String(i[7]),
                "uom": String(i[8]),
                "kpi_type": i[9] == null? "" : i[9].value,
                "max_ach": i[10] == null? "" : i[10].value,
                "formula": i[11] == null? "" : i[11].value,
                "total_actual_before": String(i[12]),
                "january": String(i[13]),
                "february": String(i[14]),
                "march": String(i[15]),
                "april": String(i[16]),
                "may": String(i[17]),
                "june": String(i[18]),
                "july": String(i[19]),
                "august": String(i[20]),
                "september": String(i[21]),
                "october": String(i[22]),
                "november": String(i[23]),
                "december": String(i[24]),
                "total_current_year": String(i[25]),
                "total_next_year": String(i[26]),
                "total_more_year": String(i[27]),
                "strategic": String(i[28]),
                "pic": String(i[29])
            })
        })
        console.log(JSON.stringify(data))
        let payload = {
            "submission_id": this.props.submissionID,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": this.props.report_id,
            "status": "submitted",
            "cat": data
        }
        let totalWeight = 0
        this.state.dataTable.map((items,indexs) => {
            if (items[0] == 3) {
                console.log(items[7])
                totalWeight += Number(items[7].replace('%', ''))
            }
        })
        console.log(totalWeight)
        if (totalWeight < 100) {
            this.setState({ alert: true, messageAlert: 'Total weight less than 100%', tipeAlert: 'warning', loading: false, buttonError: true, editable: true }) 
        } else {
            api.create().validateSubmitReport(payload).then((response) => {
                console.log(response)
                if (response.data.data.result) {
                    this.setState({ loading: false, buttonError: false, editable: true })
                } else {
                    this.setState({ loading: false, buttonError: true, editable: true })
                } 
            })
        }
    }

    closeAlert() {
        this.setState({ alert: false })
    }

    backToMasterBudget(type) {
        let data = []
        console.log(this.state.dataTable)
        this.state.dataTable.map(i => {
            // console.log(i[9] == null? "" : i[9].value)
            data.push({
                "item_report_id": i[1],
                "item_name": i[1] !== ""? null : String(i[6]),
                "parent": i[1] !== ""? null : i[2],
                "weight": String(i[7]),
                "uom": String(i[8]),
                "kpi_type": i[9] == null? "" : i[9].value,
                "max_ach": i[10] == null? "" : i[10].value,
                "formula": i[11] == null? "" : i[11].value,
                "total_actual_before": String(i[12]),
                "january": String(i[13]),
                "february": String(i[14]),
                "march": String(i[15]),
                "april": String(i[16]),
                "may": String(i[17]),
                "june": String(i[18]),
                "july": String(i[19]),
                "august": String(i[20]),
                "september": String(i[21]),
                "october": String(i[22]),
                "november": String(i[23]),
                "december": String(i[24]),
                "total_current_year": String(i[25]),
                "total_next_year": String(i[26]),
                "total_more_year": String(i[27]),
                "strategic": String(i[28]),
                "pic": String(i[29])
            })
        })
        console.log(JSON.stringify(data))
        let payload = {
            "submission_id": this.props.submissionID,
            "company_id": this.props.company.company_id,
            "periode": this.props.periode,
            "report_id": this.props.report_id,
            "status": type,
            "cat": data
        }
        console.log(JSON.stringify(payload));
        this.deleteReport(payload)
    }

    deleteReport(payloadBro) {
        let payload = {"item_report_id": this.state.dataDelete}
        
        if (this.state.dataDelete.length > 0) {
            api.create().deleteAllItemReport(payload).then((response) => {
                console.log(response)

                // api.create().validateSubmitReport(payloadBro).then((response) => {
                //     console.log(response)
                //     if (response.data.data.result) {
                        this.props.saveToMasterBudget(payloadBro)
                        this.props.onClickClose()
                //     } else {
                        
                //     }
                // })
            })
        } else {
            // api.create().validateSubmitReport(payloadBro).then((response) => {
            //     console.log(response)
            //     if (response.data.data.result) {
                    this.props.saveToMasterBudget(payloadBro)
                    this.props.onClickClose()
            //     } else {

            //     }
            // })
        }
    }


    getKPIType() {
        let body = {
            group: 'CAT',
            company_id: this.props.company.company_id,
            type: 'KPI_TYPE'
        }
        api.create().getAllSettingByType(body).then(response => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        let data = response.data.data
                        console.log(data)
                        let inputKPI = data.map((item) => {
                            return {
                                value: item.value
                            }
                        })
                        let defaultProps = {
                            options: inputKPI,
                            getOptionLabel: (option) => titleCase(option.value),
                        };
                        this.setState({ kpiTypeList: defaultProps })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                        // alert(response.data.message)
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }
        })
    }

    getMaxAch() {
        let body = {
            group: 'CAT',
            company_id: this.props.company.company_id,
            type: 'MAX_ACHIEVEMENT'
        }
        api.create().getAllSettingByType(body).then(response => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        let data = response.data.data
                        let inputMaxAch = data.map((item) => {
                            return {
                                value: item.value
                            }
                        })
                        let defaultProps = {
                            options: inputMaxAch,
                            getOptionLabel: (option) => titleCase(option.value),
                        };
                        this.setState({ maxAchList: defaultProps })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
                            if (response.data.message.includes("Someone Logged In")) {
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                        // alert(response.data.message)
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }
        })
    }

    render() {
        let dataTable2 = this.state.dataTable
        let dataDelete = this.state.dataDelete
        const handleChange = (value, tableMeta) => {
            let val = String(value).split(",").join("")
            let total = 0
            let lastValz = 0
            dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val)
            dataTable2[tableMeta.rowIndex].map((item,index) => {
                if (index >= 13 && index <= 24) {
                    let valItem = item == undefined || item == ""? 0 : item
                    total += Number(valItem)
                    if (index == 24) {
                        lastValz += Number(valItem)
                    }
                }
            })
            let valz = dataTable2[tableMeta.rowIndex][11] == null? 'SUM' : dataTable2[tableMeta.rowIndex][11].value
            dataTable2[tableMeta.rowIndex][25] = (valz == 'SUM'? total : (valz == 'AVG'? (total / 12) : lastValz)) 
            console.log(dataTable2[tableMeta.rowIndex])
        }

        const handleChangeDropdown = (value, tableMeta) => {
            dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = value
            let valz = value.value
            let total = 0
            let lastValz = 0
            if (valz == 'SUM' || valz == 'AVG' || valz == 'LAST') {
                dataTable2[tableMeta.rowIndex].map((item,index) => {
                    if (index >= 13 && index <= 24) {
                        let valItem = item == undefined || item == ""? 0 : item
                        total += Number(valItem)
                        if (index == 24) {
                            lastValz += Number(valItem)
                        }
                    }
                })
                dataTable2[tableMeta.rowIndex][25] = (valz == 'SUM'? total : (valz == 'AVG'? (total / 12) : lastValz)) 
            }
        }

        const handleChangePercentage = (value, tableMeta) => {
            let valueReal = value.replace('%', '')
            let indexParentDatatable = dataTable2.findIndex((val) => val[1] == tableMeta.rowData[2])
            let indexParentReal = this.state.dataReal.findIndex((val) => val.id == tableMeta.rowData[2])
            // console.log(indexParentDatatable)
            // console.log(indexParentReal)
            let valParent = dataTable2[indexParentDatatable][7]
            valParent.replace('%', '')
            let valChild = 0
            
            dataTable2.map((item,index) => {
                if(item[2] == dataTable2[indexParentDatatable][1] && item[1] !== tableMeta.rowData[1]) {
                    let weightItem = item[7] == ""? 0 : item[7].replace('%', '')
                    console.log(weightItem)
                    valChild += Number(weightItem)
                }
            })

            let endVal = ''
            // console.log(Number(valueReal) + Number(valChild))
            // console.log(valueReal)
            // console.log(Number(valParent.replace('%', '')))
            if ((Number(valueReal) + Number(valChild)) > Number(valParent.replace('%', ''))) {
                endVal = `${Number(valParent.replace('%', '')) - (Number(valChild))}%`
                console.log(endVal)
            } else {
                endVal = `${Number(valueReal)}%`
                console.log(endVal)
            }
            // console.log(endVal)
            dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = endVal
        }

        const handleChangeText = (value, tableMeta) => {
            console.log(value)
            dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = value
            // this.setState({dataTable: dataTable2})
        }
        
        const handleAction = (idParent) => {
            if (idParent !== null) {
                let indexsss = dataTable2.findIndex((val) => val[1] == idParent)
                if (dataTable2[indexsss][6] == 'CUSTOMER PERSPECTIVE' || dataTable2[indexsss][6] == 'INTERNAL PERSPECTIVE') {
                    return true
                } else {
                    return false
                }
            } else {
                return false
            }
        }

        const handleTambah = (data, rowIndex) => {
            console.log(dataTable2)
            let newData = []
            dataTable2.map((item, index) => {
                newData.push(item)
                if (index == rowIndex) {
                    newData.push([
                        3,
                        "",
                        item[2],
                        item[3],
                        item[4],
                        "",
                        "",
                        "",
                        "",
                        null,
                        null,
                        null,
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        ""
                    ])
                    
                }
            })
            dataTable2 = newData
            this.setState({dataTable: dataTable2}, () => {
                setTimeout(() => {
                    this.setState({loading: false})
                }, 500)  
            })
        }

        const handleDelete = (index) => {
            if (dataTable2[index][1] !== "") {
                dataDelete.push(dataTable2[index][1])
            }
            dataTable2.splice(index, 1)
            this.setState({dataTable: dataTable2, dataDelete}, () => {
                setTimeout(() => {
                    this.setState({loading: false})
                }, 500)  
            })
        }

        const columns = [{
            name: "",
            options: {
                display: false
            }
        }, {
            name: "",
            options: {
                display: false
            }
        }, {
            name: "",
            options: {
                display: false
            }
        }, {
            name: "",
            options: {
                display: false
            }
        }, {
            name: "",
            options: {
                display: false
            }
        }, {
            name: "",
            options: {
              filter: false,
              display: this.state.visibleCAT,
              customHeadRender: (columnMeta) => (
                <TableCell key={columnMeta.index} style={{ ...style, top: 0, zIndex: 102, backgroundColor: '#dbdbdb'}}>
                    <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'left' }}>{columnMeta.name}</Typography>
                </TableCell>
                ),
              customBodyRender: (val, tableMeta) => {
                return (
                // handleAction(tableMeta.rowData[2]) && 
                handleAction(tableMeta.rowData[2]) && <div style={{ display: 'flex' }}>
                    {/* {tableMeta.rowData[6] === "Active" ? */}
                      {<span>
                        <LightTooltip title={'Add'} arrow>
                          <button
                            style={{
                              backgroundColor: 'transparent',
                              cursor: 'pointer',
                              borderColor: 'transparent',
                            }}
                            // onClick={() => console.log(tableMeta.rowData[1])}
                            onClick={() => {
                                this.setState({loading: true})
                                handleTambah(tableMeta.rowData[1],tableMeta.rowIndex)
                            }}
                          >
                            <img src={Images.add} />
                          </button>
                        </LightTooltip>
                      </span>}
                      <span>
                        <LightTooltip title={'Delete'} arrow>
                          <button
                              style={{
                                  backgroundColor: 'transparent',
                                  cursor: 'pointer',
                                  borderColor: 'transparent',
                                  marginLeft: 5
                              }}
                              onClick={() => {
                                this.setState({loading: true})
                                handleDelete(tableMeta.rowIndex)
                            }}
                          >
                              <img src={Images.delete} />
                          </button>
                        </LightTooltip>
                      </span>
                  </div >
                );
              }
            }
          }, {
            name: "Key Performance Indicator",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell key={columnMeta.index} style={{ ...style, top: 0, zIndex: 102, backgroundColor: '#1c71b8'}}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'left' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                setCellProps: () => ({ style }),
                customBodyRender: (val, tableMeta) => {
                    return (
                        tableMeta.rowData[1] == "" ? 
                        <div style={{ textAlign: 'left', paddingLeft: 20 * Number(tableMeta.rowData[4]) }}>
                            <FormControlLabel
                                style={{ margin: 0 }}
                                control={
                                    <Input
                                        disableUnderline={true}
                                        style={{ color: tableMeta.rowData[1] == "" ? "#5198ea" : "black", fontSize: 12, textAlign: 'left', borderColor: 'transparent', margin: 0, backgroundColor: 'transparent' }}
                                        type="text"
                                        placeholder=""
                                        defaultValue={val}
                                        // disabled={!handleAction(tableMeta.rowData[2])}
                                        onBlur={(event) => {
                                            console.log(event.target.value)
                                            handleChangeText(event.target.value, tableMeta)
                                            console.log(dataTable2)
                                        }}
                                    />
                                }
                            />
                        </div>
                        :
                        <div style={{ width: 300 }}>
                            {tableMeta.rowData[22] ?
                                tableMeta.rowData[22].length > 0 ?
                                    tableMeta.rowData[22][0].field === 'item' ?
                                        tableMeta.rowData[4] == 0 ?
                                            <a data-tip={tableMeta.rowData[22][0].message} data-for="account">
                                                <span style={{ fontSize: 12, fontWeight: 'bold', color: 'red' }}>{String(tableMeta.rowData[0] === 4 ? "" : val).toUpperCase()}</span>
                                            </a>
                                            :
                                            <div style={{ paddingLeft: 20 * Number(tableMeta.rowData[4]) }}>
                                                <a data-tip={tableMeta.rowData[22][0].message} data-for="account">
                                                    <span style={{ fontSize: 12, color: 'red' }}>{tableMeta.rowData[0] === 4 ? "" : val}</span>
                                                </a>
                                            </div>
                                        :
                                        tableMeta.rowData[4] == 0 ?
                                            <span style={{ fontSize: 12, fontWeight: 'bold' }}>{String(tableMeta.rowData[0] === 4 ? "" : val).toUpperCase()}</span>
                                            :
                                            <div style={{ paddingLeft: 20 * Number(tableMeta.rowData[4]) }}>
                                                <span style={{ fontSize: 12 }}>{tableMeta.rowData[0] === 4 ? "" : val}</span>
                                            </div>
                                    :
                                    tableMeta.rowData[4] == 0 ?
                                        <span style={{ fontSize: 12, fontWeight: 'bold' }}>{String(tableMeta.rowData[0] === 4 ? "" : val).toUpperCase()}</span>
                                        :
                                        <div style={{ paddingLeft: 20 * Number(tableMeta.rowData[4]) }}>
                                            <span style={{ fontSize: 12 }}>{tableMeta.rowData[0] === 4 ? "" : val}</span>
                                        </div>
                                :
                                tableMeta.rowData[4] == 0 ?
                                    <span style={{ fontSize: 12, fontWeight: 'bold' }}>{String(tableMeta.rowData[0] === 4 ? "" : val).toUpperCase()}</span>
                                    :
                                    <div style={{ paddingLeft: 20 * Number(tableMeta.rowData[4]) }}>
                                        <span style={{ fontSize: 12 }}>{tableMeta.rowData[0] === 4 ? "" : val}</span>
                                    </div>
                            }
                            <ReactTooltip border={true} id="account" place="bottom" type="light" effect="solid" />
                        </div>
                    )
                }
            }
        }, {
            name: "Weight",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                setCellProps: () => ({ style2 }),
                customBodyRender: (value, tableMeta, updateValue) => {
                    return (
                        <div style={{ textAlign: 'right' }}>
                            {tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null :
                                    tableMeta.rowData[0] === 1 ? 
                                    value
                                    :
                                    <div style={{ flex: 1 }}>
                                        <FormControlLabel
                                            style={{ margin: 0 }}
                                            value={value}
                                            control={
                                                <NumberFormat
                                                    thousandSeparator={true}
                                                    suffix="%"
                                                    style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                    type="text"
                                                    placeholder=""
                                                    value={value}
                                                    maxLength={4}
                                                    onBlur={(event) => {
                                                        // updateValue(some)
                                                        handleChangePercentage(event.target.value, tableMeta)
                                                    }}
                                                />
                                            }
                                        />
                                    </div>
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "UOM",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8'}}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta, updateValue) => {
                    return (
                        <div style={{ textAlign: 'right' }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null :
                                <FormControlLabel
                                    style={{ margin: 0 }}
                                    // value={value}
                                    control={
                                        !handleAction(tableMeta.rowData[2])?
                                        <Input
                                            disableUnderline={true}
                                            style={{ fontSize: 12, textAlign: 'center', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent', marginTop: -10 }}
                                            type="text"
                                            placeholder=""
                                            defaultValue={value}
                                            color={"#5198ea"}
                                            disabled={!handleAction(tableMeta.rowData[2])}
                                            onBlur={(event) => {
                                                console.log(event.target.value)
                                                // updateValue(event.target.value)
                                                handleChangeText(event.target.value, tableMeta)
                                                console.log(dataTable2)
                                            }}
                                        /> :
                                        <ThemeProvider theme={theme}>
                                            <Input
                                                disableUnderline={true}
                                                style={{ fontSize: 12, textAlign: 'center', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent', marginBottom: -5 }}
                                                type="text"
                                                placeholder=""
                                                defaultValue={value}
                                                color={"#5198ea"}
                                                disabled={!handleAction(tableMeta.rowData[2])}
                                                onBlur={(event) => {
                                                    console.log(event.target.value)
                                                    // updateValue(event.target.value)
                                                    handleChangeText(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        </ThemeProvider>
                                    }
                                />
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "KPI Type",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null :
                                <Autocomplete
                                    {...this.state.kpiTypeList}
                                    id="kpiType"
                                    onChange={(event, newInputValue) => handleChangeDropdown(newInputValue, tableMeta)}
                                    debug
                                    disableClearable
                                    disabled={!handleAction(tableMeta.rowData[2])}
                                    value={val}
                                    style={{padding: 0, margin: 0}}
                                    renderInput={(params) =>
                                        <div ref={params.InputProps.ref} style={{padding: 0, margin: 0}}>
                                            <input style={{ borderColor: 'white', width: 96, textAlign: 'center', padding: 0, margin: 0, color: handleAction(tableMeta.rowData[2])? "#5198ea" : "black"}} type="text" {...params.inputProps} />
                                        </div>
                                    }
                                />
                            }
                            
                        </div>
                    )
                }
            }
        }, {
            name: "Max Ach.",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null :
                                <Autocomplete
                                {...this.state.maxAchList}
                                id="maxAchList"
                                onChange={(event, newInputValue) => handleChangeDropdown(newInputValue, tableMeta)}
                                debug
                                disableClearable
                                value={val}
                                style={{padding: 0, margin: 0}}
                                disabled={!handleAction(tableMeta.rowData[2])}
                                renderInput={(params) =>
                                    <div ref={params.InputProps.ref} style={{padding: 0, margin: 0}}>
                                        <input style={{ borderColor: 'white', width: 96, textAlign: 'center', padding: 0, margin: 0, color: handleAction(tableMeta.rowData[2])? "#5198ea" : "black"}} type="text" {...params.inputProps} />
                                    </div>
                                }
                                // value={this.state.parent}
                                />
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Formula YTD",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (val, tableMeta, updateValue) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null :
                                <Autocomplete
                                    {...this.state.formulaYtdList}
                                    id="formulaYtdList"
                                    onChange={(event, newInputValue) => {
                                        // updateValue(newInputValue)
                                        handleChangeDropdown(newInputValue, tableMeta)}
                                    }
                                    debug
                                    disableClearable
                                    value={val}
                                    disabled={!handleAction(tableMeta.rowData[2])}
                                    style={{padding: 0, margin: 0}}
                                    renderInput={(params) =>
                                        <div ref={params.InputProps.ref} style={{padding: 0, margin: 0}}>
                                            <input style={{ borderColor: 'white', width: 96, textAlign: 'center', padding: 0, margin: 0, color: handleAction(tableMeta.rowData[2])? "#5198ea" : "black"}} type="text" {...params.inputProps} />
                                        </div>
                                    }
                                    // value={this.state.parent}
                                />
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "2020",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#37b5e6', width: 96 }}>
                    <Typography style={{ color: 'black', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Jan 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Feb 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Mar 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Apr 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "May 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Jun 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Jul 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Aug 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Sep 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Oct 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Nop 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Dec 2021",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "2021 Total",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null : 
                                <FormControlLabel
                                    style={{ margin: 0 }}
                                    value={value}
                                    control={
                                        <NumberFormat
                                            thousandSeparator={true}
                                            style={{ fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                            type="text"
                                            placeholder=""
                                            value={value}
                                            disabled={true}
                                            // onBlur={(event) => {
                                            //     // updateValue(event.target.value)
                                            //     handleChange(event.target.value, tableMeta)
                                            //     console.log(dataTable2)
                                            // }}
                                        />
                                    }
                                />    
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "2022 Total",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "2023 Total",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ width: 96 }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null
                                :
                                <div style={{ flex: 1 }}>
                                    <FormControlLabel
                                        style={{ margin: 0 }}
                                        value={value}
                                        control={
                                            <NumberFormat
                                                thousandSeparator={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }}
                                                type="text"
                                                placeholder=""
                                                value={value}
                                                onBlur={(event) => {
                                                    // updateValue(event.target.value)
                                                    handleChange(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        }
                                    />
                                </div> 
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "Strategic Initiative",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ textAlign: 'right' }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null :
                                <FormControlLabel
                                    style={{ margin: 0 }}
                                    control={
                                        <ThemeProvider theme={theme}>
                                            <Input
                                                disableUnderline={true}
                                                style={{ fontSize: 12, textAlign: 'center', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent', marginBottom: -5 }}
                                                type="text"
                                                placeholder=""
                                                defaultValue={value}
                                                onBlur={(event) => {
                                                    console.log(event.target.value)
                                                    handleChangeText(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        </ThemeProvider>
                                        
                                    }
                                />
                            }
                        </div>
                    )
                }
            }
        }, {
            name: "PIC",
            options: {
                customHeadRender: (columnMeta) => (
                    <TableCell style={{ ...style2, top: 0, zIndex: 99, backgroundColor: '#1c71b8', width: 96 }}>
                        <Typography style={{ color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center' }}>{columnMeta.name}</Typography>
                    </TableCell>
                ),
                customBodyRender: (value, tableMeta) => {
                    return (
                        <div style={{ textAlign: 'right' }}>
                            {tableMeta.rowData[0] === 1 || tableMeta.rowData[0] === 2 || tableMeta.rowData[0] === 4?
                                null :
                                <FormControlLabel
                                    style={{ margin: 0 }}
                                    // value={value}
                                    control={
                                        <ThemeProvider theme={theme}>
                                            <Input
                                                disableUnderline={true}
                                                style={{ color: "#5198ea", fontSize: 12, textAlign: 'center', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent', marginBottom: -5 }}
                                                type="text"
                                                placeholder=""
                                                defaultValue={value}
                                                onBlur={(event) => {
                                                    console.log(event.target.value)
                                                    // updateValue(event.target.value)
                                                    handleChangeText(event.target.value, tableMeta)
                                                    console.log(dataTable2)
                                                }}
                                            />
                                        </ThemeProvider>
                                        
                                    }
                                />
                            }
                        </div>
                    )
                }
            }
        }
        ]
        const loadingComponent = (
            <div style={{ position: 'absolute', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
            </div>
        );

        return (
            <div style={{ height: this.props.height, backgroundColor: '#f8f8f8', marginBottom: 100, minHeight: 1000 }}>
                <div className={"main-color"} style={{ height: 78, flex: 1, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
                    <Typography style={{ fontSize: '16px', color: 'white' }}>Pengajuan Budget Tahunan</Typography>
                </div>
                {/* {this.state.loading && loadingComponent} */}
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
                <div style={{ flex: 1, padding: 20, width: '100%' }}>
                    {this.state.visibleCAT? <Paper style={{ paddingTop: 10, paddingBottom: 20 }}>
                        <div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
                            <Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Master Budget - Corporate Annual Target</Typography>
                        </div>
                        <div style={{ padding: 20 }}>
                            <div style={{ display: 'flex', justifyContent: 'space-between' }}>
                                <div>
                                    <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>{this.props.company.company_name}</Typography>
                                    <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>Period : {this.props.periode} (rev.{this.props.revision})</Typography>
                                    <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>in IDR mn</Typography>
                                </div>
                                <div style={{ width: '50%' }}>
                                    <div style={{ 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.downloadTemplate()}
                                            >
                                                <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={() => this.setState({ visibleUpload: true })}
                                            >
                                                <img src={Images.upload} />
                                            </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.setState({ loading: true }, () => {
                                                    //     setTimeout(() => {
                                                            this.downloadAllData()}
                                                    //     }, 100);
                                                    // })}
                                            >
                                                <img src={Images.download} />
                                            </button>
                                        </a>
                                        <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                    </div>
                                </div>
                            </div>

                            <div style={{ marginTop: 20, width: this.props.width - (this.props.open === true ? 400 : 150) }}>
                                {this.state.loading && loadingComponent}
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        data={dataTable2}
                                        columns={columns}
                                        options={options}
                                    />
                                </MuiThemeProvider>
                            </div>
                        </div>
                        <div className="grid grid-2x">
                            <div className="col-1">
                                <button
                                    className="button"
                                    type="button"
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: 'pointer',
                                        borderColor: 'transparent',
                                    }}
                                    onClick={() => this.backToMasterBudget('draft')}
                                >
                                    <div style={{ backgroundColor: '#019ce5', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                        <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Back</Typography>
                                    </div>
                                </button>
                            </div>
                            <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
                                <button
                                    className="button"
                                    type="button"
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: 'pointer',
                                        borderColor: 'transparent',
                                        outline: 'none',
                                        marginRight: 20
                                    }}
                                    onClick={() => this.setState({ loading: true }, () => {
                                        setTimeout(() => {
                                            this.props.onClickClose()
                                        }, 100);
                                    })}
                                >
                                    <div style={{ backgroundColor: '#fff', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
                                        <Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Cancel</Typography>
                                    </div>
                                </button>
                                <button
                                    className="button"
                                    type="button"
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: 'pointer',
                                        borderColor: 'transparent',
                                        outline: 'none',
                                        marginRight: 20
                                    }}
                                    onClick={() => {
                                        this.setState({ loading: true, dataTable: dataTable2}, () => {
                                            setTimeout(() => {
                                                this.handleValidate()
                                            }, 100);
                                        })
                                    }}
                                >
                                    <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                        <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Calculate</Typography>
                                    </div>
                                </button>
                                <button
                                    type="button"
                                    // disabled={this.state.buttonError}
                                    onClick={() => this.state.buttonError? 
                                        this.setState({ alert: true, messageAlert: 'Data is not complete !', tipeAlert: 'warning' }) 
                                        : this.backToMasterBudget('submitted')}
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: this.state.buttonError === true ? 'default' : 'pointer',
                                        borderColor: 'transparent',
                                        outline: 'none',
                                    }}
                                >
                                    <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                        <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save</Typography>
                                    </div>
                                </button>
                            </div>
                        </div>
                    </Paper>
                    :
                    <Paper style={{ paddingTop: 10, paddingBottom: 20 }}>
                            <div>
                                <div style={{ padding: 25 }}>
                                    <div>
                                        <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>{this.props.company.company_name}</Typography>
                                        <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>Period : {this.props.periode}</Typography>
                                        <Typography style={{ fontSize: '11px', color: '#4b4b4b' }}>in IDR mn</Typography>
                                    </div>
                                    {this.state.dataLoaded && (
                                        <div style={{ marginTop: 20, width: this.props.width - (this.props.open === true ? 400 : 150) }}>
                                            {!this.state.loading && <MuiThemeProvider theme={getMuiTheme()}>
                                                <MUIDataTable
                                                    data={dataTable2}
                                                    columns={columns}
                                                    options={options}
                                                />
                                            </MuiThemeProvider>}
                                        </div>
                                    )}
                                </div>
                                <div style={{ display: 'flex', width: '100%', placeContent: 'flex-end', padding: 20 }}>
                                    <button
                                        type="button"
                                        onClick={() => this.setState({ loading: true, visibleCAT: true }, () => {
                                            setTimeout(() => {
                                                this.getItemHierarki()
                                            }, 100);
                                        })}
                                        style={{ marginRight: 20 }}
                                    >
                                        <div style={{ backgroundColor: '#fff', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center', border: 'solid 1px #354960' }}>
                                            <Typography style={{ fontSize: '11px', color: '#354960', textAlign: 'center' }}>Cancel</Typography>
                                        </div>
                                    </button>
                                    <button
                                        className="button"
                                        type="button"
                                        disabled={this.state.buttonError}
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: this.state.buttonError === true ? 'default' : 'pointer',
                                            borderColor: 'transparent',
                                            outline: 'none',
                                            marginRight: 20
                                        }}
                                        onClick={() => {
                                            this.setState({ loading: true }, () => {
                                                setTimeout(() => {
                                                    this.setState({ loading: false, buttonError: this.state.errorPreview === true ? true : false })
                                                }, 100);
                                            })
                                        }}
                                    >
                                        <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Calculate</Typography>
                                        </div>
                                    </button>
                                    <button
                                        type="button"
                                        disabled={this.state.buttonError}
                                        onClick={() => this.setState({ loading: true }, () => {
                                            setTimeout(() => {
                                                this.uploadCAT()
                                            }, 100);
                                        })}
                                    >
                                        <div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
                                            <Typography style={{ fontSize: '11px', color: '#fff', textAlign: 'center' }}>Save</Typography>
                                        </div>
                                    </button>
                                </div>
                            </div>
                        </Paper>}
                </div>

                {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.state.judul === "MASTER BUDGET - CAT" ?
                                        this.checkUpload() :
                                        this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
                                }}
                            />
                        </div>
                    </div>
                )}
            </div>
        );
    }
}