import React, { createRef, useEffect, useState } from "react";
import PropTypes from "prop-types";
import ReactCSSTransitionGroup from "react-addons-css-transition-group";
import {
NgIf, Icon, EventEmitter, Dropdown, DropdownButton, DropdownList,
DropdownItem, Container, Loader,
} from "../../components/";
import { debounce, alert, confirm, prompt, notify } from "../../helpers/";
import { Files } from "../../model/";
import { t } from "../../locales/";
import "./submenu.scss";
class SubmenuComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
search_input_visible: false,
search_keyword: "",
};
this.$input = createRef();
this.onSearchChange_Backpressure = debounce(this.onSearchChange, 400);
this._onKeyPress = (e) => {
if (e.keyCode === 27) { // escape key
this.setState({
search_keyword: "",
search_input_visible: false,
});
if (this.$input.current) this.$input.current.blur();
this.props.onSearch(null);
} else if (e.ctrlKey && e.keyCode === 70) { // 'Ctrl F' shortcut to search
e.preventDefault();
this.setState({
search_input_visible: true,
});
if (this.$input.current) this.$input.current.focus();
} else if (e.altKey && (e.keyCode === 49 || e.keyCode === 50)) { // 'alt 1' 'alt 2' shortcut
e.preventDefault();
this.onViewChange();
}
};
}
componentDidMount() {
window.addEventListener("keydown", this._onKeyPress);
}
componentWillUnmount() {
window.removeEventListener("keydown", this._onKeyPress);
}
onNew(type) {
this.props.emit("new::"+type);
}
onDelete(arrayOfPaths) {
prompt.now(
t("Confirm by typing") + " \"remove\"",
(answer) => {
if (answer !== "remove") {
return Promise.resolve();
}
this.props.emit("file.delete.multiple", arrayOfPaths);
return Promise.resolve();
},
() => {/* click on cancel */},
);
}
onDownload(arrayOfPaths) {
this.props.emit("file.download.multiple", arrayOfPaths);
}
onExtract(arrayOfPaths) {
alert.now(