<script lang="ts">
  /*
   * Visualizes any special case: e.g. not open for a long time, 24/7 open, ...
   * */
  import opening_hours from "opening_hours"
  import Tr from "../../Base/Tr.svelte"
  import Translations from "../../i18n/Translations"

  export let oh: opening_hours
  let nextChange = oh.getNextChange()
  let nowOpen = oh.getState(new Date())
  let comment = oh.getComment() ?? oh.getUnknown()
  const t = Translations.t.general.opening_hours
</script>

{#if nextChange !== undefined}
  <Tr t={(nowOpen ? t.open_until : t.closed_until).Subs({ date: nextChange.toLocaleString() })} />
{:else if typeof comment === "string"}
  <div>{comment}</div>
{:else if oh.getState()}
  <Tr t={t.open_24_7} />
{:else}
  <Tr t={t.closed_permanently} />
{/if}
