import 'package:comwell_key_app/common/components/comwell_error_widget.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class ShareBookingBaseTemplate extends StatelessWidget {
final Booking booking;
final bool isShared;
final void Function() onClicked;
final bool isLoading;
final Error? error;
const ShareBookingBaseTemplate({
super.key,
required this.booking,
required this.onClicked,
required this.isShared,
required this.isLoading,
this.error,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
backgroundColor: sandColor,
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
if (error != null)
TweenAnimationBuilder<double>(
tween: Tween<double>(begin: -1.0, end: 0.0),
duration: const Duration(milliseconds: 400),
curve: Curves.easeOutCubic,
builder: (context, value, child) {
return Transform.translate(
offset: Offset(0, value * 200),
child: Opacity(
opacity: 1.0 + value,
child: child,
),
);
},
child: Padding(
padding: const EdgeInsets.only(top: 40.0),
child: error != null
? ComwellErrorWidget(
title: context.strings.share_booking_page_error_title,
subtitle: context.strings.share_booking_page_error_subtitle,
border: true,
small: true,
)
: const SizedBox.shrink(),
),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const SizedBox(width: 52),
Text(
isShared
? context.strings.received_shared_booking_page_title
: context.strings.share_booking_page_title,
style: theme.textTheme.titleMedium?.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
Padding(
padding: const EdgeInsets.only(right: 16),
child: isShared
? const SizedBox.shrink()
: ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
},
style: ElevatedButton.styleFrom(
minimumSize: const Size(36, 36),
padding: EdgeInsets.zero,
backgroundColor: Theme.of(context).colorScheme.surface,
shape: const CircleBorder(),
elevation: 0,
),
child: Icon(
Icons.close,
color: Theme.of(context).colorScheme.onSurface,
size: 24,
),
),
),
],
),
),
Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: [
Image.asset(
'assets/images/booking_background.png',
height: 450,
width: 330,
fit: BoxFit.cover,
),
Positioned(
top: 16,
left: 16,
child: Text(
booking.hotelName,
style: theme.textTheme.headlineLarge?.copyWith(
color: Theme.of(context).colorScheme.surface,
),
),
),
Positioned(
bottom: 16,
left: 16,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
DateFormat('d. MMM').format(booking.startDate),
style: theme.textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.surface,
),
),
Icon(
Icons.arrow_forward,
size: 16,
color: Theme.of(context).colorScheme.surface,
),
Text(
DateFormat('d. MMM').format(booking.endDate),
style: theme.textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.surface,
),
),
],
),
Text(
'${booking.guests.length} ${booking.guests.length > 1 ? context.strings.guests : context.strings.guest}',
style: theme.textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.surface.withValues(alpha: 0.7),
),
),
],
),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Text(
isShared
? context.strings.received_shared_booking_page_subtitle(
"${booking.firstName} ${booking.lastName}",
)
: context.strings.share_booking_page_subtitle,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.surface.withValues(alpha: 0.8),
),
textAlign: TextAlign.center,
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: onClicked,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.surface,
minimumSize: const Size.fromHeight(52),
elevation: 0,
),
child: isLoading
? const CircularProgressIndicator(
color: sandColor,
backgroundColor: colorTertiary,
strokeWidth: 2,
)
: Text(
isShared
? context.strings.generic_ok
: context.strings.share_booking_page_share_button,
style: theme.textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
),
),
),
),
],
),
);
}
}