import React, { Component } from "react";
import Router from "next/router";
import { Row, Col, FormGroup, Button, Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap";
import { addBanding } from "@/actions/banding";
import { addDocPerbaikan } from "@/actions/docPerbaikan";
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;
	}
}
export class ModalPermohonan extends Component {
	constructor(props) {
		super(props);
		this.state = {
			modal1: false,
			files: [],
		};
	}
	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: [],
		});
	};
	toggleModal1 = () => {
		this.props.toggleModal(false);
		this.setState({
			modal1: !this.state.modal1,
		});
	};
	onSubmit = 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 addBanding({ noSanksi, ptId: "0BCE4DB7-B207-445D-8D03-0C54B7688252" }, formdata);
		formdata.append("banding", added.add.sanksi.banding._id);
		await addDocPerbaikan({ noSanksi, ptId: "0BCE4DB7-B207-445D-8D03-0C54B7688252" }, formdata);
		if (added) {
			Router.push({
				pathname: "/app/pt/jawaban-keberatan",
			});
		}
	};
	handleKirim = (e) => {
		this.setState({
			modal1: !this.state.modal1,
		});
		this.onSubmit(e);
	};
	render() {
		const { files } = this.state;
		const thumbs = files.map((file, index) => (
			
				 ));
		return (
			<>
				
					Apakah anda akan mengajukan banding?
					
						{" "}
						
					
				
				
					Upload Dokumen Banding
					
						
					
					
						
					
				
			>
		);
	}
}
export default ModalPermohonan;
			
		));
		return (
			<>
				
					Apakah anda akan mengajukan banding?
					
						{" "}
						
					
				
				
					Upload Dokumen Banding
					
						
					
					
						
					
				
			>
		);
	}
}
export default ModalPermohonan;