<template>
  <div class="card">
    <header
      class="card-header has-background-grey-lighter is-unselectable"
      @click="toggle"
    >
      <p class="card-header-title">{{ header }}</p>
      <button class="card-header-icon">
        <span class="icon">
          <font-awesome-icon
            :icon="'fa-solid fa-angle-' + (is_open ? 'down' : 'right')"
          />
        </span>
      </button>
    </header>

    <template v-if="is_open">
      <slot v-if="ready" name="default" />
      <div v-else class="card-content">
        <progress class="progress is-primary" max="100" />
      </div>
    </template>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from "vue-class-component";

@Options({
  props: {
    header: {
      type: String,
      required: false,
      default: "",
    },
    ready: Boolean,
  },
  emits: ["open", "close"],
})
export default class extends Vue {
  public header!: string;
  public ready!: boolean;

  public is_open = false;

  public toggle() {
    this.is_open = !this.is_open;
    this.$emit(this.is_open ? "open" : "close");
  }
}
</script>

<style lang="scss" scoped>
div.card {
  &:not(:last-child) {
    margin-bottom: 1.5rem;
  }
  > .card-header {
    cursor: pointer;
  }
}
</style>
