import React from 'react';
import superagent from 'superagent';
import cookie from 'react-cookies';

import MenuPageWrapper from '../Wrappers/MenuPageWrapper.jsx';
import * as ApiUtils from '../CloudApi/ApiUtils.js';
import EnvironmentsTable from './EnvironmentsTable.jsx';

export default class Environments extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            environments: []
        };
    }

    async componentDidMount() {
        try {
            const res2 = await superagent.get(`/cloud/admin/rooms/environments`).accept('json');
            console.log(res2.body);
            this.setState({ environments: res2.body.items, environmentsCount: res2.body.count });
        } catch (e) {
            console.log(e);
        }
    }

    render() {
        return (
            <MenuPageWrapper title="Environments" menuItems={[]} >
                <EnvironmentsTable environments={this.state.environments} environmentsCount={this.state.environmentsCount} />
            </MenuPageWrapper>
        );
    }
}
