import { __ } from '@wordpress/i18n'; import { Checkbox } from '@/components/ui/checkbox'; import { useOption } from '@/store/settings-store'; import type { ChatbotData } from './types'; /** * Pages the chatbot bubble shows on: "Product Pages" (all single products) * plus every published page and post. IDs and the "product" slug are * compared as strings since the saved option mixes both. */ export default function PageVisibility( { pages }: { pages: ChatbotData[ 'pages' ] } ) { const [ selected, setSelected ] = useOption( 'chatbot', 'wtofe_chatbot_pages' ); const current = ( selected ?? [] ).map( String ); const toggle = ( value: string, checked: boolean ) => setSelected( checked ? [ ...current, value ] : current.filter( ( item ) => item !== value ) ); const options = [ { id: 'product', title: __( 'Product Pages', 'ai-content-generator-for-woocommerce' ) }, ...pages ]; return (
{ options.map( ( page ) => { const value = String( page.id ); return ( toggle( value, checked ) } /> ); } ) }
); }