import React, { Component } from "react";
import Router from "next/router";
import Link from "next/link";
import { getSanksi } from "@/actions/sanksi";
import Header from "@/components/Main/Header";
import DetailPT from "@/components/Main/DetailPT";
import DetailSanksi from "@/components/Main/DetailSanksi";
import Riwayat from "@/components/PT/CabutSanksi/Riwayat";
import ContentWrapper from "@/components/Layout/ContentWrapper";
import { Row, Col, Card, CardBody, FormGroup, Button } from "reactstrap";
import { addCabutSanksi } from "@/actions/cabutSanksi";
let Dropzone = null;
class DropzoneWrapper extends Component {
	state = {
		isClient: false,
	};
	componentDidMount = () => {
		Dropzone = require("react-dropzone").default;
		this.setState({ isClient: true });
	};
	render() {
		return Dropzone ? {this.props.children} : null;
	}
}
class DetailPencabutanSanksi extends Component {
	constructor(props) {
		super(props);
		this.state = {
			files: [],
		};
	}
	static async getInitialProps({ query }) {
		const { noSanksi } = query;
		const sanksi = await getSanksi({ noSanksi, ptId: "0BCE4DB7-B207-445D-8D03-0C54B7688252" });
		return { query, sanksi };
	}
	onDrop = (files) => {
		this.setState({
			files: files.map((file) =>
				Object.assign(file, {
					preview: URL.createObjectURL(file),
				})
			),
			stat: "Added " + files.length + " file(s)",
		});
	};
	uploadFiles = (e) => {
		e.preventDefault();
		e.stopPropagation();
		this.setState({
			stat: this.state.files.length ? "Dropzone ready to upload " + this.state.files.length + " file(s)" : "No files added.",
		});
	};
	clearFiles = (e) => {
		e.preventDefault();
		e.stopPropagation();
		this.setState({
			stat: this.state.files.length ? this.state.files.length + " file(s) cleared." : "No files to clear.",
		});
		this.setState({
			files: [],
		});
	};
	handleKirim = async (e) => {
		e.preventDefault();
		const { noSanksi } = this.props.query;
		const formdata = new FormData();
		if (this.state.files.length > 0) {
			this.state.files.forEach((e) => {
				formdata.append("files", e);
			});
			const added = await addCabutSanksi({ noSanksi, ptId: "0BCE4DB7-B207-445D-8D03-0C54B7688252" }, formdata);
			if (added) {
				Router.push({
					pathname: "/app/pt/pencabutan-sanksi",
				});
			}
		}
	};
	render() {
		const { sanksi } = this.props;
		const { files } = this.state;
		const thumbs = files.map((file, index) => (
			
				 ));
		return (
			
		));
		return (
			
				
				
					
						Permohonan Pencabutan Sanksi
						
							
								
							
						
					 
					
						
							
								
									
										
											
											Permohonan Pencabutan Sanksi
											
										
									
								
							
						
						
							
						
					
					
						
							
						
					
				 
			
		);
	}
}
export default DetailPencabutanSanksi;