import { Grid, Text, Title, Badge, Space, ActionIcon, Tooltip, Box } from '@mantine/core'; import { useState } from 'react'; import { RegexFilter } from '../../js/models'; import { b64decode, errorNotify, getapiobject, okNotify } from '../../js/utils'; import style from "./index.module.scss"; import { BsTrashFill } from "react-icons/bs" import YesNoModal from '../YesNoModal'; import FilterTypeSelector from '../FilterTypeSelector'; import { FaPause, FaPlay } from 'react-icons/fa'; import { useClipboard } from '@mantine/hooks'; function RegexView({ regexInfo }:{ regexInfo:RegexFilter }) { const mode_string = regexInfo.mode === "C"? "C -> S": regexInfo.mode === "S"? "S -> C": regexInfo.mode === "B"? "S <-> C": "🤔" let regex_expr = b64decode(regexInfo.regex); const [deleteModal, setDeleteModal] = useState(false); const [deleteTooltipOpened, setDeleteTooltipOpened] = useState(false); const [statusTooltipOpened, setStatusTooltipOpened] = useState(false); const clipboard = useClipboard({ timeout: 500 }); const deleteRegex = () => { getapiobject().regexdelete(regexInfo.id).then(res => { if(!res){ okNotify(`Regex ${regex_expr} deleted successfully!`,`Regex '${regex_expr}' ID:${regexInfo.id} has been deleted!`) }else{ errorNotify(`Regex ${regex_expr} deleation failed!`,`Error: ${res}`) } }).catch( err => errorNotify(`Regex ${regex_expr} deleation failed!`,`Error: ${err}`)) } const changeRegexStatus = () => { (regexInfo.active?getapiobject().regexdisable:getapiobject().regexenable)(regexInfo.id).then(res => { if(!res){ okNotify(`Regex ${regex_expr} ${regexInfo.active?"deactivated":"activated"} successfully!`,`Regex '${regex_expr}' ID:${regexInfo.id} has been ${regexInfo.active?"deactivated":"activated"}!`) }else{ errorNotify(`Regex ${regex_expr} ${regexInfo.active?"deactivation":"activation"} failed!`,`Error: ${res}`) } }).catch( err => errorNotify(`Regex ${regex_expr} ${regexInfo.active?"deactivation":"activation"} failed!`,`Error: ${err}`)) } return