import React from 'react';
import superagent from 'superagent';
import _ from 'lodash';

import constants from '../CloudApi/Constants.js';
import WaxIdBitField from './WaxIdBitField.jsx';
import ToolPathDownloadButton from './ToolPathDownloadButton.jsx';
import MenuPageWrapper from '../Wrappers/MenuPageWrapper.jsx';
import JobsList from "./JobsList.jsx";
import * as ApiUtils from '../CloudApi/ApiUtils.js';

import { Segment, Modal, Header, Icon, Button, Table, Form, Divider, Label } from 'semantic-ui-react'

export default class Batch extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false
        };
    }

    async componentDidMount() {
        if (this.state.loading) {
            return;
        }
        this.setState({ loading: true });
        try {
            const batchId = this.props.match.params.batchId;
            const res = await superagent.get(`/api/admin/fabricator/batch/${batchId}`).accept('json');
            console.log(res.body);
            this.setState({batch: res.body});
        } catch (e) {
            console.error(e);
        }
        this.setState({ loading: false });
    }

    render() {
        if (this.state.batch) {
            return (
                <div>
                    <MenuPageWrapper title={`Saved query: ${this.state.batch.name}`} menuItems={[]} loading={false}>
                        <JobsList jobs={this.state.batch.jobs} />
                    </MenuPageWrapper>
                </div>
            )
        }
        return null;
    }
}
