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

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

	componentDidMount = async () => {
		const { user } = this.props;
		const log = await getLog({ ptId: user.peran[0].organisasi.id, isPT: true });
		const pelaporan = await getPelaporan({ ptId: user.peran[0].organisasi.id });
		this.setState({ log, pelaporan });
	};

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

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