import React, { useState, useEffect } from "react";
import { Table, Tag, Space } from 'antd';

import _service from '@netuno/service-client';




const ProdsTabela = () => {

    const [data, setData] = useState([]);

    useEffect(() => {
        _service({
            url: "produtos",
            success: (response) => {
                setData(response.json)
            },
            fail: (e) => {
                console.log("Service Error", e);
            }
        });

    }, []);

    const columns = [
        {
            title: 'Nome',
            dataIndex: 'nome',
            key: 'name',
            render: text => <a>{text}</a>,
        },
        {
            title: 'Categoria',
            dataIndex: 'categoria',
            key: 'categoria',
        },
        {
            title: 'Stock',
            dataIndex: 'stock',
            key: 'stock',
        },
        {
            title: 'Preço',
            dataIndex: 'preco',
            key: 'preco',
        }];

    return (
        <div >
            <h2>Tabela de Produtos-</h2>
            <Table columns={columns} dataSource={data} />
        </div>
    );
}

export default ProdsTabela;