<?php
/**
 * Row template for layout-7 (2-column grid based on layout-4)
 *
 * Available variables:
 * @var WP_User $user
 * @var array $columns
 * @var int $avatar_size
 *
 * @since 4.2.0
 */

// Get user data
$user_name  = $user->display_name;
$user_login = $user->user_login;
$user_email = $user->user_email;
$user_url   = $user->user_url;
$user_bio   = get_user_meta( $user->ID, 'description', true );

// Get first and last name
$first_name = get_user_meta( $user->ID, 'first_name', true );
$last_name  = get_user_meta( $user->ID, 'last_name', true );

// Get phone number
$phone = get_user_meta( $user->ID, 'wpuf_profile_phone', true );

// Get avatar size for card layout - this layout uses landscape aspect ratio
$card_avatar_size = ! empty( $avatar_size ) ? $avatar_size : 384;

// For landscape layouts, use the avatar size as width and calculate height
// Using a 2:1 aspect ratio approximately (384:188 ≈ 2:1)
$width  = $card_avatar_size;
$height = $card_avatar_size;
$size_class = '!wpuf-w-[' . $width . 'px] !wpuf-h-[' . $height . 'px]';

// Use new avatar function with dynamic size
$avatar = wpuf_ud_get_user_avatar_html( $user, $card_avatar_size, $size_class . ' !wpuf-rounded-[10px] !wpuf-object-cover' );
?>

<li class="wpuf-flex wpuf-flex-col wpuf-items-center wpuf-gap-4">
    <!-- Avatar -->
    <div class="wpuf-flex-shrink-0">
        <?php echo $avatar; ?>
    </div>

    <!-- User Information -->
    <div class="!wpuf-flex !wpuf-flex-col !wpuf-items-center !wpuf-text-center !wpuf-flex-grow">
        <!-- Full Name -->
        <h3 class="!wpuf-text-[20px] !wpuf-leading-[28px] !wpuf-font-semibold !wpuf-text-gray-900">
            <?php
            $name_parts = [];
            if ( $first_name ) {
                $name_parts[] = esc_html( $first_name );
            }
            if ( $last_name ) {
                $name_parts[] = esc_html( $last_name );
            }
            if ( ! empty( $name_parts ) ) {
                echo implode( ' ', $name_parts );
            } elseif ( $user_name ) {
                echo esc_html( $user_name );
            }
            ?>
        </h3>

        <!-- Email -->
        <?php if ( $user_email ) : ?>
            <p class="wpuf-text-[14px] wpuf-font-normal wpuf-text-gray-600 !wpuf-m-0">
                <a href="mailto:<?php echo esc_url( $user_email ); ?>" target="_blank" rel="noopener" class="wpuf-text-gray-500 hover:wpuf-text-gray-900">
                    <?php echo esc_html( $user_email ); ?>
                </a>
            </p>
        <?php endif; ?>

        <!-- Website -->
        <?php if ( $user_url ) : ?>
            <p class="wpuf-text-[14px] wpuf-font-normal wpuf-text-gray-600 !wpuf-m-0">
                <a href="<?php echo esc_url( $user_url ); ?>" target="_blank" rel="noopener" class="wpuf-text-gray-500 hover:wpuf-text-gray-900">
                    <?php echo esc_html( $user_url ); ?>
                </a>
            </p>
        <?php endif; ?>

        <!-- Phone Number -->
        <?php if ( $phone ) : ?>
            <p class="wpuf-text-[14px] wpuf-font-normal wpuf-text-gray-600 !wpuf-m-0">
                <a href="tel:<?php echo esc_attr( $phone ); ?>" class="wpuf-text-gray-500 hover:wpuf-text-gray-900">
                    <?php echo esc_html( $phone ); ?>
                </a>
            </p>
        <?php endif; ?>

        <!-- Social Icons -->
        <?php
        // Include social icons
        include WPUF_UD_TEMPLATES . '/shortcodes/directory/template-parts/social-icons.php';
        ?>
    </div>

    <!-- View Profile Button -->
    <div class="wpuf-mt-auto !wpuf-pt-2">
        <?php $profile_url = wpuf_ud_get_row_profile_url( $user, $all_data, $profile_url_helper ?? null ); ?>
        <a href="<?php echo esc_url( $profile_url ); ?>" class="!wpuf-bg-gray-800 !wpuf-text-white hover:!wpuf-text-white !wpuf-no-underline !wpuf-inline-flex !wpuf-items-center !wpuf-px-4 !wpuf-py-2 !wpuf-text-sm !wpuf-font-medium !wpuf-rounded-md hover:!wpuf-bg-gray-700">
            <?php esc_html_e( 'View Profile', 'wpuf-pro' ); ?>
            <span class="wpuf-sr-only">, <?php echo esc_html( $user_name ); ?></span>
        </a>
    </div>
</li>
