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

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

export default class Parameter extends Component {
    constructor(props) {
        super(props)
        this.state = {
            visibleCreate: false,
            visibleEdit: false,
            visibleParameter: true,
            popupError: false,
            data: [],
            dataTable: []
        }
        this.fileHandler = this.fileHandler.bind(this);
    }

    componentDidMount() {
        this.getAllParameter()
    }

    getAllParameter() {
        api.create().getAllParameter().then(response => {
            if (response.data.status === "success") {
                console.log(response);
                let data = response.data.data
                let listData = data.map((item, index) => {
                    return [
                        item.setting_id,
                        item.setting_group,
                        item.setting_type,
                        item.company_name,
                        item.description,
                        item.order,
                        item.value,
                        item.min_value,
                        item.max_value,
                        item.status
                    ]
                })
                this.setState({ dataTable: listData, data: response.data.data })
            } else {
                alert(response.data.message)
            }
        })
    }

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

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

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

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

    downloadDataTable = async () => {
        let res = await fetch(
            "https://tia.eksad.com/tia-reporting-dev/public/setting/export_setting"
        )
        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 = 'Parameter.xlsx';
            a.click();
        }
    }

    handleInputChange(e) {
        this.setState({ search: e })
        let body = {
            "keyword": e
        }
        api.create().searchParameter(body).then(response => {
            console.log(response.data);
            if (response.data.status == 'success') {
                let data = response.data.data
                let listData = data.map((item, index) => {
                    return [
                        index,
                        item.setting_group,
                        item.setting_type,
                        item.company_name,
                        item.description,
                        item.order,
                        item.value,
                        item.min_value,
                        item.max_value,
                        item.status
                    ]
                })
                this.setState({ dataTable: listData, listData: response.data.data })
            } else {
                alert(response.data.message)
            }
        })
    }

    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
            // console.log(resp)
            if (err) {
                console.log(err);
            }
            else {
                let judul = resp.rows[2]
                let isi = resp.rows.slice(3)
                let payload = []
                isi.map((item, index) => {
                    if (item.length > 0) {
                        payload.push({
                            id: index + 1,
                            group: item[0],
                            parameter: item[1],
                            company: item[2],
                            description: item[3],
                            orders: item[4],
                            value: item[5],
                            min_value: item[6],
                            max_value: item[7],
                            start_date: item[8],
                            end_date: item[9],
                        })
                    }
                })
                let body = {
                    setting: payload
                }
                this.setState({ payload: body, buttonError: false })
                api.create().checkUploadParameter(body).then(response => {
                    console.log(response);
                    if (response.data !== null) {
                        if (response.data.status === "success") {
                            let dataRow = response.data.data.map((item, index) => {
                                return [
                                    index + 1,
                                    item.group,
                                    item.parameter,
                                    item.company,
                                    item.description,
                                    item.orders,
                                    item.value,
                                    item.min_value,
                                    item.max_value,
                                    item.start_date,
                                    item.end_date,
                                    item.error,
                                ]
                            })
                            let columns = [
                                "Data Ke-",
                                {
                                    name: "Group",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('group'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="group">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="group" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Parameter",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('parameter'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="parameter">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="parameter" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Perusahaan",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('company'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="company">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="company" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Deskripsi",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('description'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="description">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="description" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Order",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('order'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="order">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="order" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Value",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('value'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="value">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="value" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Min Value",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('min_value'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="min_value">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="min_value" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Max Value",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('max_value'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="max_value">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="max_value" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Berlaku Mulai",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('start_date'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="start_date">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="start_date" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "Berlaku Hingga",
                                    options: {
                                        customBodyRender: (val, tableMeta) => {
                                            let check = null
                                            if (tableMeta.rowData[11] != null) {
                                                check = tableMeta.rowData[11].findIndex((val) => val.field.includes('end_date'))
                                                if (check > -1) {
                                                    this.setState({ buttonError: true })
                                                }
                                            }
                                            return (
                                                <div style={{ display: 'flex' }}>
                                                    {tableMeta.rowData[11] != null && check > -1 ?
                                                        <a data-tip={tableMeta.rowData[11][check].message} data-for="enddate">
                                                            <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                        </a> :
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                                                    }
                                                    <ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
                                                </div >
                                            );
                                        }
                                    }
                                },
                                {
                                    name: "",
                                    options: {
                                        display: false
                                    }
                                }
                            ]

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

                })

            }
        });
    }

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

    render() {
        const columns = [{
            name: "Action",
            options: {
                sort: false,
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <button
                                style={{
                                    backgroundColor: 'transparent',
                                    cursor: 'pointer',
                                    borderColor: 'transparent'
                                }}
                                onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
                                // onClick={()=> console.log(tableMeta)}
                            >
                                <img src={Images.editCopy} />
                            </button>
                        </div >
                    );
                }
            }
        }, {
            name: "Group",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }, {
            name: "Parameter",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }, {
            name: "Perusahaan",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }, {
            name: "Deskripsi",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }, {
            name: "Order",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }, {
            name: "Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }, {
            name: "Min Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }, {
            name: "Max Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }, {
            name: "Status",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
                            <span style={{ color: tableMeta.rowData[9] === "Aktif" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
                        </div >
                    );
                }
            }
        }]
        const data = [
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Default", "Range Periode Lap", "1", "-", "1", "10", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Puninar Group", "Range Periode Lap", "2", "-", "1", "15", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "TAP Group", "Range Periode Lap", "3", "-", "1", "15", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Daya Group", "Range Periode Lap", "4", "-", "1", "20", "Non Aktif"],
            ["", "-", "-", "-", "-", "-"]
        ]
        return (
            <div style={{ height: this.props.height }}>
                {/* <Row> */}
                <div className={"main-color"} style={{ height: 199, width: '100%' }} />
                {this.state.visibleParameter === true ?
                    <div>
                        <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -150 }}>
                            <label style={{ color: 'white', fontSize: 16, alignSelf: 'center', width: '20%', }}>Parameter</label>
                            <div style={{ color: 'white', width: '50%', height: 37, display: 'flex', backgroundColor: 'white', borderWidth: 2, alignItems: 'center', borderRadius: 6, paddingLeft: 5, paddingRight: 5, alignSelf: 'center' }}>
                                <img src={Images.searchBlack} style={{ marginRight: 10 }} />
                                <InputBase
                                    style={{ width: '100%' }}
                                    placeholder="Search"
                                    value={this.state.search}
                                    onChange={(e) => this.handleInputChange(e.target.value)}
                                    inputProps={{ 'aria-label': 'naked' }}
                                />
                            </div>
                            <div style={{ width: '30%', justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
                                <a data-tip={'Download Template'} data-for="template">
                                    <button
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            margin: 5
                                        }}
                                        onClick={() => this.downloadFile()}
                                    >
                                        <img src={Images.template} />
                                    </button>
                                </a>
                                <ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" />
                                <a data-tip={'Upload'} data-for="upload">
                                    <button
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            margin: 5
                                        }}
                                        onClick={() => 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.downloadDataTable()}
                                    >
                                        <img src={Images.download} />
                                    </button>
                                </a>
                                <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                <a data-tip={'Tambah'} data-for="create">
                                    <button
                                        style={{
                                            backgroundColor: 'transparent',
                                            cursor: 'pointer',
                                            borderColor: 'transparent',
                                            margin: 5
                                        }}
                                        onClick={() => this.setState({ visibleCreate: true })}
                                    >
                                        <img src={Images.add} />
                                    </button>
                                </a>
                                <ReactTooltip border={true} id="create" place="bottom" type="light" effect="solid" />
                            </div>
                        </div>
                        <div style={{ padding: 25 }}>
                            <MuiThemeProvider theme={getMuiTheme()}>
                                <MUIDataTable
                                    theme={getMuiTheme()}
                                    data={this.state.dataTable}
                                    columns={columns}
                                    options={options}
                                />
                            </MuiThemeProvider>

                        </div>
                    </div>
                    :
                    <div>
                        <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -150 }}>
                            <label style={{ color: 'white', fontSize: 16, alignSelf: 'center' }}>Preview Data</label>
                        </div>
                        <div style={{ padding: 25 }}>
                            {this.state.dataLoaded && (
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        theme={getMuiTheme()}
                                        data={this.state.rows}
                                        columns={this.state.cols}
                                        options={options2}
                                    />
                                </MuiThemeProvider>
                            )}
                        </div>
                        <div style={{ display: 'flex', width: '100%', placeContent: 'flex-end', padding: 20 }}>
                            <button
                                type="button"
                                onClick={() => this.setState({ visibleParameter: true })}
                                style={{ marginRight: 20 }}
                            >
                                <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                    <span style={{ color: '#354960', fontSize: 11 }}>Batal</span>
                                </div>
                            </button>
                            <button
                                type="button"
                                onClick={() => this.state.buttonError ? this.setState({ popupError: true }) : this.uploadParameter()}
                                style={{}}
                            >
                                <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                    <span style={{ color: '#fff', fontSize: 11 }}>Simpan</span>
                                </div>
                            </button>
                        </div>
                    </div>
                }
                {this.state.visibleCreate && (
                    <CreateParameter
                        onClickClose={() => this.setState({ visibleCreate: false })}
                        createParameter={this.createParameter.bind(this)}
                    />
                )}

                {this.state.visibleEdit && (
                    <CreateParameter
                        type={"edit"}
                        onClickClose={() => this.setState({ visibleEdit: false })}
                        data={this.state.rowData}
                        updateParameter={this.updateParameter.bind(this)}
                    />
                )}
                {this.state.popupError && (
                    <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
                )}
                {this.state.visibleUpload && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
                                <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                                    <div className="popup-title">
                                        <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Upload File</span>
                                    </div>
                                </div>
                                <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                                    <button
                                        type="button"
                                        className="btn btn-circle btn-white"
                                        onClick={() => this.setState({ visibleUpload: false })}
                                    >
                                        <img src={Images.close} />
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
                                acceptedFiles={["xlsx"]}
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
                                onUpload={() => this.setState({ visibleUpload: false, visibleParameter: false })}
                            />
                        </div>
                    </div>
                )}
            </div>
        );
    }
}