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

import Table from 'antd/lib/table';
import Column from "antd/lib/table/Column";
import Tag from "antd/lib/tag";
import Button from 'antd/lib/button';
import StockBotao from "./StockBotao/index.jsx";





const TabelaFarmacia = () => {


    const [data, setData] = useState([]);
    const [ stock, setStock ] = useState(null);



    useEffect(() => {
        const fail = () => {
            this.setState({ loading: false });
            notification["error"]({
                message: 'Erro',
                description: 'Tabela de Farmácia com erros...',
                style: {
                    marginTop: 100,
                }
            });
        };
        netuno.service({
            url: '/services/farmacias',
            method: 'GET',
            credentials: 'include',
            headers: {
                'Content-Type': 'application/json'
            },
            success: (response) => {

                if (response.json) {

                    setData(response.json);
                } else {
                    fail();
                }
            },
            fail: () => {
                fail();
            }

        });
        }, []);

        const columns = [
            {
                title: "Farmácia",
                dataIndex: "lab"
            },
            {
                title: "Stock de Farmácias",
                render: (text, record, index) => (
                    <div>
                        { <Button onClick={ () =>  setStock(record) }>Ver Stock</Button>}
                    </div>
                )
            }
        ];

       


        return <>

        { !!stock && <StockBotao
            produto={stock}
            onClose={ () => setStock(null) }
        /> }
        
        
        <Table dataSource={data} {... { columns}} />

        </>
};

export default TabelaFarmacia;