2025-02-08 16:10:01 -05:00
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
import TrashCanOutline from '~icons/mdi/trash-can-outline';
|
|
|
|
|
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
|
|
|
|
import type { Collection, Lodging, User } from '$lib/types';
|
|
|
|
|
import { addToast } from '$lib/toasts';
|
|
|
|
|
import { t } from 'svelte-i18n';
|
|
|
|
|
import DeleteWarning from './DeleteWarning.svelte';
|
2025-03-17 10:38:41 -04:00
|
|
|
|
import { LODGING_TYPES_ICONS } from '$lib';
|
2025-02-08 16:10:01 -05:00
|
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
2025-03-17 10:38:41 -04:00
|
|
|
|
function getLodgingIcon(type: string) {
|
|
|
|
|
if (type in LODGING_TYPES_ICONS) {
|
|
|
|
|
return LODGING_TYPES_ICONS[type as keyof typeof LODGING_TYPES_ICONS];
|
|
|
|
|
} else {
|
|
|
|
|
return '🏨';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-10 11:59:56 -04:00
|
|
|
|
function formatDateInTimezone(utcDate: string, timezone?: string): string {
|
|
|
|
|
if (!utcDate) return '';
|
|
|
|
|
try {
|
|
|
|
|
return new Intl.DateTimeFormat(undefined, {
|
|
|
|
|
timeZone: timezone,
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: 'short',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
hour12: true
|
|
|
|
|
}).format(new Date(utcDate));
|
|
|
|
|
} catch {
|
|
|
|
|
return new Date(utcDate).toLocaleString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-08 16:10:01 -05:00
|
|
|
|
export let lodging: Lodging;
|
|
|
|
|
export let user: User | null = null;
|
|
|
|
|
export let collection: Collection | null = null;
|
|
|
|
|
|
|
|
|
|
let isWarningModalOpen: boolean = false;
|
|
|
|
|
|
|
|
|
|
function editTransportation() {
|
|
|
|
|
dispatch('edit', lodging);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let unlinked: boolean = false;
|
|
|
|
|
|
|
|
|
|
$: {
|
|
|
|
|
if (collection?.start_date && collection.end_date) {
|
|
|
|
|
// Parse transportation dates
|
|
|
|
|
let transportationStartDate = lodging.check_in
|
|
|
|
|
? new Date(lodging.check_in.split('T')[0]) // Ensure proper date parsing
|
|
|
|
|
: null;
|
|
|
|
|
let transportationEndDate = lodging.check_out
|
|
|
|
|
? new Date(lodging.check_out.split('T')[0])
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
// Parse collection dates
|
|
|
|
|
let collectionStartDate = new Date(collection.start_date);
|
|
|
|
|
let collectionEndDate = new Date(collection.end_date);
|
|
|
|
|
|
|
|
|
|
// Check if the collection range is outside the transportation range
|
|
|
|
|
const startOutsideRange =
|
|
|
|
|
transportationStartDate &&
|
|
|
|
|
collectionStartDate < transportationStartDate &&
|
|
|
|
|
collectionEndDate < transportationStartDate;
|
|
|
|
|
|
|
|
|
|
const endOutsideRange =
|
|
|
|
|
transportationEndDate &&
|
|
|
|
|
collectionStartDate > transportationEndDate &&
|
|
|
|
|
collectionEndDate > transportationEndDate;
|
|
|
|
|
|
|
|
|
|
unlinked = !!(
|
|
|
|
|
startOutsideRange ||
|
|
|
|
|
endOutsideRange ||
|
|
|
|
|
(!transportationStartDate && !transportationEndDate)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function deleteTransportation() {
|
|
|
|
|
let res = await fetch(`/api/lodging/${lodging.id}`, {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
console.log($t('transportation.transportation_delete_error'));
|
|
|
|
|
} else {
|
|
|
|
|
addToast('info', $t('transportation.transportation_deleted'));
|
|
|
|
|
isWarningModalOpen = false;
|
|
|
|
|
dispatch('delete', lodging.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#if isWarningModalOpen}
|
|
|
|
|
<DeleteWarning
|
2025-02-15 19:44:11 -05:00
|
|
|
|
title={$t('adventures.delete_lodging')}
|
2025-02-08 16:10:01 -05:00
|
|
|
|
button_text="Delete"
|
2025-02-15 19:44:11 -05:00
|
|
|
|
description={$t('adventures.lodging_delete_confirm')}
|
2025-02-08 16:10:01 -05:00
|
|
|
|
is_warning={false}
|
|
|
|
|
on:close={() => (isWarningModalOpen = false)}
|
|
|
|
|
on:confirm={deleteTransportation}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
class="card w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-md xl:max-w-md bg-neutral text-neutral-content shadow-xl"
|
|
|
|
|
>
|
|
|
|
|
<div class="card-body space-y-4">
|
|
|
|
|
<!-- Title and Type -->
|
2025-04-07 01:38:14 +02:00
|
|
|
|
<h2 class="text-2xl font-semibold">{lodging.name}</h2>
|
|
|
|
|
<div>
|
|
|
|
|
<div class="badge badge-secondary">
|
|
|
|
|
{$t(`lodging.${lodging.type}`) + ' ' + getLodgingIcon(lodging.type)}
|
2025-02-08 16:10:01 -05:00
|
|
|
|
</div>
|
2025-04-07 01:38:14 +02:00
|
|
|
|
{#if unlinked}
|
|
|
|
|
<div class="badge badge-error">{$t('adventures.out_of_range')}</div>
|
|
|
|
|
{/if}
|
2025-02-08 16:10:01 -05:00
|
|
|
|
</div>
|
|
|
|
|
|
2025-02-15 19:44:11 -05:00
|
|
|
|
<!-- Location -->
|
2025-02-08 16:10:01 -05:00
|
|
|
|
<div class="space-y-2">
|
|
|
|
|
{#if lodging.location}
|
|
|
|
|
<div class="flex items-center gap-2">
|
2025-02-15 19:44:11 -05:00
|
|
|
|
<span class="font-medium text-sm">{$t('adventures.location')}:</span>
|
|
|
|
|
<p>{lodging.location}</p>
|
2025-02-08 16:10:01 -05:00
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2025-02-15 19:44:11 -05:00
|
|
|
|
{#if lodging.check_in && lodging.check_out}
|
2025-02-08 16:10:01 -05:00
|
|
|
|
<div class="flex items-center gap-2">
|
2025-02-15 19:44:11 -05:00
|
|
|
|
<span class="font-medium text-sm">{$t('adventures.dates')}:</span>
|
|
|
|
|
<p>
|
2025-05-10 11:59:56 -04:00
|
|
|
|
{formatDateInTimezone(lodging.check_in ?? '', lodging.timezone ?? undefined)} –
|
|
|
|
|
{formatDateInTimezone(lodging.check_out ?? '', lodging.timezone ?? undefined)}
|
2025-05-10 13:17:01 -04:00
|
|
|
|
{#if lodging.timezone}
|
|
|
|
|
<span class="text-xs opacity-60 ml-1">({lodging.timezone})</span>
|
|
|
|
|
{/if}
|
2025-02-15 19:44:11 -05:00
|
|
|
|
</p>
|
2025-02-08 16:10:01 -05:00
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2025-02-16 09:35:07 -05:00
|
|
|
|
{#if lodging.user_id == user?.uuid || (collection && user && collection.shared_with && collection.shared_with.includes(user.uuid))}
|
|
|
|
|
{#if lodging.reservation_number}
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<span class="font-medium text-sm">{$t('adventures.reservation_number')}:</span>
|
|
|
|
|
<p>{lodging.reservation_number}</p>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if lodging.price}
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<span class="font-medium text-sm">{$t('adventures.price')}:</span>
|
|
|
|
|
<p>{lodging.price}</p>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{/if}
|
2025-02-08 16:10:01 -05:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Actions -->
|
|
|
|
|
{#if lodging.user_id == user?.uuid || (collection && user && collection.shared_with && collection.shared_with.includes(user.uuid))}
|
|
|
|
|
<div class="card-actions justify-end">
|
|
|
|
|
<button
|
|
|
|
|
class="btn btn-primary btn-sm flex items-center gap-1"
|
|
|
|
|
on:click={editTransportation}
|
|
|
|
|
title="Edit"
|
|
|
|
|
>
|
|
|
|
|
<FileDocumentEdit class="w-5 h-5" />
|
|
|
|
|
<span>{$t('transportation.edit')}</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
on:click={() => (isWarningModalOpen = true)}
|
|
|
|
|
class="btn btn-secondary btn-sm flex items-center gap-1"
|
|
|
|
|
title="Delete"
|
|
|
|
|
>
|
|
|
|
|
<TrashCanOutline class="w-5 h-5" />
|
|
|
|
|
<span>{$t('adventures.delete')}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|