// Import React and useState for managing state import { useState, useEffect } from "@wordpress/element"; // Import Ant Design components for UI import { Switch } from "antd"; // Removed unused imports: Select, Form // Import specific typography components from Ant Design import Paragraph from "antd/es/typography/Paragraph"; import Title from "antd/es/typography/Title"; // Import WordPress translation function import { __ } from "@wordpress/i18n"; import Notice from "../../Components/Notice"; import { RetweetOutlined, UnlockOutlined } from "@ant-design/icons"; import Tag from "../../Components/Tag"; // Declare a global variable for plugin-specific data declare var swiftCouponSingle: { data: { auto_apply: { enabled: boolean; // Whether auto-apply is enabled allow_user_to_remove: boolean; // Whether users can remove the coupon }; }; }; // Define the AutoApply component const AutoApply: React.FC = () => { // State for whether auto-apply is enabled const [enabled, setEnabled] = useState( swiftCouponSingle.data?.auto_apply?.enabled || false ); // State for whether users can remove the coupon const [allowUserToRemove, setAllowUserToRemove] = useState( swiftCouponSingle.data?.auto_apply?.allow_user_to_remove || false ); // Effect to dispatch a custom event when state changes useEffect(() => { const event = new CustomEvent("swiftcoupons-coupon-data-changed", { detail: { type: "auto_apply", // Event type data: { enabled: enabled, // Current enabled state allow_user_to_remove: allowUserToRemove, // Current allowUserToRemove state }, }, }); window.dispatchEvent(event); // Dispatch the event }, [enabled, allowUserToRemove]); // Dependencies for the effect return ( // Main container with padding and flex layout