import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard";
import BasePage from "../Base";
import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography";
import classes from "./classes.module.scss";
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
import FolderBoxInformation from "@Front/Components/DesignSystem/FolderBoxInformation";
import QuantityProgressBar from "@Front/Components/DesignSystem/QuantityProgressBar";
import ClientSection from "./ClientSection";
import ChevronIcon from "@Assets/Icons/chevron.svg";
import Confirm from "@Front/Components/DesignSystem/Modal/Confirm";
import InputField from "@Front/Components/DesignSystem/Form/Elements/InputField";
import { useRouter } from "next/router";

type IPropsClass = {
	selectedFolderUid: string;
};
type IState = {
	selectedFolder: IDashBoardFolder | null;
	isArchivedModalOpen: boolean;
};
class FolderInformationClass extends BasePage<IPropsClass, IState> {
	public constructor(props: IPropsClass) {
		super(props);
		this.state = {
			selectedFolder: null,
			isArchivedModalOpen: false,
		};
		this.onSelectedFolder = this.onSelectedFolder.bind(this);
		this.openArchivedModal = this.openArchivedModal.bind(this);
		this.closeArchivedModal = this.closeArchivedModal.bind(this);
	}

	// TODO: Message if the user has not created any folder yet
	// TODO: get the selected folder from the api in componentDidMount
	public override render(): JSX.Element {
		return (
			<DefaultNotaryDashboard title={"Dossier"} onSelectedFolder={this.onSelectedFolder}>
				<div className={classes["root"]}>
					{this.state.selectedFolder ? (
						<div className={classes["folder-informations"]}>
							<div className={classes["folder-header"]}>
								<div className={classes["header"]}>
									<Typography typo={ITypo.H1Bis}>Informations du dossier</Typography>
									<Button variant={EButtonVariant.LINE} icon={ChevronIcon}>
										Modifier les collaborateurs
									</Button>
								</div>
								<FolderBoxInformation folder={this.state.selectedFolder} />
								<div className={classes["second-box"]}>
									<FolderBoxInformation folder={this.state.selectedFolder} isDescription />
								</div>
								<div className={classes["progress-bar"]}>
									<QuantityProgressBar title="Complétion du dossier" total={100} currentNumber={0} />
								</div>
								{this.doesFolderHaveCustomer() && <ClientSection folder={this.state.selectedFolder} />}
							</div>

							{!this.doesFolderHaveCustomer() && <ClientSection folder={this.state.selectedFolder} />}

							<div className={classes["button-container"]}>
								<Button variant={EButtonVariant.GHOST} onClick={this.openArchivedModal}>
									Archiver le dossier
								</Button>
								<Button variant={EButtonVariant.SECONDARY}>Supprimer le dossier</Button>
							</div>
							<Confirm
								isOpen={this.state.isArchivedModalOpen}
								onClose={this.closeArchivedModal}
								closeBtn
								header={"Archiver le dossier ?"}
								cancelText={"Annuler"}
								confirmText={"Archiver"}>
								<div className={classes["modal-title"]}>
									<Typography typo={ITypo.P_16}>Souhaitez-vous vraiment archiver le dossier ?</Typography>
								</div>
								<InputField name="input field" fakeplaceholder="Description" textarea />
							</Confirm>
						</div>
					) : (
						<div className={classes["no-folder-selected"]}>
							<Typography typo={ITypo.H1Bis}>Informations du dossier</Typography>
							<div className={classes["choose-a-folder"]}>
								<Typography typo={ITypo.P_18} color={ITypoColor.GREY}>
									Veuillez sélectionner un dossier.
								</Typography>
							</div>
						</div>
					)}
				</div>
			</DefaultNotaryDashboard>
		);
	}
	public override async componentDidMount() {
		// if()
		// const selectedFolder = await Fodler.getInstance().getByUid(this.props.selectedFolderUid);
		// this.setState({ selectedFolder });
	}

	private doesFolderHaveCustomer(): boolean {
		return this.state.selectedFolder?.office_folder_has_customers !== undefined;
	}

	private onSelectedFolder(folder: IDashBoardFolder): void {
		this.setState({ selectedFolder: folder });
	}

	private openArchivedModal(): void {
		this.setState({ isArchivedModalOpen: true });
	}

	private closeArchivedModal(): void {
		this.setState({ isArchivedModalOpen: false });
	}
}

export default function FolderInformation() {
	const router = useRouter();
	let { uid } = router.query;
	uid = uid as string;
	return <FolderInformationClass selectedFolderUid={uid} />;
}
