<?php
/**
 * Gutenberg Block Template
 *
 * Supports admin styling for forms rendered via blocks
 */

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

// Same style logic as form-default
$dakidarts_styles = get_option( 'dakidarts_numerology_style_settings', [] );
$dakidarts_default_styles = [
    'form_bg'        => '#fff',
    'form_padding'   => '10px',
    'form_margin'    => '0',
    'button_bg'      => '#0073aa',
    'button_color'   => '#fff',
    'button_padding' => '10px 20px',
    'button_border'  => '1px solid #0073aa',
    'button_position'=> 'inherit'
];

$dakidarts_styles = wp_parse_args( $dakidarts_styles, $dakidarts_default_styles );
$dakidarts_form_style   = sprintf( 'background:%s;padding:%s;margin:%s;', esc_attr( $dakidarts_styles['form_bg'] ), esc_attr( $dakidarts_styles['form_padding'] ), esc_attr( $dakidarts_styles['form_margin'] ) );
$dakidarts_button_style = sprintf(
    'background:%s;color:%s;padding:%s;border:%s;display:block;margin:%s;',
    esc_attr( $dakidarts_styles['button_bg'] ),
    esc_attr( $dakidarts_styles['button_color'] ),
    esc_attr( $dakidarts_styles['button_padding'] ),
    esc_attr( $dakidarts_styles['button_border'] ),
    $dakidarts_styles['button_position'] === 'inherit' ? 'initial' : '0 auto'
);
?>

<form method="post" class="dakidarts-form dakidarts-block-form" style="<?php echo esc_attr( $dakidarts_form_style ); ?>">
    <?php foreach ( $params as $dakidarts_param ) : ?>
        <p>
            <label for="<?php echo esc_attr( $dakidarts_param ); ?>">
                <?php echo esc_html( ucfirst( str_replace( '_', ' ', $dakidarts_param ) ) ); ?>:
            </label>
            <input type="text" name="<?php echo esc_attr( $dakidarts_param ); ?>" required />
        </p>
    <?php endforeach; ?>

    <input type="hidden" name="dakidarts_endpoint" value="<?php echo esc_attr( $endpoint ); ?>" />
    <button type="submit" name="dakidarts_submit" class="dakidarts-submit" style="<?php echo esc_attr( $dakidarts_button_style ); ?>">
        <?php esc_html_e( 'Calculate', 'dakidarts-numerology-core' ); ?>
    </button>
</form>
