<?php

namespace KupShop\ComponentsBundle\Twig\Components\Account\OrdersList\Order;

use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use KupShop\ComponentsBundle\Twig\DataProvider\OrderDataTrait;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent(template: '@Components/components/Account/OrdersList/Order/Items/Items.1.html.twig')]
#[Component(1, [
    new Version(1, newJs: null),
])]
class Items extends BaseComponent
{
    use OrderDataTrait;

    public int $limit = 5;

    protected array $items;

    public function getItems(): array
    {
        return $this->order->getItems();
    }

    public function getOrderUrl(): string
    {
        return $this->order->getUrl();
    }

    public function getMoreProducts(): string
    {
        $moreProducts = [];
        foreach (array_slice($this->order->getItems(), $this->limit) as $item) {
            $moreProducts[] = "{$item->getPieces()}x {$item->getDescription()}";
        }

        return join("\n", $moreProducts);
    }
}
