import React, {useEffect, useState} from 'react'
import Modal from 'antd/lib/modal'
import Typography from 'antd/lib/typography';
import "./styles.less"

const { Title,  } = Typography;

const JanelaPublicacoes = ({ok, pessoa}) => {
    const [data, setData] = useState([])
    useEffect(() => {
        netuno.service({
            url: '/services/pessoas/publicacoes',
            method: 'POST',
            credentials: 'include',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                uid: pessoa.uid
            }),
            success: (response)=> {
                if (response.json) {
                    setData(response.json)
                } else {
                    fail();
                }
            },
            fail: ()=> {
                fail();
            }
        });
    }, [])
    const fail = ()=> {
        setLoader(false)
        notification["error"]({
            message: 'Error',
            description: 'Data loading error...',
            style: {
                marginTop: 100,
            }
        });
    };
    console.log(data)
    return(
        <Modal
            title={`Publicações de ${pessoa.nome} ${pessoa.sobrenome}`}
            visible={true}
            onOk={() => ok(false)}>
            {data.map((publicao) => {
                return(
                    <div className="publicacao-container">
                        <hr />
                        <div>
                            <Title level={5}>{publicao.comunidade}</Title>
                            <span>{publicao.momento.replace(":00.0", "")}</span>
                        </div>
                        <p>{publicao.mensagem}</p>
                    </div>
                )
            })}
        </Modal>
    )
}

export default JanelaPublicacoes