<?php
/**
 * Renders the artifact details page.
 *
 * @package    Plugnmeet
 * @subpackage Plugnmeet/admin/partials
 */

if ( ! defined( 'PLUGNMEET_BASE_NAME' ) ) {
    die;
}

$metadata      = $artifact_info->getMetadata();
$is_file_based = ( $metadata && $metadata->hasFileInfo() );
$roomId        = isset( $_GET['room_id'] ) ? sanitize_text_field( $_GET['room_id'] ) : '';
$paged         = isset( $_GET['paged'] ) ? sanitize_text_field( $_GET['paged'] ) : '';
?>
<div class="wrap plugnmeet-artifact-details">
    <div class="plugnmeet-details-header">
        <h1 class="wp-heading-inline"><?php echo __( 'Artifact Details', 'plugnmeet' ); ?></h1>
        <div class="plugnmeet-header-actions">
            <a href="<?php echo admin_url( 'admin.php?page=plugnmeet-artifacts&room_id=' . $roomId . '&paged=' . $paged ); ?>"
               class="button plugnmeet-button-secondary">
                <?php echo __( 'Back to Artifacts', 'plugnmeet' ); ?>
            </a>
            <?php if ( $is_file_based ) : ?>
                <a href="#" class="button plugnmeet-button-primary download-artifact"
                   data-artifact-id="<?php echo esc_attr( $artifact_info->getArtifactId() ); ?>"><?php echo __( 'Download', 'plugnmeet' ); ?></a>
            <?php endif; ?>
            <?php if ( $context['is_analytics'] ) : ?>
                <a href="#" class="button plugnmeet-button-success download-analytics-excel"
                   data-artifact-id="<?php echo esc_attr( $artifact_info->getArtifactId() ); ?>"><?php echo __( 'Download Excel', 'plugnmeet' ); ?></a>
            <?php endif; ?>
            <?php if ( $is_file_based ) : ?>
                <a href="#" class="button plugnmeet-button-danger delete-artifact"
                   data-artifact-id="<?php echo esc_attr( $artifact_info->getArtifactId() ); ?>"><?php echo __( 'Delete', 'plugnmeet' ); ?></a>
            <?php endif; ?>
        </div>
    </div>
    <hr/>

    <table class="form-table details">
        <tbody>
        <?php foreach ( $context['details'] as $detail ) : ?>
            <tr>
                <th scope="row"><?php echo esc_html( $detail['label'] ); ?></th>
                <td><?php echo esc_html( $detail['value'] ); ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>

    <?php if ( $context['is_analytics'] ) : ?>
        <h2 class="room-analytics-header"><?php echo __( 'Room Analytics', 'plugnmeet' ); ?></h2>
        <table class="form-table">
            <tbody>
            <?php foreach ( $context['room_details'] as $detail ) : ?>
                <tr>
                    <th scope="row"><?php echo esc_html( $detail['label'] ); ?></th>
                    <td><?php echo esc_html( $detail['value'] ); ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <?php if ( $context['has_users'] ) : ?>
            <h2 class="user-analytics-header"><?php echo __( 'User Analytics', 'plugnmeet' ); ?></h2>
            <div class="plugnmeet-analytics-table-wrapper">
                <table class="wp-list-table widefat striped">
                    <thead>
                    <tr>
                        <?php foreach ( $context['user_headers'] as $header ) : ?>
                            <th><?php echo esc_html( $header ); ?></th>
                        <?php endforeach; ?>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ( $context['user_rows'] as $row ) : ?>
                        <tr>
                            <?php foreach ( $row['data'] as $cell ) : ?>
                                <td><?php echo wp_kses( $cell['value'], array( 'br' => array() ) ); ?></td>
                            <?php endforeach; ?>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php endif; ?>
    <?php endif; ?>

    <?php if ( $context['is_meeting_summary'] ) : ?>
        <h2 class="meeting-summary-header"><?php echo __( 'Meeting Summary', 'plugnmeet' ); ?></h2>
        <div>
            <?php echo wp_kses_post( $context['meeting_summary_content'] ); ?>
        </div>
    <?php endif; ?>
</div>
