<?php

declare(strict_types=1);

namespace External\HannahBundle\Admin\Tabs;

use KupShop\AdminBundle\Admin\WindowTab;

class OrderOCTab extends WindowTab
{
    protected $title = 'flapOrderOC';
    protected $template = 'window/order.oc.invoice.tpl';

    public static function getTypes()
    {
        return [
            'orders' => 10,
        ];
    }

    public function getVars($smarty_tpl_vars)
    {
        if (!$this->getID()) {
            return [];
        }

        $order = new \Order();
        $order->createFromDB($this->getID());
        $invoiceNumerLokalu = $order->getData('invoice_numer_lokalu') ?: '';
        $deliveryNumerLokalu = $order->getData('delivery_numer_lokalu') ?: '';

        return [
            'invoiceNumber' => $invoiceNumerLokalu,
            'deliveryNumber' => $deliveryNumerLokalu,
        ];
    }

    public function handleUpdate()
    {
        if (!$this->getID()) {
            return;
        }

        $data = $this->getData();
        $order = new \Order();

        if ($order->createFromDB($this->getID())) {
            $order->setData('invoice_numer_lokalu', $data['invoice_number'] ?: '');
            $order->setData('delivery_numer_lokalu', $data['delivery_number'] ?: '');
        }
    }

    public function getLabel()
    {
        return 'OC';
    }
}
