<?php

$cfg = Inoby_Config::component("img-with-text");

//IMG BLOCK
$image = mb_get_block_field("img");
$img_alt_text = mb_get_block_field("img-alt-text");
$img_position = mb_get_block_field("img-position");
$img_col = (mb_get_block_field("img-col") ?: $cfg["img-col"]) / 10 + 1;
$space_col = $cfg["space-col"];

//TEXT BLOCK
$text = mb_get_block_field("text");
$slogan = mb_get_block_field("slogan");
$heading = mb_get_block_field("heading");
$subheading = mb_get_block_field("subheading");

//BUTTON BLOCK
$btn_text = mb_get_block_field("btn-text");
$btn_url = mb_get_block_field("btn-url");

$text_col = max(12 - $img_col - $space_col, 1);
$id = uniqid("inoby-img-with-text");

if ($image): ?>
<div <?= inoby_block_attrs($attributes, [
    "id" => $id,
    "class" => "inoby-img-with-text",
  ]) ?>>
  <style>
  <?="#{$id}"?>.img-with-text-wrap {
    --img-with-text-img-col: <?=$img_col ?>;
    --img-with-text-text-col: <?=$text_col ?>;
  }
  </style>
  <div class="container">
    <div class="row <?php if ($img_position == "left") {
        echo "left";
      } else {
        echo "right";
      } ?>">
      <div class="col-12">
        <div class="img-with-text-wrap <?php if ($img_position == "left") {
            echo "left";
          } else {
            echo "right";
          } ?>">
          <div class="img-wrap">
            <?= isset($image)
                ? mb_inoby_picture(
                  $image,
                  $cfg["img-size"] ?? "s-12",
                  $cfg["bp-sizes"] ?? [],
                )
                : "" ?>
          </div>
          <div class="content-wrap">
            <div class="text-wrap <?php if(!$heading && $slogan): echo 'with-slogan'; endif; ?>">
              <?php 
                if($slogan){echo '<span class="slogan">'. $slogan .'</span>';} 
                echo '<br>';
                if($heading){echo '<h2 class="like-h1">'. $heading .'</h2>';}
                if($subheading){echo '<h2 class="subheading underlined">'. $subheading .'</h2>';} 
                if($text){echo '<p class="text">'. $text .'</p>';}
              ?>
            </div>
            <div class="button-wrap">
              <?php if ($btn_url):
                  echo isset($btn_url) || $btn_text
                    ? '<a href="' .
                      $btn_url .
                      '" class="button">' .
                      $btn_text .
                      "</a>"
                    : "";
                endif; ?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<?php endif; ?>