import React from "react";
import PropTypes from "prop-types";
import copyToClipboard from "../../lib/copyToClipboard";
import AttachmentEditor from "./AttachmentEditor";
import ModalStore from "../../stores/ModalStore";
import ToastStore from "../../stores/ToastStore";
import { useDraggable } from "../drag";
export default function Attachment(props) {
const { attributeName, draggable, locales, locale } = props;
const { record } = draggable;
const { attachment, uploading } = record;
const listeners = useDraggable(draggable, props.startDrag);
const copyEmbed = (evt) => {
evt.preventDefault();
copyToClipboard(`[attachment:${attachment.id}]`);
ToastStore.dispatch({
type: "NOTICE", message: "Embed code copied to clipboard"
});
};
const deleteRecord = (evt) => {
evt.preventDefault();
if (props.deleteRecord) {
props.deleteRecord();
}
};
const description = () => {
if (attachment.description && attachment.description[locale]) {
return attachment.description[locale];
}
return null;
};
const name = () => {
if (attachment.name && attachment.name[locale]) {
return attachment.name[locale];
}
return null;
};
const editAttachment = (evt) => {
evt.preventDefault();
ModalStore.dispatch({
type: "OPEN",
payload:
{description()}
}