import { Tooltip, ActionIcon, CopyButton, Flex } from "@mantine/core";
import { IconCheck, IconGitCommit, IconFileDiff, IconEdit, IconColumnInsertRight, IconReplace, IconCopy,IconFile } from "@tabler/icons-react";
import React, { useState } from "react";
import { useMst } from "@/views/stores/RootStore";
import messageUtil from '@/util/MessageUtil';
import APIUtil from "@/util/APIUtil";
import IDEServiceUtil from "@/util/IDEServiceUtil";
const IconButton = ({ label, color = 'gray', onClick, children }) => (
{children}
);
const CodeCopyButton = ({ code, language, platform }) => {
return (
{({ copied, copy }) => (
{
copy();
APIUtil.createEvent(
{name: 'copy', value: code, language: language, ide: platform},
APIUtil.getCurrentMessageId()
);
}}>
{copied ? : }
)}
);
};
const DiffButton = ({ code, language, platform }) => {
const handleClick = () => {
const e = 'show_diff';
let selectedCode = code;
const selection = window.getSelection();
if (selection) {
selectedCode = selection.toString().trim();
}
// If no code is selected, use the entire code block
if (!selectedCode) {
selectedCode = code;
}
messageUtil.sendMessage({
command: e,
content: selectedCode
});
APIUtil.createEvent(
{name: e, value: selectedCode, language: language, ide: platform},
APIUtil.getCurrentMessageId()
);
};
return (
);
};
const EditApplyButton = ({ code, language, platform }) => {
const handleClick = () => {
IDEServiceUtil.callService("diff_apply", {
filepath: "",
content: code,
autoedit: true
});
APIUtil.createEvent(
{name: "edit_apply", value: code, language: language, ide: platform},
APIUtil.getCurrentMessageId()
);
};
return (
);
};
const CodeApplyButton = ({ code, language, platform }) => {
const handleClick = () => {
const e = 'code_apply';
messageUtil.sendMessage({
command: e,
content: code
});
APIUtil.createEvent(
{name: e, value: code, language: language, ide: platform},
APIUtil.getCurrentMessageId()
);
};
return (
);
};
const FileApplyButton = ({ code, language, platform }) => {
const handleClick = () => {
const e = 'code_file_apply';
messageUtil.sendMessage({
command: e,
content: code
});
APIUtil.createEvent(
{name: e, value: code, language: language, ide: platform},
APIUtil.getCurrentMessageId()
);
};
return (
);
};
// Add a new button to create new file
const NewFileButton = ({ code, language, platform }) => {
const handleClick = () => {
const e = 'code_new_file';
messageUtil.sendMessage({
command: e,
language: language,
content: code
});
APIUtil.createEvent(
{name: e, value: code, language: language, ide: platform},
APIUtil.getCurrentMessageId()
);
};
return (
);
};
// Similar changes can be made to DiffButton, CodeApplyButton, FileApplyButton, and CodeCopyButton
const CodeButtons = ({ platform, language, code }) => (
<>
{language === 'edits' && (
)}
>
);
export default CodeButtons;