<?php
$certificates = get_posts([
	'post_type' => 'dozent_certificate',
	'numberposts'   => '-1',
] );

$default_certificate_id = (int) get_option( 'default_certificate_id' );
?>

<div id="dlc-list-wrap" class="wrap">

    <h1>
		<?php _e( 'Certificates', 'dozent-lms-certificate' ); ?>
        <a href="<?php echo admin_url( 'post-new.php?post_type=dozent_certificate' ); ?>" class="page-title-action">
			<?php _e( 'Add Certificate', 'dozent-lms-certificate' ); ?>
        </a>
    </h1>

    <div class="dozent-certificate-page dozent-mt-4">
		<?php
		if ( is_array( $certificates ) && count( $certificates ) > 0 ) {
			?>

            <div class="dozent-row">

				<?php foreach ( $certificates as $certificate ) {
					$thumbnail = get_the_post_thumbnail_url( $certificate->ID );
					$certificate_title = $certificate->post_title;
					$edit_url = admin_url( "post.php?post={$certificate->ID}&action=edit" );
					?>
                    <div class="dozent-col-4">
                        <div class="certificate-loop-wrap">
                            <a href="<?php echo $edit_url; ?>" title="<?php echo $certificate_title; ?>" class="certificate-cover-wrap">
                                <img src="<?php echo $thumbnail; ?>" />
                            </a>

                            <div class="certificate-title">
                                <a href="<?php echo $edit_url; ?>">
                                    <h3> <?php echo $certificate_title; ?> </h3>
                                </a>

                                <label>
                                    <input type="radio" name="_certificate_default" value="<?php echo $certificate->ID; ?>" <?php checked( $certificate->ID, $default_certificate_id ) ?> >
									<?php _e( 'Set as Default', 'dozent-lms-certificate' ); ?>
                                </label>
                            </div>
                        </div>
                    </div>

				<?php } ?>

            </div>

			<?php
		} else {
			?>
            <div class="import-default-certificate dozent-text-center">
                <h3> <?php _e( 'Import Certificate', 'dozent-lms-certificate' ); ?> </h3>
                <p> <?php _e( 'Import pre-designed certificate to use those instants, you can always add your custom-designed certificate', 'dozent-lms-certificate' ); ?> </p>
                <form action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post">
                    <input type="hidden" name="action" value="dozent_import_certificates">
                    <button type="submit" class="button"> <?php _e( 'Import Certificate', 'dozent-lms-certificate' ); ?> </button>
                </form>
            </div>
			<?php
		}
		?>
    </div>
</div>



