<script setup lang="ts">
import {useNews} from '../stores/useNews';

const news = useNews();

async function click() {
  if (!news.canManualSync()) return;
  await fetch('/sync', {method: 'POST'});
  await news.sync({country: 'DE'});
}
</script>
<template>
  <button :disabled="!news.canManualSync()" @click="click"
          class="px-4 py-2 rounded bg-green-600 disabled:bg-gray-400 text-white">
    Sync now
  </button>
  <p v-if="!news.canManualSync()" class="text-xs text-gray-500 mt-1">
    Wait {{ Math.ceil((30 * 60 * 1000 - (Date.now() - news.lastSync)) / 60000) }} min
  </p>
</template>
