<?php

namespace Kai\Product\Block\Product\View;

use Magento\Catalog\Block\Product\View\Description;

class CustomTab extends Description
{

    public function headerHTML()
    {
        return $this->getLayout()
            ->createBlock("Magento\Framework\View\Element\Template")
            ->setTemplate("Kai_Product::product/view/header.phtml")
            ->toHtml();
    }

    public function getProductName()
    {
        $product = $this->getProduct();
        if ($product) {
            $product->getName();
        }
        return $product;
    }

    public function getImage()
    {
        $product = $this->getProduct();

        if ($product) {
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $helperImport = $objectManager->get('\Magento\Catalog\Helper\Image');

            $imageUrl = $helperImport->init($product, 'product_page_image_small')
                ->setImageFile($product->getSmallImage()) // image,small_image,thumbnail
                ->resize(380)
                ->getUrl();
            return $imageUrl;
        }
        return null;
    }

    public function getPrice()
    {
        $product = $this->getProduct();
        if ($product) {
            return $product->getFormattedPrice();
        }
        return null;
    }

    public function getCustomAttribute()
    {
        $product = $this->getProduct();
        // Replace 'your_custom_attribute_code' with your actual attribute code
        return $product->getData('kai_attribute');
    }
}
