<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; }

class Sifency_Addons_Taxonomy_Interface {
	public function sifency_addons_render_taxonomy_interface() {
		$screen = get_current_screen();
		$tax    = get_taxonomy( $screen->taxonomy );
		$terms  = get_terms(
			array(
				'taxonomy'   => $screen->taxonomy,
				'hide_empty' => false,
			)
		);

		if ( function_exists( 'sifency_addons_admin_render_layout' ) ) {
			sifency_addons_admin_render_layout( '', function () { } ); }
		?>
		<div class="sifency-app-wrapper sifency-tax-wrapper">
			<aside class="sifency-cpt-sidebar" id="sifency-tax-form-area">
				<div class="sifency-brand">
					<div class="sifency-logo-icon"><span class="dashicons dashicons-plus"></span></div>
					<span>Add New <?php echo esc_html( $tax->labels->singular_name ); ?></span>
				</div>
				<div class="sifency-nav" id="sifency-move-form-here"></div>
			</aside>
			<main class="sifency-main">
				<header class="sifency-topbar">
					<div class="topbar-left"><h2><?php echo esc_html( $tax->labels->name ); ?></h2></div>
					<div class="topbar-right">
						<a href="<?php echo esc_url( add_query_arg( 'view', 'classic' ) ); ?>" class="sifency-btn-xs btn-classic sifency-admin-btn text_underline_animation">
							<span class="dashicons dashicons-undo"></span> <span>Switch to Classic</span>
						</a>
						<span class="count-badge"><?php echo count( $terms ); ?> Items</span>
					</div>
				</header>
				<div class="sifency-content-area">
					<div class="sifency-grid">
						<?php
						if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) :
							foreach ( $terms as $term ) :
								$edit_link = admin_url( 'term.php?taxonomy=' . $screen->taxonomy . '&tag_ID=' . $term->term_id . '&post_type=' . get_post_type() );
								?>
							<div class="sifency-card-for-cpt">
								<div class="card-status status-publish"></div>
								<div class="card-body">
									<h3 class="card-title">
										<a href="<?php echo esc_url( $edit_link ); ?>" class="text_underline_animation sifency-admin-btn"><span><?php echo esc_html( $term->name ); ?></span></a>
									</h3>
									<div class="card-meta">
										<span>/<?php echo esc_html( $term->slug ); ?></span>
										<span class="status-badge"><?php echo esc_html( $term->count ); ?> Posts</span>
									</div>
									<?php
									if ( ! empty( $term->description ) ) :
										?>
										<p><?php echo esc_html( wp_trim_words( $term->description, 10 ) ); ?></p><?php endif; ?>
								</div>
								<div class="card-actions">
									<a href="<?php echo esc_url( $edit_link ); ?>" class="sifency-btn-xs btn-classic sifency-admin-btn text_underline_animation"><span>Edit</span></a>
								</div>
							</div>
						<?php endforeach; else : ?>
							<div class="sifency-empty-state"><span class="dashicons dashicons-category"></span><p>No categories found.</p></div>
						<?php endif; ?>
					</div>
				</div>
			</main>
		</div>
		<?php
	}
}