<?php

use humhub\helpers\Html;
use humhub\modules\suggestedFollowing\services\SuggestedFollowResult;
use humhub\modules\user\widgets\Image as UserImage;
use humhub\modules\user\widgets\UserFollowButton;

/**
 * @var \yii\web\View $this
 * @var SuggestedFollowResult[] $suggestions
 */
?>
<div class="panel panel-default suggested-following-widget">

    <div class="panel-heading">
        <?= Yii::t('SuggestedfollowingModule.base', '<strong>Suggested</strong> to Follow') ?>
    </div>

    <div class="panel-body">

        <?php foreach ($suggestions as $result): ?>
            <?php $user = $result->user; ?>

            <div class="suggested-following-item d-flex align-items-center mb-3">

                <div class="flex-shrink-0 me-3">
                    <?= UserImage::widget([
                        'user' => $user,
                        'width' => 40,
                        'htmlOptions' => [
                            'class' => 'rounded',
                            'style' => 'display:block;'
                        ],
                    ]) ?>
                </div>

                <div class="flex-grow-1">

                    <div class="fw-semibold">
                        <?= Html::a(
                            Html::encode($user->displayName),
                            $user->getUrl(),
                            ['class' => 'link-accent']
                        ) ?>
                    </div>

                    <div class="small text-body-secondary">
                        <?= Yii::t(
                            'SuggestedfollowingModule.base',
                            'Followed by {n, plural, =1{1 person} other{# people}} you follow',
                            ['n' => $result->overlapCount]
                        ) ?>
                    </div>

                </div>

                <div class="flex-shrink-0 ms-2">
                    <?= UserFollowButton::widget([
                        'user' => $user,
                        'followOptions' => [
                            'class' => 'btn btn-primary btn-sm followButton'
                        ],
                        'unfollowOptions' => [
                            'class' => 'btn btn-outline-primary btn-sm unfollowButton'
                        ],
                    ]) ?>
                </div>

            </div>

        <?php endforeach; ?>

    </div>

</div>