<?php
/**
 * Template part for displaying edit post link
 *
 * @package errigal
 * @since 1.0.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Accessibility_Class as Accessibility_Class,
	Errigal_Component_Class as Component_Class,
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
};
use Errigal\Content\Errigal_Content as Content;
use Errigal\Shared\{
	Errigal_Html_Builder as Html_Builder,
	Errigal_Utility as Utility,
};

if (
	! Content::can_edit() ||
	! ( is_page() || is_single() )
) {
	return;
}

$html_builder = Html_Builder::create();
$edit_link    = $html_builder->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME => 'edit-link',
		),
	)
);

edit_post_link(
	sprintf(
		/* translators: %s: Name of current post. Only visible to screen readers. */
		esc_html__( 'Edit %s', 'errigal' ),
		$html_builder->create_span(
			array(
				Html_Option::ATTRS => array(
					Html_Attr::CLASS_NAME => Accessibility_Class::SCREEN_READER_TEXT,
				),
			)
		)->get_element(
			esc_html(
				wp_strip_all_tags( get_the_title() )
			)
		)
	),
	$edit_link->get_open_tag(),
	$edit_link->get_close_tag(),
	null,
	Utility::get_class(
		Component_Class::BUTTON,
		Component_Class::CONTAINED
	)
);
