<script setup lang="ts">
import type { Status } from 'masto'

const props = defineProps<{
  status: Status
  command?: boolean
}>()

const status = $computed(() => {
  if (props.status.reblog && props.status.reblog)
    return props.status.reblog
  return props.status
})

const createdAt = useFormattedDateTime(status.createdAt)

const visibility = $computed(() => STATUS_VISIBILITIES.find(v => v.value === status.visibility)!)
</script>

<template>
  <div :id="`status-${status.id}`" flex flex-col gap-2 py3 px-4 relative>
    <StatusActionsMore :status="status" absolute right-2 top-2 />
    <NuxtLink :to="getAccountRoute(status.account)" rounded-full hover:bg-active transition-100 pr5 mr-a>
      <AccountHoverWrapper :account="status.account">
        <AccountInfo :account="status.account" />
      </AccountHoverWrapper>
    </NuxtLink>
    <div
      :class="status.visibility === 'direct' ? 'my2 p1 px4 br2 bg-fade border-primary-light border-1 rounded-3 rounded-tl-none' : ''"
    >
      <StatusSpoiler :enabled="status.sensitive">
        <template #spoiler>
          <p text-2xl>
            {{ status.spoilerText }}
          </p>
        </template>
        <StatusBody :status="status" :with-action="false" text-2xl />
        <StatusPoll
          v-if="status.poll"
          :poll="status.poll"
        />
        <StatusMedia
          v-if="status.mediaAttachments?.length"
          :status="status"
          :class="status.visibility === 'direct' ? 'pb4' : ''"
          full-size
        />
        <StatusPreviewCard
          v-if="status.card"
          :card="status.card"
          :class="status.visibility === 'direct' ? 'pb4' : ''"
          :small-picture-only="status.mediaAttachments?.length > 0"
        />
      </StatusSpoiler>
    </div>
    <div flex="~ gap-1" items-center text-secondary text-sm>
      <div flex>
        <div>{{ createdAt }}</div>
        <StatusEditIndicator
          :status="status"
          :inline="false"
        >
          <span ml1 font-bold cursor-pointer>{{ $t('state.edited') }}</span>
        </StatusEditIndicator>
      </div>
      <div>&middot;</div>
      <CommonTooltip :content="$t(`visibility.${visibility.value}`)" placement="bottom">
        <div :class="visibility.icon" />
      </CommonTooltip>
      <div v-if="status.application?.name">
        &middot; {{ status.application?.name }}
      </div>
    </div>
    <StatusActions :status="status" details :command="command" border="t base" pt-2 />
  </div>
</template>
