<template>
    <div v-if="isMobile" class="scroll-button-container" @click="scrollToMessageListBottom()">
        <img class="scroll-button-icon" :src="pageBackIcon" alt="scroll down" />
    </div>
    <div v-else class="scroll-button-pc" @click="scrollToMessageListBottom()">
        <span class="scroll-button-pc__icon" aria-hidden="true">
            <svg viewBox="0 0 16 16" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M3.5 4.5L8 9L12.5 4.5" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"
                    stroke-linejoin="round" />
                <path d="M3.5 8.5L8 13L12.5 8.5" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"
                    stroke-linejoin="round" />
            </svg>
        </span>
        <span class="scroll-button-pc__text">{{ t('回到最新位置') }}</span>
    </div>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import pageBackIcon from '../../../assets/icons/pageBack.svg'
import { isMobile } from '../../../utils/env'

interface ScrollButtonProps {
    scrollToMessageListBottom: () => void
}

const props = defineProps<ScrollButtonProps>()
const { t } = useI18n()
</script>

<style scoped>
.scroll-button-container {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    background: #fff;
    border: 1px solid #e0e0e0;
    box-shadow: 0 4px 12px -5px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    z-index: 100;
}

.scroll-button-icon {
    width: 12px;
    height: 12px;
    transform: rotate(-90deg);
}

/* PC 端：胶囊按钮 */
.scroll-button-pc {
    position: absolute;
    bottom: 12px;
    right: 16px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    background: #ffffff;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
    color: #3370FF;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    z-index: 100;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.scroll-button-pc:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.scroll-button-pc:active {
    transform: translateY(1px);
}

.scroll-button-pc__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #3370FF;
}

.scroll-button-pc__text {
    font-weight: 500;
}
</style>