<?php
/**
 * AI Review Moderation column template for the comments list table.
 *
 * @package SAAI
 *
 * @var string $moderation_status The moderation status (pending/approved/flagged/rejected).
 * @var array  $result            The moderation result data.
 * @var int    $confidence        The normalized confidence score (0-100).
 */

if ( ! defined( 'ABSPATH' ) ) {
    die( 'You are not allowed to call this page directly.' );
}

use SAAI\AI_Agents\Review_Moderation_AI;

$status_labels = Review_Moderation_AI::get_status_labels();
$status_colors = Review_Moderation_AI::get_status_colors();

$status_label = isset( $status_labels[ $moderation_status ] ) ? $status_labels[ $moderation_status ] : $moderation_status;
$status_color = isset( $status_colors[ $moderation_status ] ) ? $status_colors[ $moderation_status ] : '#50575e';

$flags   = is_array( $result ) && ! empty( $result['flags'] ) && is_array( $result['flags'] ) ? $result['flags'] : array();
$summary = is_array( $result ) && isset( $result['admin_summary'] ) ? $result['admin_summary'] : '';
?>

<div class="saai-moderation-column" style="line-height: 1.6;">
    <span style="display: inline-block; padding: 1px 8px; border-radius: 3px; font-size: 11px; font-weight: 600; color: #fff; background-color: <?php echo esc_attr( $status_color ); ?>;">
        <?php echo esc_html( $status_label ); ?>
    </span>

    <?php if ( 'pending' !== $moderation_status && $confidence > 0 ) : ?>
        <span style="display: inline-block; margin-left: 4px; font-size: 12px; color: #50575e;">
            <?php echo esc_html( $confidence ); ?>%
        </span>
    <?php endif; ?>

    <?php if ( ! empty( $flags ) ) : ?>
        <div style="margin-top: 4px;">
            <?php foreach ( $flags as $flag ) : ?>
                <span style="display: inline-block; margin: 0 2px 2px 0; padding: 0 6px; border-radius: 3px; font-size: 11px; background-color: #fce4e4; color: #8a1f1f;">
                    <?php echo esc_html( $flag ); ?>
                </span>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>

    <?php if ( $summary ) : ?>
        <p style="margin: 4px 0 0; font-size: 12px; color: #646970;">
            <?php echo esc_html( wp_trim_words( $summary, 15 ) ); ?>
        </p>
    <?php endif; ?>
</div>
