<?php

/**
 * @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render
 */
$isCustomColor = $attributes['isCustomColor'] ?? false;

$style = "";
if ($isCustomColor) {
  $style = "
    --orphic-ui-persistent-banner-background-color: {$attributes['backgroundColor']};
    --orphic-ui-persistent-banner-text-color: {$attributes['textColor']};
    --orphic-ui-persistent-banner-border-color: {$attributes['borderColor']};
    --orphic-ui-persistent-banner-primary-color: {$attributes['primaryColor']};
    --orphic-ui-persistent-banner-primary-bg: {$attributes['primaryBg']};
    --orphic-ui-persistent-banner-error-bg: {$attributes['errorBg']};
    --orphic-ui-persistent-banner-error-text: {$attributes['errorText']};
  ";
}
?>
<div <?php echo get_block_wrapper_attributes(); ?>>
  <div class="orphic-ui-persistent-banner-content <?php echo $isCustomColor ? 'customColor' : ''; ?>"
    data-id="<?php echo esc_attr($attributes['bannerName']); ?>"
    data-first-visit="<?php echo $attributes['isFirstVisit'] ? 'true' : 'false'; ?>"
    data-position="<?php echo esc_attr($attributes['position']); ?>"
    <?php if ($isCustomColor): ?> style="<?php echo $style; ?>" <?php endif; ?>>
    <div class="orphic-ui-persistent-banner-wrapper">
      <div class="orphic-ui-persistent-banner-text">
        <?php echo $content; // Affiche le contenu de InnerBlocks 
        ?>
      </div>
      <div class="orphic-ui-persistent-banner-buttons">
        <button class="orphic-ui-persistent-banner-close">
          <?php echo esc_html($attributes['closeText'] ?? 'Close'); ?>
        </button>
        <?php if ($attributes['isAgreeEnabled']): ?>
          <?php if (!$attributes['hasRedirect']): ?>
            <button class="orphic-ui-persistent-banner-agree">
              <?php echo esc_html($attributes['agreeText'] ?? 'Agree'); ?>
            </button>
          <?php else: ?>
            <a href="<?php echo $attributes['redirectUrl'] ? esc_url($attributes['redirectUrl']) : '#'; ?>" class="orphic-ui-persistent-banner-agree">
              <?php echo esc_html($attributes['agreeText'] ?? 'Agree'); ?>
            </a>
          <?php endif; ?>
        <?php endif; ?>
      </div>
    </div>
  </div>
</div>