<?php
/**
 * The sidebar containing the main widget area
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package business_office
 */
?>

<aside id="secondary" class="widget-area layout__sidebar sidebar" aria-label="<?php esc_attr_e( 'Sidebar', 'business-office' ); ?>">
	<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
		<?php dynamic_sidebar( 'sidebar-1' ); ?>
	<?php else : ?>
		<section class="widget widget_search c-widget">
			<h2 class="widget-title"><?php _e( 'Search', 'business-office' ); ?></h2>
			<?php get_search_form(); ?>
		</section>

		<section class="widget c-widget">
			<h2 class="widget-title"><?php _e( 'Recent Posts', 'business-office' ); ?></h2>
			<ul>
				<?php
				$business_office_recent_posts = wp_get_recent_posts(
					array(
						'numberposts' => 5,
						'post_status' => 'publish',
					)
				);

				foreach ( $business_office_recent_posts as $business_office_post ) :
					?>
					<li>
						<a href="<?php echo esc_url( get_permalink( $business_office_post['ID'] ) ); ?>">
							<?php echo esc_html( $business_office_post['post_title'] ); ?>
						</a>
					</li>
					<?php
				endforeach;
				?>
			</ul>
		</section>

		<section class="widget c-widget">
			<h2 class="widget-title"><?php _e( 'Recent Comments', 'business-office' ); ?></h2>
			<ul>
				<?php
				$business_office_recent_comments = get_comments(
					array(
						'number'      => 5,
						'status'      => 'approve',
						'post_status' => 'publish',
					)
				);

				foreach ( $business_office_recent_comments as $business_office_comment ) :
					$business_office_comment_post_title = get_the_title( $business_office_comment->comment_post_ID );
					?>
					<li>
						<a href="<?php echo esc_url( get_comment_link( $business_office_comment ) ); ?>">
							<?php
							echo esc_html(
								sprintf(
									/* translators: 1: Comment author, 2: Post title. */
									__( '%1$s on %2$s', 'business-office' ),
									$business_office_comment->comment_author,
									$business_office_comment_post_title
								)
							);
							?>
						</a>
					</li>
					<?php
				endforeach;
				?>
			</ul>
		</section>

		<section class="widget c-widget">
			<h2 class="widget-title"><?php _e( 'Archives', 'business-office' ); ?></h2>
			<ul>
				<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
			</ul>
		</section>
	<?php endif; ?>
</aside>