import React, { Component } from "react";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import { Row, Col } from "reactstrap";
import { getPelaporan } from "@/actions/pelaporan";
import CaseProgress from "@/components/Main/CaseProgress";
import TableLaporan from "@/components/Penjadwalan/TableLaporan";
import { connect } from "react-redux";
import Loader from "@/components/Common/Loader";
import Link from "next/link";

class Penjadwalan extends Component {
	constructor(props) {
		super(props);
		this.state = {
			pelaporan: {},
		};
	}

	componentDidMount = async () => {
		const { token } = this.props;
		const pelaporan = await getPelaporan(token);
		this.setState({ pelaporan });
	};

	render() {
		const { pelaporan } = this.state;
		return (
			<ContentWrapper>
				<div className="content-heading">
					<div>Penjadwalan Evaluasi</div>
					<div className="ml-auto">
						<Link href="/app/pelaporan">
							<button className="btn btn-sm btn-secondary text-sm">&lt; back</button>
						</Link>
						<Link href="/app/pemeriksaan">
							<button className="btn btn-sm btn-secondary text-sm">next &gt;</button>
						</Link>
					</div>
				</div>
				<Row>
					<Col lg="4">
						<CaseProgress />
					</Col>
					<Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/penjadwalan/todo" linkName="Atur Jadwal" /> : <Loader />}</Col>
				</Row>
			</ContentWrapper>
		);
	}
}

const mapStateToProps = (state) => ({ user: state.user, token: state.token });
export default connect(mapStateToProps)(Penjadwalan);
