<?php
$product_id = mb_get_block_field("product");
$product = wc_get_product($product_id);
$stock_qty_format = apply_filters("featured-product-qty-label-format", "Zostáva %d miest");
if ($product) {
  $product_img_url = wp_get_attachment_image_url($product->get_image_id(), "full"); ?>

<div class="inoby-featured-product" style="background-image: url('<?= $product_img_url ?>');">
  <div class="content" >
    <h2 class="title"><?= $product->get_title() ?></h2>
    <div class="excerpt">
      <?= $product->get_short_description() ?>
    </div>
    <div class="add-to-cart">
      <?php if (mb_get_block_field("show_stock_status") ?? false && $product->get_manage_stock()): ?>
        <div class="stock">
          <?= sprintf($stock_qty_format, $product->get_stock_quantity()) ?></span>
        </div>
      <?php endif; ?>

      <?php if (RC_ENABLED): ?> 
        <?= rc_button([
          "text" => __("Pridať do košíka", "inoby"),
          "type" => "primary",
          "class" => "button add-to-cart-btn",
          "data" => [
            "data-quantity" => 1,
            "data-product_id" => $product->get_id(),
            "data-open_minicart" => 1,
          ],
        ]) ?>
      <?php else: ?>
        <a class="button" href="<?= $product->add_to_cart_url() ?>">
          <?= __("Pridať do košíka", "inoby") ?>
        </a>
      <?php endif; ?>
    </div>
  </div>
</div>

<?php
}
