<?php
/**
 * Sidebar.
 *
 * @package ttsunsolar
 */
?>
<aside id="secondary" class="sidebar-column" role="complementary" aria-label="<?php esc_attr_e( 'Sidebar', 'ttsunsolar' ); ?>">
	<div class="sidebar-panel">
		<div class="sidebar-panel__head">
			<span class="sidebar-panel__eyebrow"><?php esc_html_e( 'Explore', 'ttsunsolar' ); ?></span>
			<h2 class="sidebar-panel__title"><?php esc_html_e( 'Blog sidebar', 'ttsunsolar' ); ?></h2>
		</div>

		<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
			<div class="sidebar-panel__widgets">
				<?php dynamic_sidebar( 'sidebar-1' ); ?>
			</div>
		<?php else : ?>
			<div class="sidebar-panel__widgets">
				<section class="widget widget_search">
					<h3 class="widget-title"><?php esc_html_e( 'Search', 'ttsunsolar' ); ?></h3>
					<?php get_search_form(); ?>
				</section>

				<section class="widget widget_recent_entries">
					<h3 class="widget-title"><?php esc_html_e( 'Recent Posts', 'ttsunsolar' ); ?></h3>
					<ul>
						<?php
						$ttsunsolar_recent = wp_get_recent_posts(
							array(
								'numberposts' => 5,
								'post_status' => 'publish',
							),
							OBJECT
						);
						if ( ! empty( $ttsunsolar_recent ) ) :
							foreach ( $ttsunsolar_recent as $ttsunsolar_post ) :
								?>
								<li>
									<a href="<?php echo esc_url( get_permalink( $ttsunsolar_post ) ); ?>">
										<?php echo esc_html( get_the_title( $ttsunsolar_post ) ); ?>
									</a>
								</li>
								<?php
							endforeach;
							wp_reset_postdata();
						else :
							?>
							<li><?php esc_html_e( 'No posts yet.', 'ttsunsolar' ); ?></li>
						<?php endif; ?>
					</ul>
				</section>

				<section class="widget widget_categories">
					<h3 class="widget-title"><?php esc_html_e( 'Categories', 'ttsunsolar' ); ?></h3>
					<ul>
						<?php
						wp_list_categories(
							array(
								'title_li' => '',
								'number'   => 8,
							)
						);
						?>
					</ul>
				</section>
			</div>
		<?php endif; ?>
	</div>
</aside>
