<commit_before><!--
  - @copyright 2018 <NAME> <<EMAIL>>
  -
  - @author 2018 <NAME> <<EMAIL>>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->

<template>
	<div class="attachment" @click="download">
		<img v-if="isImage" class="mail-attached-image" :src="url" />
		<img class="attachment-icon" :src="mimeUrl" />
		<span class="attachment-name" :title="label"
			>{{ fileName }}
			<span class="attachment-size">({{ humanReadable(size) }})</span>
		</span>
		<button
			v-if="isCalendarEvent"
			class="button attachment-import calendar"
			:class="{'icon-add': !loadingCalendars, 'icon-loading-small': loadingCalendars}"
			:disabled="loadingCalendars"
			:title="t('mail', 'Import into calendar')"
			@click.stop="loadCalendars"
		></button>
		<button class="button icon-download attachment-download" :title="t('mail', 'Download attachment')"></button>
		<button
			class="attachment-save-to-cloud"
			:class="{'icon-folder': !savingToCloud, 'icon-loading-small': savingToCloud}"
			:disabled="savingToCloud"
			:title="t('mail', 'Save to Files')"
			@click.stop="saveToCloud"
		></button>
		<div
			v-on-click-outside="closeCalendarPopover"
			class="popovermenu bubble attachment-import-popover hidden"
			:class="{open: showCalendarPopover}"
		>
			<PopoverMenu :menu="calendarMenuEntries" />
		</div>
	</div>
</template>

<script>
import {formatFileSize} from '@nextcloud/files'
import {mixin as onClickOutside} from 'vue-on-click-outside'
import {getFilePickerBuilder} from '@nextcloud/dialogs'
import PopoverMenu from '@nextcloud/vue/dist/Components/PopoverMenu'

import {parseUid} from '../util/EnvelopeUidParser'
import Logger from '../logger'

import {downloadAttachment, saveAttachmentToFiles} from '../service/AttachmentService'
import {getUserCalendars, importCalendarEvent} from '../service/DAVService'

export default {
	name: 'MessageAttachment',
	components: {
		PopoverMenu,
	},
	mixins: [onClickOutside],
	props: {
		id: {
			type: Number,
			required: true,
		},
		fileName: {
			type: String,
			required: true,
		},
		url: {
			type: String,
			required: true,
		},<commit_msg>Fix Vue attachment id prop type<commit_after><!--
  - @copyright 2018 <NAME> <<EMAIL>>
  -
  - @author 2018 <NAME> <<EMAIL>>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->

<template>
	<div class="attachment" @click="download">
		<img v-if="isImage" class="mail-attached-image" :src="url" />
		<img class="attachment-icon" :src="mimeUrl" />
		<span class="attachment-name" :title="label"
			>{{ fileName }}
			<span class="attachment-size">({{ humanReadable(size) }})</span>
		</span>
		<button
			v-if="isCalendarEvent"
			class="button attachment-import calendar"
			:class="{'icon-add': !loadingCalendars, 'icon-loading-small': loadingCalendars}"
			:disabled="loadingCalendars"
			:title="t('mail', 'Import into calendar')"
			@click.stop="loadCalendars"
		></button>
		<button class="button icon-download attachment-download" :title="t('mail', 'Download attachment')"></button>
		<button
			class="attachment-save-to-cloud"
			:class="{'icon-folder': !savingToCloud, 'icon-loading-small': savingToCloud}"
			:disabled="savingToCloud"
			:title="t('mail', 'Save to Files')"
			@click.stop="saveToCloud"
		></button>
		<div
			v-on-click-outside="closeCalendarPopover"
			class="popovermenu bubble attachment-import-popover hidden"
			:class="{open: showCalendarPopover}"
		>
			<PopoverMenu :menu="calendarMenuEntries" />
		</div>
	</div>
</template>

<script>
import {formatFileSize} from '@nextcloud/files'
import {mixin as onClickOutside} from 'vue-on-click-outside'
import {getFilePickerBuilder} from '@nextcloud/dialogs'
import PopoverMenu from '@nextcloud/vue/dist/Components/PopoverMenu'

import {parseUid} from '../util/EnvelopeUidParser'
import Logger from '../logger'

import {downloadAttachment, saveAttachmentToFiles} from '../service/AttachmentService'
import {getUserCalendars, importCalendarEvent} from '../service/DAVService'

export default {
	name: 'MessageAttachment',
	components: {
		PopoverMenu,
	},
	mixins: [onClickOutside],
	props: {
		id: {
			type: String,
			required: true,
		},
		fileName: {
			type: String,
			required: true,
		},
		url: {
			type: String,
			required: true,
		},
{'fraction_non_alphanumeric': 0.1397006414825374, 'fraction_numerical': 0.003563791874554526, 'mean_word_length': 4.187615526802218, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6184804', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1738, 'n_words': 505}