<?php
/**
 * Plugin settings page template.
 *
 * @package SAAI
 */

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

<div class="saai-review-summary-metabox" data-total-reviews-count="<?php echo esc_attr( $total_reviews_count ); ?>">
    <div class="saai-review-summary-metabox__summary">
        <h3><?php esc_html_e( 'Review Summary', 'storeagent-ai-for-woocommerce' ); ?></h3>
        <textarea class="saai-review-summary-metabox__summary__textarea" name="saai_review[summary]" rows="5"><?php echo wp_kses_post( $review_summary['summary'] ); ?></textarea>
    </div>

    <div class="saai-review-summary-metabox__key-takeaways">
        <h3><?php esc_html_e( 'Key Takeaways', 'storeagent-ai-for-woocommerce' ); ?></h3>
        <ul>
            <?php foreach ( $review_summary['key_takeaways'] as $key => $takeaway ) : ?>
                <li class="saai-review-summary-metabox__key-takeaways__item">
                    <select name="saai_review[key_takeaways][<?php echo esc_attr( $key ); ?>][sentiment]">
                        <option value="positive" <?php selected( $takeaway['sentiment'], 'positive' ); ?>><?php esc_html_e( 'Positive', 'storeagent-ai-for-woocommerce' ); ?></option>
                        <option value="neutral" <?php selected( $takeaway['sentiment'], 'neutral' ); ?>><?php esc_html_e( 'Neutral', 'storeagent-ai-for-woocommerce' ); ?></option>
                        <option value="negative" <?php selected( $takeaway['sentiment'], 'negative' ); ?>><?php esc_html_e( 'Negative', 'storeagent-ai-for-woocommerce' ); ?></option>
                    </select>
                    <input type="text" name="saai_review[key_takeaways][<?php echo esc_attr( $key ); ?>][content]" value="<?php echo esc_attr( $takeaway['content'] ); ?>">
                    <i class="dashicons-before dashicons-minus"></i>
                </li>
            <?php endforeach; ?>
        </ul>
        <button id="saai-review-summary-add-key-takeaway-button" type="button" class="button"><?php esc_html_e( 'Add Key Takeaway', 'storeagent-ai-for-woocommerce' ); ?></button>
    </div>
    <?php wp_nonce_field( 'saai_review_summary_metabox', 'saai_review_summary_metabox_nonce' ); ?>

    <div class="saai-review-summary-metabox__generate-button-container">
        <button type="button" id="saai-review-summary-generate-button" class="saai-button saai-button-main saai-button-left-icon">
            <img src="<?php echo esc_url( SAAI_PLUGIN_URL . 'static/images/ai-icon.svg' ); ?>" alt="AI Icon" style="width: 16px; height: 16px;">
            <span class="saai-button-text"><?php esc_html_e( 'Regenerate with AI', 'storeagent-ai-for-woocommerce' ); ?></span>
        </button>
        <span class="spinner"></span>
    </div>
</div>
