import React, { Component } from "react";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import Header from "@/components/Main/Header";
import DetailPT from "@/components/Main/DetailPT";
import { getLogPT } from "@/actions/log";
import { getPT } from "@/actions/PT";
import { Row, Col } from "reactstrap";
import Timeline from "@/components/Main/Timeline";
import { connect } from "react-redux";
import Loader from "@/components/Common/Loader";

class Pemantauan extends Component {
	constructor(props) {
		super(props);
		this.state = {
			log: [],
			pt: {},
		};
	}

	componentDidMount = async () => {
		const { token } = this.props;
		const log = await getLogPT(token);
		const pt = await getPT(token);
		this.setState({ log, pt });
	};

	render() {
		const { log, pt } = this.state;
		return (
			<ContentWrapper unwrap>
				{pt?.data ? <Header data={pt.data} /> : <Loader />}
				<div className="p-3">
					<Row>
						{log.data ? (
							<Col xl="9">
								<Timeline data={log.data} />
							</Col>
						) : (
							<Loader />
						)}
						<Col xl="3">{pt.data && <DetailPT data={pt.data} />}</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

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