<template>
  <div class="ui-notification-types-config q-pa-lg">
    <div class="text-h5 q-mb-md">Настройка pop-up уведомлений</div>
    <q-table
      :columns="columns"
      :data="tableData"
      :pagination="pagination"
      flat
      hide-bottom
      separator="horizontal"
    >
      <template v-slot:body="props">
        <ui-notifications-widget-config-item
          :props="props"
          :label="props.row.configName"
          :type="props.row.type"
        />
      </template>
    </q-table>
    <q-separator />
  </div>
</template>

<script lang="ts">
import { Component, Inject, Vue } from 'vue-property-decorator'
import { QSeparator, QTable } from 'quasar'
import UiNotificationsWidgetConfigItem from '@/widgets/notifications/components/config/UiNotificationsWidgetConfigItem.vue'
import NotificationsConfigModule from '@/widgets/notifications/modules/NotificationsConfigModule'
import LocalStorageHelper from '@/widgets/notifications/helpers/LocalStorageHelper'

@Component({
  components: { UiNotificationsWidgetConfigItem, QTable, QSeparator },
})
export default class UiNotificationsWidgetConfig extends Vue {
  @Inject('NotificationsConfigModule')
  notificationConfigStore!: NotificationsConfigModule

  pagination = {
    perPage: 0,
  }

  created() {
    const count = LocalStorageHelper.getNotificationsCount()
    const duration = LocalStorageHelper.getDuration()

    if (count) {
      this.notificationConfigStore.setNotificationCount(count)
    }

    if (duration) {
      this.notificationConfigStore.setNotificationDuration(duration)
    }
  }

  get tableData() {
    return [
      {
        type: 'count',
        configName: 'Показывать уведомлений',
      },
      {
        type: 'duration',
        configName: 'Длительность отображения',
      },
    ]
  }

  columns = [
    {
      name: 'configName',
      field: 'configName',
      align: 'left',
      label: 'Настройка',
    },
    { name: 'value', field: 'value', align: 'left', label: 'Значение' },
  ]
}
</script>
