<?php
namespace SabaiApps\Directories\Component\WordPressUser\DisplayElement;

use SabaiApps\Directories\Component\Entity\Model\Bundle;
use SabaiApps\Directories\Component\Display;
use SabaiApps\Directories\Context;

class UserCommentsDisplayElement extends Display\Element\AbstractElement {

	protected function _displayElementInfo( Bundle $bundle ) {
		return array(
			'type'             => 'content',
			'label'            => __( 'User Comments', 'directories-pro' ),
			'description'      => __( 'Displays comments submitted by the user', 'directories-pro' ),
			'default_settings' => array(
				'field_group' => null,
			),
			'icon'             => 'far fa-comments',
			'designable'       => array( 'margin', 'padding' ),
		);
	}

	public function displayElementSupports( Bundle $bundle, Display\Model\Display $display ) {
		return $bundle->entitytype_name === 'user';
	}

	public function displayElementRender( Bundle $bundle, array $element, $var, ?array $context = null ) {
		if ( $comments = get_comments(
			array(
				'user_id' => $var->getId(),
				'status'  => array( 'approve' ),
			)
		) ) {
			return '<ul>' . wp_list_comments(
				array(
					'echo' => false,
				),
				$comments
			) . '</ul>';
		}
	}
}
