import { useState } from "react";
import {
Divider,
IconButton,
Stack,
TextField,
Typography,
} from "@mui/material";
import {
CheckRounded,
CloseRounded,
DeleteRounded,
EditRounded,
OpenInNewRounded,
} from "@mui/icons-material";
interface Props {
value?: string;
onlyEdit?: boolean;
onChange: (value?: string) => void;
onOpenUrl?: (value?: string) => void;
onDelete?: () => void;
onCancel?: () => void;
}
export const WebUIItem = (props: Props) => {
const {
value,
onlyEdit = false,
onChange,
onDelete,
onOpenUrl,
onCancel,
} = props;
const [editing, setEditing] = useState(false);
const [editValue, setEditValue] = useState(value);
if (editing || onlyEdit) {
return (
<>
setEditValue(e.target.value)}
placeholder={`Support %host %port %secret`}
autoComplete="off"
/>
{
onChange(editValue);
setEditing(false);
}}
>
{
onCancel?.();
setEditing(false);
}}
>
>
);
}
const html = value
?.replace("%host", "%host")
.replace("%port", "%port")
.replace("%secret", "%secret");
return (
<>
({
"> span": {
color: palette.primary.main,
},
})}
dangerouslySetInnerHTML={{ __html: html || "NULL" }}
/>
onOpenUrl?.(value)}
>
{
setEditing(true);
setEditValue(value);
}}
>
>
);
};