import { h } from "tsx-dom" ; import { CleanupType } from "../../lib/settingsSignature" ; import { getBadgeForCleanupType } from "../../background/backgroundHelpers" ; import { translateElement } from "../../lib/htmlUtils" ; import { RuleDialog } from "../dialogs/ruleDialog" ; import { cleanupTypeForElement } from "../../lib/settings" ; interface RuleButtonProps { expression ? : string ; type : CleanupType | null ; temporary ? : boolean ; onConfirm : ( type : CleanupType , expression : string , temporary : boolean ) => void ; } function updateRuleButton ( button , type , translate = false ) { const badge = type !== null && getBadgeForCleanupType ( type ) ; button . className = badge ? badge . className : "cleanup_type_none" ; button . setAttribute ( "data-i18n" , ( badge ? badge . i18nButton : "cleanup_type_create_button" ) + "?title?markdown" ) ; translateElement ( button ) ; } export function RuleButton ( { expression , type , temporary , onConfirm } ) { function onChangeProxy ( type , expression , temporary ) { updateRuleButton ( button , type , true ) ; onConfirm ( type , expression || "" , temporary ) ; } function onClick ( ) { < RuleDialog expression = { expression } editable = { type === null } focusType = { cleanupTypeForElement ( button ) } temporary = { temporary || false } onConfirm = { ( type , expression , temporary ) => type !== false && onChangeProxy ( type , expression , temporary ) } />; } const button = < button onClick = { onClick } />; updateRuleButton ( button , type ) ; return button ; }