import React from "react";
import PropTypes from "prop-types";
import copyToClipboard from "../../lib/copyToClipboard";
import AttachmentEditor from "./AttachmentEditor";
import ModalStore from "../ModalStore";
import ToastStore from "../ToastStore";
import { useDraggable } from "../drag";
export default function Attachment(props) {
const { attributeName, draggable } = 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[props.locale]) {
return attachment.description[props.locale];
}
return null;
};
const name = () => {
if (attachment.name && attachment.name[props.locale]) {
return attachment.name[props.locale];
}
return null;
};
const editAttachment = (evt) => {
evt.preventDefault();
ModalStore.dispatch({
type: "OPEN",
payload:
{description()}
}