2024-12-01 17:20:21 +01:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import {
|
|
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
} from "@/components/ui/alert-dialog";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
2025-01-29 04:39:33 +01:00
|
|
|
import { Input, UrlInput } from "@/components/ui/input";
|
2024-12-01 17:20:21 +01:00
|
|
|
import { Textarea } from "@/components/ui/textarea";
|
2025-07-16 07:48:39 +02:00
|
|
|
import * as m from "~~/paraglide/messages.js";
|
2024-12-01 17:20:21 +01:00
|
|
|
import {
|
|
|
|
|
type ConfirmModalOptions,
|
|
|
|
|
type ConfirmModalResult,
|
|
|
|
|
confirmModalService,
|
|
|
|
|
} from "./composable.ts";
|
|
|
|
|
|
|
|
|
|
const isOpen = ref(false);
|
|
|
|
|
const modalOptions = ref<ConfirmModalOptions>({
|
2024-12-07 22:17:22 +01:00
|
|
|
title: m.antsy_whole_alligator_blink(),
|
2024-12-01 17:20:21 +01:00
|
|
|
message: "",
|
|
|
|
|
inputType: "none",
|
2024-12-07 22:17:22 +01:00
|
|
|
confirmText: m.antsy_whole_alligator_blink(),
|
|
|
|
|
cancelText: m.soft_bold_ant_attend(),
|
2024-12-01 17:20:21 +01:00
|
|
|
});
|
|
|
|
|
const inputValue = ref("");
|
|
|
|
|
const resolvePromise = ref<((result: ConfirmModalResult) => void) | null>(null);
|
|
|
|
|
|
|
|
|
|
function open(options: ConfirmModalOptions): Promise<ConfirmModalResult> {
|
|
|
|
|
isOpen.value = true;
|
2025-01-29 04:39:33 +01:00
|
|
|
isValid.value = false;
|
|
|
|
|
|
2024-12-01 17:20:21 +01:00
|
|
|
modalOptions.value = {
|
2024-12-07 22:17:22 +01:00
|
|
|
title: options.title || m.antsy_whole_alligator_blink(),
|
2024-12-01 17:20:21 +01:00
|
|
|
message: options.message,
|
|
|
|
|
inputType: options.inputType || "none",
|
2024-12-07 22:17:22 +01:00
|
|
|
confirmText: options.confirmText || m.antsy_whole_alligator_blink(),
|
|
|
|
|
cancelText: options.cancelText || m.soft_bold_ant_attend(),
|
2024-12-01 17:20:21 +01:00
|
|
|
};
|
|
|
|
|
inputValue.value = options.defaultValue || "";
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
resolvePromise.value = resolve;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleConfirm() {
|
|
|
|
|
if (resolvePromise.value) {
|
|
|
|
|
resolvePromise.value({
|
|
|
|
|
confirmed: true,
|
|
|
|
|
value: inputValue.value,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
isOpen.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleCancel() {
|
|
|
|
|
if (resolvePromise.value) {
|
|
|
|
|
resolvePromise.value({
|
|
|
|
|
confirmed: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
isOpen.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
confirmModalService.register({
|
|
|
|
|
open,
|
|
|
|
|
});
|
2025-01-29 04:39:33 +01:00
|
|
|
|
|
|
|
|
const isValid = ref(false);
|
2024-12-01 17:20:21 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-12-09 22:32:22 +01:00
|
|
|
<AlertDialog
|
|
|
|
|
:key="String(isOpen)"
|
|
|
|
|
:open="isOpen"
|
|
|
|
|
@update:open="isOpen = false"
|
|
|
|
|
>
|
2026-01-09 22:35:46 +01:00
|
|
|
<AlertDialogContent class="sm:max-w-106.25 flex flex-col">
|
2024-12-01 17:20:21 +01:00
|
|
|
<AlertDialogHeader>
|
|
|
|
|
<AlertDialogTitle>{{ modalOptions.title }}</AlertDialogTitle>
|
|
|
|
|
<AlertDialogDescription v-if="modalOptions.message">
|
|
|
|
|
{{ modalOptions.message }}
|
|
|
|
|
</AlertDialogDescription>
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
|
2025-12-09 22:32:22 +01:00
|
|
|
<Input
|
|
|
|
|
v-if="modalOptions.inputType === 'text'"
|
|
|
|
|
v-model="inputValue"
|
|
|
|
|
/>
|
2024-12-01 17:20:21 +01:00
|
|
|
|
2025-12-09 22:32:22 +01:00
|
|
|
<UrlInput
|
|
|
|
|
v-if="modalOptions.inputType === 'url'"
|
|
|
|
|
v-model="inputValue"
|
|
|
|
|
placeholder="google.com"
|
|
|
|
|
v-model:is-valid="isValid"
|
|
|
|
|
/>
|
2025-01-29 04:39:33 +01:00
|
|
|
|
2025-12-09 22:32:22 +01:00
|
|
|
<Textarea
|
|
|
|
|
v-else-if="modalOptions.inputType === 'textarea'"
|
|
|
|
|
v-model="inputValue"
|
|
|
|
|
rows="6"
|
|
|
|
|
/>
|
2024-12-01 17:20:21 +01:00
|
|
|
|
|
|
|
|
<AlertDialogFooter class="w-full">
|
|
|
|
|
<AlertDialogCancel :as-child="true">
|
|
|
|
|
<Button variant="outline" @click="handleCancel">
|
|
|
|
|
{{ modalOptions.cancelText }}
|
|
|
|
|
</Button>
|
|
|
|
|
</AlertDialogCancel>
|
|
|
|
|
<AlertDialogAction :as-child="true">
|
2025-12-09 22:32:22 +01:00
|
|
|
<Button
|
|
|
|
|
@click="handleConfirm"
|
|
|
|
|
:disabled="!isValid && modalOptions.inputType === 'url'"
|
|
|
|
|
>
|
2024-12-01 17:20:21 +01:00
|
|
|
{{ modalOptions.confirmText }}
|
|
|
|
|
</Button>
|
|
|
|
|
</AlertDialogAction>
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
2025-01-29 04:39:33 +01:00
|
|
|
</template>
|