<?php

/**
 * @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render
 */

$wrapper_attributes = get_block_wrapper_attributes([
  'class' => 'testimonial-unit-slide'
]);

$image = $attributes['image'] ?? null;
$show_image = $attributes['showImage'] ?? true;
$is_custom_color = $attributes['isCustomColor'] ?? false;

$style = '';
if ($is_custom_color) {
  // S'assurer que les couleurs ne sont pas vides
  $bg_color = !empty($attributes['backgroundColor']) ? $attributes['backgroundColor'] : 'var(--orphic-wp-block-plugin-color-background, #ffffff)';
  $text_color = !empty($attributes['textColor']) ? $attributes['textColor'] : 'var(--orphic-wp-block-plugin-color-text, #172B4D)';
  $border_color = !empty($attributes['borderColor']) ? $attributes['borderColor'] : 'var(--orphic-wp-block-plugin-color-border, #e0e0e0)';

  $style = sprintf(
    '--orphic-wp-testimonial-custom-background-color: %s; --orphic-wp-testimonial-custom-text-color: %s; --orphic-wp-testimonial-custom-border-color: %s;',
    $bg_color,
    $text_color,
    $border_color
  );
}
?>

<div <?php echo $wrapper_attributes; ?>>
  <div class="testimonial-unit-content <?php echo $is_custom_color ? 'customColor' : ''; ?>"
    style="<?php echo esc_attr($style); ?>">
    <?php if ($show_image && !empty($image['url'])) : ?>
      <div class="testimonial-image">
        <img src="<?php echo esc_url($image['url']); ?>"
          alt="<?php echo esc_attr($image['alt']); ?>" />
      </div>
    <?php endif; ?>
    <div class="testimonial-text">
      <?php echo $content; ?>
    </div>
  </div>
</div>