<?php

namespace Formatrica\Fields;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Shared form-level context handed to each Field_Renderer_Interface::render()
 * call. Carries the few pieces of surrounding state a field renderer legitimately
 * needs without giving it access to the Form_Renderer internals. Constructed once
 * per form render.
 */
final class Field_Render_Context
{
    /**
     * @param string   $currency      Form-level payment currency (price field).
     * @param \Closure  $render_select fn(array $field): string — render a field
     *                                 as a native select (dynamic_select reuse).
     */
    public function __construct(
        private string $currency,
        private \Closure $render_select
    ) {
    }

    public function currency(): string
    {
        return $this->currency;
    }

    /**
     * Render the given field as a native <select>. Used by dynamic_select after
     * it has resolved its options.
     *
     * @param array<string, mixed> $field
     */
    public function render_select(array $field): string
    {
        return ($this->render_select)($field);
    }
}
