import {useState} from '@wordpress/element'; import {Spinner} from '@wordpress/components'; import {__, _n, sprintf} from '@wordpress/i18n'; import './AssignmentTargetColumn.scss'; import EditableLinkedItem from './EditableLinkItem'; import TextInput from './TextInput'; import Checkbox from './Checkbox'; const PlacementCard = ( {placement, isAssigned, onAssignmentChange, activeContext} ) => { const [isReplacing, setIsReplacing] = useState( false ); const isOccupiedByOther = placement.item_id !== 0 && placement.item_id !== activeContext?.id; const isOccupied = placement.item_id !== 0 && placement.id !== activeContext.id && !isAssigned; const showReplaceLink = isOccupiedByOther && !isAssigned; const isDisabled = showReplaceLink; const handleCheckboxChange = ( isChecked ) => { const action = isChecked ? 'assign_to_placement' : 'unassign_from_placement'; onAssignmentChange( {action, placementId: placement.id} ); if ( !isChecked ) { setIsReplacing( false ); } }; const handleReplaceClick = ( e ) => { e.preventDefault(); setIsReplacing( true ); onAssignmentChange( {action: 'assign_to_placement', placementId: placement.id} ); }; return (
); }; const TargetColumn = ( {placements, activeContext, assignments, onAssignmentChange, isTargetLoading, onSearchChange, searchQuery} ) => { let statusMessage = ''; if ( activeContext && isTargetLoading ) { statusMessage = __( 'Loading placements…', 'adpresso' ); } else if ( activeContext ) { statusMessage = placements.length === 0 ? __( 'No placements available.', 'adpresso' ) /* translators: %d: number of placements */ : sprintf( _n( '%d placement', '%d placements', placements.length, 'adpresso' ), placements.length ); } // Stays mounted across all branches (same slot in every fragment), so updates are announced. const statusRegion = (
{statusMessage}
); if ( !activeContext ) { return ( <> {statusRegion}

{__( 'Select an option on the left.', 'adpresso' )}

); } if ( isTargetLoading ) { return ( <> {statusRegion}
); } return ( <> {statusRegion}
{/* Stage 1: */} {!activeContext && (
{__( 'Select an option on the left', 'adpresso' )}
)} {/* Loading */} {activeContext && isTargetLoading && (
{__( 'Loading placements…', 'adpresso' )}
)} {/* List */} {activeContext && !isTargetLoading && ( <>
{placements.length === 0 && (

{__( 'No placements available.', 'adpresso' )}

)} {placements.map( ( placement ) => ( ) )}
)}
); }; export default TargetColumn;