<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="mail-message-attachments">
		<div class="attachments">
			<MessageAttachment v-for="attachment in attachments"
							   :key="attachment.id"
							   :id="attachment.id"
							   :fileName="attachment.fileName"
							   :size="attachment.size"
							   :url="attachment.downloadUrl"
							   :isImage="attachment.isImage"
							   :isCalendarEvent="attachment.isCalendarEvent"
							   :mimeUrl="attachment.mimeUrl"/>
		</div>
		<p v-if="moreThanOne">
			<button class="attachments-save-to-cloud"
					:class="{'icon-folder' : !savingToCloud, 'icon-loading-small' : savingToCloud}"
					:disabled="savingToCloud"
					v-on:click="saveAll">
				{{ t('mail', 'Save all to Files') }}
			</button>
		</p>
	</div>
</template>

<script>
	import MessageAttachment from './MessageAttachment'
	import {parseUid} from '../util/EnvelopeUidParser'
	import {saveAttachmentsToFiles} from '../service/AttachmentService'

	export default {
		name: "MessageAttachments",
		components: {
			MessageAttachment
		},
		props: {
			attachments: Array,
		},
		data () {
			return {
				savingToCloud: false,
			}
		},
		computed: {
			moreThanOne () {
				return this.attachments.length > 1
			}
		},
		methods: {
			saveAll () {
				const pickDestination = () => {
					return new Promise((res, rej) => {
						OC.dialogs.filepicker(
							t('mail', 'CChoose a folder to store the attachments in'),
							res,
							false,
							'httpd/unix-directory',
							true
						)
					})
				}
				const saveAttachments = (accountId, folderId, messageId) => directory => {
					return saveAttachmentsToFiles(
						accountId,
						folderId,
						messageId,
						directory
					)
				}
				const {accountId, folderId, id} = parseUid(this.$route.params.messageUid)

				return pickDestination()<commit_msg>Fix typo in attachments button<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="mail-message-attachments">
		<div class="attachments">
			<MessageAttachment v-for="attachment in attachments"
							   :key="attachment.id"
							   :id="attachment.id"
							   :fileName="attachment.fileName"
							   :size="attachment.size"
							   :url="attachment.downloadUrl"
							   :isImage="attachment.isImage"
							   :isCalendarEvent="attachment.isCalendarEvent"
							   :mimeUrl="attachment.mimeUrl"/>
		</div>
		<p v-if="moreThanOne">
			<button class="attachments-save-to-cloud"
					:class="{'icon-folder' : !savingToCloud, 'icon-loading-small' : savingToCloud}"
					:disabled="savingToCloud"
					v-on:click="saveAll">
				{{ t('mail', 'Save all to Files') }}
			</button>
		</p>
	</div>
</template>

<script>
	import MessageAttachment from './MessageAttachment'
	import {parseUid} from '../util/EnvelopeUidParser'
	import {saveAttachmentsToFiles} from '../service/AttachmentService'

	export default {
		name: "MessageAttachments",
		components: {
			MessageAttachment
		},
		props: {
			attachments: Array,
		},
		data () {
			return {
				savingToCloud: false,
			}
		},
		computed: {
			moreThanOne () {
				return this.attachments.length > 1
			}
		},
		methods: {
			saveAll () {
				const pickDestination = () => {
					return new Promise((res, rej) => {
						OC.dialogs.filepicker(
							t('mail', 'Choose a folder to store the attachments in'),
							res,
							false,
							'httpd/unix-directory',
							true
						)
					})
				}
				const saveAttachments = (accountId, folderId, messageId) => directory => {
					return saveAttachmentsToFiles(
						accountId,
						folderId,
						messageId,
						directory
					)
				}
				const {accountId, folderId, id} = parseUid(this.$route.params.messageUid)

				return pickDestination()
{'fraction_non_alphanumeric': 0.11974474474474474, 'fraction_numerical': 0.004129129129129129, 'mean_word_length': 2.825556353194544, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2749153', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1599, 'n_words': 461}