$data Keys: mtd_cost, total_calls, avg_cost, cap, * projected, models, drill, level, offset. * * @return void */ public function render( array $data ): void { $mtd_cost = (float) $data['mtd_cost']; $total_calls = (int) $data['total_calls']; $avg_cost = (float) $data['avg_cost']; $cap = (float) $data['cap']; $projected = (float) $data['projected']; $models = (array) $data['models']; $drill = (array) $data['drill']; $level = (string) $data['level']; $offset = (int) $data['offset']; $meter_pct = $cap > 0 ? min( 100, round( ( $mtd_cost / $cap ) * 100 ) ) : 0; $meter_class = $meter_pct >= 90 ? ' prv-meter--capped' : ''; $projected_warn = $projected > $cap; echo '
'; $this->render_subnav( 'costs' ); echo '
'; echo '

' . esc_html__( 'Cost Accountability', 'pr-vision' ) . '

'; echo '

' . esc_html__( 'Per-call spend against the $5.00 monthly cap.', 'pr-vision' ) . '

'; echo '
'; // Cap progress card. echo '
'; echo '

' . esc_html__( 'Budget', 'pr-vision' ) . '

'; echo '
'; echo '
'; echo '
'; echo '$' . esc_html( number_format( $mtd_cost, 2 ) ) . ''; echo ' ' . esc_html( sprintf( /* translators: %s: cap amount */ __( 'of $%s', 'pr-vision' ), number_format( $cap, 2 ) ) ) . ''; echo '
'; echo '
'; $proj_class = $projected_warn ? ' style="color:#FF9D4D"' : ''; echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static string echo '' . esc_html__( 'Linear estimate', 'pr-vision' ) . ''; echo '$' . esc_html( number_format( $projected, 2 ) ) . ''; echo '
'; $days_left = (int) gmdate( 't' ) - (int) gmdate( 'j' ); echo '
' . esc_html( sprintf( /* translators: %d: days */ __( '%d days remaining', 'pr-vision' ), $days_left ) ) . '
'; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; if ( $total_calls > 0 ) { echo '

'; echo esc_html( sprintf( /* translators: 1: cost, 2: call count */ __( '$%1$s recorded across %2$d calls this month — matches the Dashboard MTD total.', 'pr-vision' ), number_format( $mtd_cost, 4 ), $total_calls ) ); echo '

'; } echo '
'; // Summary bento. echo '
'; $this->render_bento_tile( __( 'Total calls', 'pr-vision' ), (string) $total_calls, __( 'this month', 'pr-vision' ) ); $this->render_bento_tile( __( 'Avg cost / call', 'pr-vision' ), '$' . number_format( $avg_cost, 4 ), '' ); $top_model = ! empty( $models ) ? $models[0]['model'] . ' ($' . number_format( $models[0]['mtd_cost'], 4 ) . ')' : __( '—', 'pr-vision' ); $this->render_bento_tile( __( 'Most expensive model', 'pr-vision' ), $top_model, '' ); echo '
'; // Model breakdown table. $this->render_model_table( $models ); // Drill-down card. $this->render_drill_down( $drill, $level, $offset ); echo '
'; // .wrap } /** * Render the subnav tab strip (shared across all PR Vision pages). * * Side effects: Outputs HTML. * * @param string $active Active tab key: dashboard|costs|calls|settings. * * @return void */ public function render_subnav( string $active ): void { $tabs = array( 'dashboard' => array( 'label' => __( 'Dashboard', 'pr-vision' ), 'slug' => 'pr-vision', ), 'costs' => array( 'label' => __( 'Costs', 'pr-vision' ), 'slug' => 'pr-vision-costs', ), 'calls' => array( 'label' => __( 'Call Log', 'pr-vision' ), 'slug' => 'pr-vision-calls', ), 'settings' => array( 'label' => __( 'Settings', 'pr-vision' ), 'slug' => 'pr-vision-settings', ), ); echo ''; } /** * Render a single bento tile. * * Side effects: Outputs HTML. * * @param string $label Label text. * @param string $value Primary value. * @param string $sub Sub-label (empty to omit). * * @return void */ private function render_bento_tile( string $label, string $value, string $sub ): void { echo '
'; echo '
' . esc_html( $label ) . '
'; echo '
' . esc_html( $value ) . '
'; if ( '' !== $sub ) { echo '
' . esc_html( $sub ) . '
'; } echo '
'; } /** * Render the per-model cost breakdown table. * * Side effects: Outputs HTML. * * @param array> $models Model rows. * * @return void */ private function render_model_table( array $models ): void { echo '

'; echo esc_html__( 'By Model', 'pr-vision' ); echo '

'; if ( empty( $models ) ) { echo '

' . esc_html__( 'No cost data yet. Run a probe to begin recording per-call costs.', 'pr-vision' ) . '

'; echo '
'; return; } echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ( $models as $row ) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
' . esc_html__( 'Model', 'pr-vision' ) . '' . esc_html__( 'Calls', 'pr-vision' ) . '' . esc_html__( 'MTD Cost', 'pr-vision' ) . '' . esc_html__( 'Cost / Call', 'pr-vision' ) . '
' . esc_html( (string) $row['model'] ) . '' . esc_html( (string) (int) $row['calls'] ) . '$' . esc_html( number_format( (float) $row['mtd_cost'], 6 ) ) . '$' . esc_html( number_format( (float) $row['cost_per_call'], 6 ) ) . '
'; echo ''; } /** * Render the drill-down card with level picker and results table. * * Side effects: Outputs HTML. * * @param array> $drill Drill-down rows. * @param string $level Current aggregation level. * @param int $offset Current pagination offset. * * @return void */ private function render_drill_down( array $drill, string $level, int $offset ): void { echo '

'; echo esc_html__( 'Cost Drill-Down', 'pr-vision' ); echo '

'; $levels = array( 'run', 'peptide', 'intent', 'model' ); $base_url = admin_url( 'admin.php?page=pr-vision-costs' ); echo '
'; foreach ( $levels as $lvl ) { $is_active = ( $lvl === $level ); $cls = 'prv-seg-btn' . ( $is_active ? ' prv-seg-btn--active' : '' ); $url = add_query_arg( array( 'prv_level' => $lvl, 'prv_offset' => 0, ), $base_url ); echo ''; echo esc_html( ucfirst( $lvl ) ); echo ''; } echo '
'; if ( empty( $drill ) ) { echo '

' . esc_html__( 'No data for this level.', 'pr-vision' ) . '

'; echo '
'; return; } echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ( $drill as $row ) { $filter_url = add_query_arg( array( $this->level_to_filter_key( $level ) => rawurlencode( (string) $row['group_key'] ) ), admin_url( 'admin.php?page=pr-vision-calls' ) ); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
' . esc_html( ucfirst( $level ) ) . '' . esc_html__( 'Calls', 'pr-vision' ) . '' . esc_html__( 'Cost', 'pr-vision' ) . '' . esc_html__( 'View', 'pr-vision' ) . '
' . esc_html( (string) $row['group_key'] ) . '' . esc_html( (string) (int) $row['calls'] ) . '$' . esc_html( number_format( (float) $row['total_cost'], 6 ) ) . '' . esc_html__( 'View calls →', 'pr-vision' ) . '
'; echo ''; } /** * Map drill-down level to call-log filter query param key. * * @param string $level Drill-down level: run|peptide|intent|model. * * @return string Filter parameter name. */ private function level_to_filter_key( string $level ): string { $map = array( 'run' => 'prv_filter_run', 'peptide' => 'prv_filter_peptide', 'intent' => 'prv_filter_intent', 'model' => 'prv_filter_model', ); return $map[ $level ] ?? 'prv_filter_run'; } }