<template>
  <q-bar class="bg-transparent q-px-md" v-bind="$attrs" style="height: 55px">
    <q-icon v-if="icon" :name="icon" />
    <div>{{ title }}</div>

    <q-space />

    <q-btn
      v-if="maximizable"
      dense
      flat
      :icon="!maximizedToggle ? 'mdi-arrow-expand' : 'mdi-arrow-collapse'"
      @click="onMaximazedClick"
    />

    <q-btn dense flat icon="mdi-close" @click="emit('close')" />
  </q-bar>
</template>

<script setup>
import { ref, onMounted } from "vue";

const emit = defineEmits(["maximized", "close"]);

const { title, fullscreen, maximizable, icon } = defineProps({
  title: {
    type: String,
    default: "",
  },
  fullscreen: {
    type: Boolean,
    default: false,
  },
  maximizable: {
    type: Boolean,
    default: false,
  },
  icon: {
    type: String,
    default: "",
  },
});

const maximizedToggle = ref(false);

const onMaximazedClick = () => {
  maximizedToggle.value = !maximizedToggle.value;

  emit("maximized", maximizedToggle.value);
};

onMounted(() => {
  if (fullscreen) {
    maximizedToggle.value = true;
  }
});
</script>
