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 { Row, Col } from "reactstrap";
import Timeline from "@/components/Main/Timeline";
import { getPT } from "@/actions/PT";
import Link from "next/link";

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

	static async getInitialProps({ query }) {
		return { query };
	}

	componentDidMount = async () => {
		const { query } = this.props;
		const log = await getLog({ ptId: query.ptId });
		this.setState({ log });
		const pt = await getPT({ id: query.ptId });
		this.setState({ pt });
	};

	render() {
		const { pt, log } = this.state;

		return (
			<ContentWrapper unwrap>
				{/* <Header /> */}
				<div className="p-3">
					<div className="content-heading">
						<div>Pemantauan {pt?.data && pt.data[0].nama}</div>
						<div className="ml-auto">
							<Link href="/app/pemantauan">
								<button className="btn btn-sm btn-secondary text-sm">&lt; back</button>
							</Link>
						</div>
					</div>
					<Row>
						<Col xl="9">
							<Timeline data={log.data} />
						</Col>
						<Col xl="3">{pt?.data && <DetailPT data={pt.data[0]} />}</Col>
					</Row>
				</div>
			</ContentWrapper>
		);
	}
}

export default Pemantauan;
