{include $el->common('header')}

<div id="{$htmlId}" class="elm-item-organizer {$htmlClass}">

	{var $authors = array()}
	{var $authorConfig = $el->getOptionObjectFromConfig(authors)}
	{var $enableCarousel  = false}

	{var $args = array(
		'meta_key'    => 'last_name',
		'include'     => !in_array("0", (array)$el->option->authors) ? $el->option->authors : aitGetUsersByRoles($authorConfig[roles]),
		'orderby'     => $el->option(orderby),
		'order'       => $el->option(order),
		'number'      => $el->option(count),
	)}

	{foreach get_users($args) as $author}
		{?array_push($authors, WpLatte::createEntity('PostAuthor', $author->ID))}
	{/foreach}



	{if $args[orderby] == random}
		{? shuffle($authors)}
	{/if}


	{if !empty($authors)}
		{var $layout = $el->option->layout}
		{var $target = $el->option('linksInNewWindow') ? 'target="_blank"'}
		{var $textRows = $el->option->textRows}
		{var $authorAvatar = $el->option->authorAvatar}
		{var $authorPostsCount = $el->option->authorPostsCount}
		{var $authorBio = $el->option->authorBio}
		{var $authorSocial = $el->option->authorSocial}
		{var $authorBackground = $el->option->itemBackground}
		{var $authorBackgroundImage = $el->option->itemBackgroundImage}
		{* Unified variables and data *}
		{if $layout == box}
			{var $enableCarousel  = $el->option->boxEnableCarousel}
			{var $boxAlign 		  = $el->option->boxAlign}
			{var $numOfRows       = $el->option->boxRows}
			{var $numOfColumns    = $el->option->boxColumns}
		{else}
			{var $enableCarousel  = $el->option->listEnableCarousel}
			{var $numOfRows       = $el->option->listRows}
			{var $numOfColumns    = $el->option->listColumns}
		{/if}

		{if $enableCarousel}
			<div class="loading"><span class="ait-preloader">{!__ 'Loading&hellip;'}</span></div>
		{/if}

		{if $layout == box}
			<div n:class='elm-item-organizer-container, "column-{$numOfColumns}", "layout-{$layout}", $enableCarousel ? carousel-container : carousel-disabled,' data-cols="{$numOfColumns}" data-first="1" data-last="{= ceil(sizeof($authors) / $numOfRows) }" data-arrow-left="{__ 'previous'}" data-arrow-right="{__ 'next'}">
			{foreach $authors as $author}
				{var $meta = (object)$author->meta('user-metabox')}

				{if $enableCarousel and $iterator->isFirst($numOfRows)}
					<div n:class="item-box, $enableCarousel ? carousel-item">
				{/if}
				<div n:class='item, "item{$iterator->counter}",	$enableCarousel ? carousel-item, $iterator->isFirst($numOfColumns) ? item-first, $iterator->isLast($numOfColumns) ? item-last, $authorAvatar ? image-present, ($authorBackground == "enable" && $authorBackgroundImage) ? author-bg, $boxAlign ? $boxAlign'	data-id="{$iterator->counter}">

					<a href="{$author->postsUrl}" rel="author" class="author-link">

						{if $authorBackground == 'enable' and $authorBackgroundImage}

							{if isset($meta->authorBackground) and $meta->authorBackground != ''}
								{var backgroundUrl = $meta->authorBackground}
							{else}
								{var backgroundUrl = $options->theme->header->headbg->image}
							{/if}

							<div class="author-background-wrap">
								<div class="author-background" style="background-image: url('{!aitResizeImage($backgroundUrl, array('width' => 640, 'height' => 150, 'crop' => true))}');"></div>
							</div>

						{/if}

						{if $authorAvatar}
							<div class="item-thumbnail">
								{!$author->avatar(150)}
								{if $authorPostsCount}
									<div class="author-posts-count">
										<span>{_n '%s post', '%s posts', count_user_posts($author->id)|printf:count_user_posts($author->id)}</span>
									</div>
								{/if}
							</div>
						{/if}

						<div class="item-title">
							<h3>{$author->displayName}</h3>
							{if $authorPostsCount and !$authorAvatar}
								<div class="author-posts-count">
									<span>{_n '%s post', '%s posts', count_user_posts($author->id)|printf:count_user_posts($author->id)}</span>
								</div>
							{/if}
						</div>
					</a>

					<div class="item-text">
						{var $authorBiography = isset($meta->biography) ? AitLangs::getCurrentLocaleText($meta->biography): ""}

						{if $authorBio and $authorBiography != ''}
							<div class="item-excerpt">
								<p class="txtrows-{$textRows}">{!wp_trim_words(strip_shortcodes($authorBiography|striptags), 200)}</p>
							</div>
						{/if}
						{if isset($meta->socIcons) and !empty($meta->socIcons) and $authorSocial}
							<div class="item-icons">
								<ul class="author-icons">
									{foreach $meta->socIcons as $icon}
									<li>
										<a href="{$icon['url']}">
											{if $icon['iconFont']}
												<i class="fa {$icon['iconFont']}"></i>
											{else}
												{if $icon['icon']}<img src="{$icon['icon']}" class="s-icon s-icon-light" alt="icon">{/if}
											{/if}
											<!-- <span class="s-title">{AitLangs::getCurrentLocaleText($icon['title'])}</span> -->
										</a>
									</li>
									{/foreach}
								</ul>
							</div>
						{/if}
					</div>
				</div>

				{if $enableCarousel and $iterator->isLast($numOfRows)}
					</div>
				{/if}
			{/foreach}
			</div>
		{else}
			<div n:class='elm-item-organizer-container, "column-{$numOfColumns}", "layout-{$layout}", $enableCarousel ? carousel-container : carousel-disabled,' data-cols="{$numOfColumns}" data-first="1" data-last="{= ceil(sizeof($authors) / $numOfRows)}" data-arrow-left="{__ 'previous'}" data-arrow-right="{__ 'next'}">
			{foreach $authors as $author}

				{var $meta = (object)$author->meta('user-metabox')}

				{if $enableCarousel and $iterator->isFirst($numOfRows)}
					<div n:class="item-box, $enableCarousel ? carousel-item">
				{/if}
				<div n:class='item, "item{$iterator->counter}",	$enableCarousel ? carousel-item, $iterator->isFirst($numOfColumns) ? item-first, $iterator->isLast($numOfColumns) ? item-last, $authorAvatar ? image-present, ($authorBackground == "enable" && $authorBackgroundImage) ? author-bg' data-id="{$iterator->counter}">

					<a href="{$author->postsUrl}" rel="author" class="author-link">

						{if $authorBackground == 'enable' and $authorBackgroundImage}

							{if isset($meta->authorBackground) and ($meta->authorBackground != '')}
								{var backgroundUrl = $meta->authorBackground}
							{else}
								{var backgroundUrl = $options->theme->header->headbg->image}
							{/if}

							<div class="author-background-wrap">
								<div class="author-background" style="background-image: url('{!aitResizeImage($backgroundUrl, array('width' => 640, 'height' => 400, 'crop' => true))}');"></div>
							</div>

						{/if}

						{if $authorAvatar}
							<div class="item-thumbnail">
								{!$author->avatar(150)}
								{if $authorPostsCount}
									<div class="author-posts-count">
										<span>{_n '%s post', '%s posts', count_user_posts($author->id)|printf:count_user_posts($author->id)}</span>
									</div>
								{/if}
							</div>
						{/if}

						<div class="item-title">
							<h3>{$author->displayName}</h3>
							{if $authorPostsCount and !$authorAvatar}
									<div class="author-posts-count">
										<span>{_n '%s post', '%s posts', count_user_posts($author->id)|printf:count_user_posts($author->id)}</span>
									</div>
							{/if}
						</div>
					</a>

					<div class="item-text">
						{var $authorBiography = AitLangs::getCurrentLocaleText($meta->biography)}

						{if $authorBio and $authorBiography != ''}
							<div class="item-excerpt">
								<p class="txtrows-{$textRows}">{!wp_trim_words(strip_shortcodes($authorBiography|striptags), 200)}</p>
							</div>
						{/if}

						{if isset($meta->socIcons) and !empty($meta->socIcons) and $authorSocial}
							<div class="item-icons">
								<ul class="author-icons">
									{foreach $meta->socIcons as $icon}
									<li>
										<a href="{$icon['url']}">
											{if $icon['iconFont']}
												<i class="fa {$icon['iconFont']}"></i>
											{else}
												{if $icon['icon']}<img src="{$icon['icon']}" class="s-icon s-icon-light" alt="icon">{/if}
											{/if}
											<!-- <span class="s-title">{AitLangs::getCurrentLocaleText($icon['title'])}</span> -->
										</a>
									</li>
									{/foreach}
								</ul>
							</div>
						{/if}
					</div>
				</div>

				{if $enableCarousel and $iterator->isLast($numOfRows)}
					</div>
				{/if}
			{/foreach}
			</div>
		{/if}
	{else}
		<div class="elm-item-organizer-container">
			<div class="alert alert-info">
				{_x 'Authors', 'name of element'}&nbsp;&nbsp;|&nbsp;&nbsp;{__ 'Info: There are no items created, add some please.'}
			</div>
		</div>
	{/if}
</div>

{includePart "ait-theme/elements/authors/javascript", enableCarousel => $enableCarousel}
