
import React, { useEffect, useState } from "react";

import { Dashboard } from './../../../../models/'

import { BasicTable } from './../../../../lib'

import { Skeleton, Empty } from "antd";


export default function PopQueryDashboard({ record, id }) {

    const [loading, setLoading] = useState(false);

    const [result, setResult] = useState([[], 0]);

    useEffect(() => {

        setLoading(true);

        Dashboard.execPopQuery(id)
            .then((response) => {

                let reportData = {};

                if (response.result) {

                    reportData = response.result[0];

                } else {

                    if (response && response[0]) {

                        reportData = response[0];

                    } else {

                        reportData = response;

                    }

                }

                setResult(reportData)

                setLoading(false);


                console.log(record.tiletypeptr, result);
            })
            .catch(() => {
                // setResult({ error: 'Error' });
            });
    }, []);

    return <>

        {loading ? (
            <Skeleton active />
        ) : (
            <>
                {result.length ? <BasicTable result={result} /> : <Empty />}
            </>
        )}
    </>;
}
