<div class="wrap pcfb-wrap">
    <h1 class="wp-heading-inline">
        <span class="pcfb-heading-icon dashicons dashicons-pressthis"></span>
        <?php esc_html_e( 'Form Responses', 'pc-form-builder-xyz123' ); ?>
    </h1>

    <hr class="wp-header-end">

    <?php
    $forms = PC_Form_Handler::get_forms( array( 'limit' => 100 ) );
    ?>

    <div class="pcfb-responses-page">
        <?php if ( empty( $forms ) ) : ?>
            <div class="pcfb-empty-state">
                <span class="dashicons dashicons-pressthis pcfb-empty-icon"></span>
                <h3><?php esc_html_e( 'No forms to show responses', 'pc-form-builder-xyz123' ); ?></h3>
                <p><?php esc_html_e( 'Create a form first to start collecting and viewing responses.', 'pc-form-builder-xyz123' ); ?></p>
                <a href="<?php echo admin_url( 'admin.php?page=pcfb-form-builder&form_id=new' ); ?>" class="button button-primary">
                    <?php esc_html_e( 'Create a Form', 'pc-form-builder-xyz123' ); ?>
                </a>
            </div>
        <?php else : ?>
            <div class="pcfb-responses-overview">
                <h2><?php esc_html_e( 'Select a Form', 'pc-form-builder-xyz123' ); ?></h2>
                <p class="description"><?php esc_html_e( 'Choose a form to view its responses.', 'pc-form-builder-xyz123' ); ?></p>

                <div class="pcfb-forms-select-list">
                    <?php foreach ( $forms as $form ) : ?>
                        <?php
                        $response_count = PC_Form_Handler::get_form_response_count( $form->id );
                        $view_url = admin_url( 'admin.php?page=pcfb-responses&form_id=' . $form->id );
                        $status_class = 'active' === $form->status ? 'status-active' : 'status-inactive';
                        ?>
                        <div class="pcfb-form-select-item">
                            <div class="pcfb-form-select-info">
                                <h3>
                                    <a href="<?php echo esc_url( $view_url ); ?>">
                                        <?php echo esc_html( $form->name ); ?>
                                    </a>
                                </h3>
                                <span class="pcfb-status <?php echo esc_attr( $status_class ); ?>">
                                    <?php echo esc_html( 'active' === $form->status ? __( 'Active', 'pc-form-builder-xyz123' ) : __( 'Inactive', 'pc-form-builder-xyz123' ) ); ?>
                                </span>
                            </div>
                            <div class="pcfb-form-select-stats">
                                <span class="pcfb-response-count">
                                    <strong><?php echo esc_html( $response_count ); ?></strong>
                                    <?php echo _n( 'Response', 'Responses', $response_count, 'pc-form-builder-xyz123' ); ?>
                                </span>
                                <a href="<?php echo esc_url( $view_url ); ?>" class="button button-small">
                                    <?php esc_html_e( 'View Responses', 'pc-form-builder-xyz123' ); ?>
                                </a>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>

            <div class="pcfb-total-responses">
                <?php
                $total_responses = 0;
                foreach ( $forms as $form ) {
                    $total_responses += PC_Form_Handler::get_form_response_count( $form->id );
                }
                ?>
                <div class="pcfb-total-card">
                    <span class="pcfb-total-number"><?php echo esc_html( $total_responses ); ?></span>
                    <span class="pcfb-total-label"><?php esc_html_e( 'Total Responses Across All Forms', 'pc-form-builder-xyz123' ); ?></span>
                </div>
            </div>
        <?php endif; ?>
    </div>
</div>
