/**
  * Initializes the AJAX-based live search.
  *
  * @since 3.0.0
  *
  * @return void
  */
 public function initialize()
 {
     add_action('wp_ajax_' . self::ACTION, function () {
         $context = RelationshipContext::from_request();
         ob_start();
         $this->search_results->render($context);
         wp_send_json_success(['html' => ob_get_clean(), 'remoteSiteId' => $context->remote_site_id()]);
     });
 }
    /**
     * Renders the markup.
     *
     * @since   3.0.0
     * @wp-hook TODO: Reference (to-be-defined) class constant of Translation meta box.
     *
     * @param RelationshipContext $context Relationship context data object.
     *
     * @return void
     */
    public function render(RelationshipContext $context)
    {
        $remote_post_id = $context->remote_post_id();
        $remote_site_id = $context->remote_site_id();
        $action_container_id = "mlp-rc-action-container-{$remote_site_id}";
        $actions = [$this->default_action => __('Leave as is', 'multilingual-press'), RelationshipController::ACTION_CONNECT_NEW => __('Create new post', 'multilingual-press')];
        if ($remote_post_id) {
            $actions[RelationshipController::ACTION_DISCONNECT] = __('Remove relationship', 'multilingual-press');
        }
        $action_search_id = "mlp-rc-action-{$remote_site_id}-search";
        $search_container_id = "mlp-rc-search-container-{$remote_site_id}";
        $search_input_id = "mlp-rc-search-{$remote_site_id}";
        ?>
		<div class="mlp-relationship-control" data-remote-post-id="<?php 
        echo esc_attr($remote_post_id);
        ?>
"
			data-remote-site-id="<?php 
        echo esc_attr($remote_site_id);
        ?>
"
			data-results-selector="#mlp-rc-search-results-<?php 
        echo esc_attr($remote_site_id);
        ?>
"
			data-source-post-id="<?php 
        echo esc_attr($context->source_post_id());
        ?>
"
			data-source-site-id="<?php 
        echo esc_attr($context->source_site_id());
        ?>
">
			<button type="button" name="mlp_rc_<?php 
        echo esc_attr($remote_site_id);
        ?>
"
				class="button secondary mlp-rc-button mlp-click-toggler"
				data-toggle-target="#<?php 
        echo esc_attr($action_container_id);
        ?>
">
				<?php 
        esc_html_e('Change Relationship', 'multilingual-press');
        ?>
			</button>
			<div id="<?php 
        echo esc_attr($action_container_id);
        ?>
" class='hidden'>
				<div class="mlp-rc-settings">
					<div class="mlp-rc-actions">
						<?php 
        array_walk($actions, [$this, 'render_radio_input'], $remote_site_id);
        ?>
						<p>
							<label for="<?php 
        echo esc_attr($action_search_id);
        ?>
">
								<input
									type="radio"
									name="mlp_rc_action[<?php 
        echo esc_attr($remote_site_id);
        ?>
]"
									value="<?php 
        echo esc_attr(RelationshipController::ACTION_CONNECT_EXISTING);
        ?>
"
									id="<?php 
        echo esc_attr($action_search_id);
        ?>
"
									class="mlp-state-toggler"
									data-toggle-target="#<?php 
        echo esc_attr($search_container_id);
        ?>
">
								<?php 
        esc_html_e('Select existing post &hellip;', 'multilingual-press');
        ?>
							</label>
						</p>
					</div>
					<div id="<?php 
        echo esc_attr($search_container_id);
        ?>
" class="mlp-rc-search-container">
						<label for="<?php 
        echo esc_attr($search_input_id);
        ?>
">
							<?php 
        esc_html_e('Live search', 'multilingual-press');
        ?>
						</label>
						<input type="search" id="<?php 
        echo esc_attr($search_input_id);
        ?>
" class="mlp-rc-search">
						<ul id="mlp-rc-search-results-<?php 
        echo esc_attr($remote_site_id);
        ?>
"
							class="mlp-rc-search-results">
							<?php 
        $this->search_results->render($context);
        ?>
						</ul>
					</div>
				</div>
				<p>
					<button type="button" class="button button-primary mlp-save-relationship-button">
						<?php 
        esc_attr_e('Save and reload this page', 'multilingual-press');
        ?>
					</button>
					<span class="description">
						<?php 
        esc_html_e('Please save other changes first separately.', 'multilingual-press');
        ?>
					</span>
				</p>
			</div>
		</div>
		<?php 
        $this->localize_script();
    }