<?php
/**
 * Class OrderDetailsPointInfo
 *
 * @package DhlPolska\Point
 */

namespace DhlPolska\Point;

use DhlPolskaVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use DhlPolskaVendor\WPDesk\View\Renderer\Renderer;
use WC_Order;

/**
 * Render pickup point information in order details.
 */
class OrderDetailsPointInfo implements Hookable {
	use ParcelshopDataTrait;

	/**
	 * @var Renderer
	 */
	private Renderer $renderer;

	/**
	 * OrderDetailsPointInfo constructor.
	 *
	 * @param Renderer $renderer .
	 */
	public function __construct( Renderer $renderer ) {
		$this->renderer = $renderer;
	}

	/**
	 * Hooks.
	 */
	public function hooks() {
		add_action( 'woocommerce_order_details_after_order_table', [ $this, 'render_point_info' ] );
	}

	/**
	 * @param WC_Order $order .
	 *
	 * @return void
	 */
	public function render_point_info( $order ): void {
		if ( ! $order instanceof WC_Order ) { /* @phpstan-ignore-line */
			return;
		}

		$parcelshop_data = $this->get_parcelshop_data( $order );

		if ( '' === $parcelshop_data['id'] ) {
			return;
		}

		$this->renderer->output_render(
			'point/order-details-parcelshop',
			[
				'order'           => $order,
				'parcelshop_data' => $parcelshop_data,
			]
		);
	}
}
