import 'package:comwell_key_app/up_sales/components/upgrades_counter.dart';
import 'package:comwell_key_app/up_sales/components/upsale_header_media.dart';
import 'package:comwell_key_app/up_sales/models/addon_upgrade.dart';
import 'package:comwell_key_app/up_sales/models/room_upgrade.dart';
import 'package:comwell_key_app/up_sales/models/upgrade.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:flutter/material.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/up_sales/components/comwell_radio_button.dart';
class UpSalesUpgradesWidget extends StatelessWidget {
final double width;
final double height;
final Upgrade upgrade;
final bool isSelected;
final String routeName;
final bool showCounter;
final bool isAddon;
final void Function(Upgrade) onTap;
const UpSalesUpgradesWidget({
super.key,
this.width = 328,
this.height = 268,
required this.upgrade,
this.isSelected = false,
required this.routeName,
this.showCounter = false,
required this.onTap,
this.isAddon = false,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
width: width,
height: height,
margin: const EdgeInsets.only(left: 16, right: 8, top: 8, bottom: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: isSelected == true ? sandColor : colorDivider,
width: 1,
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
children: [
UpsaleHeaderMedia(
height: 180,
animationJson: upgrade is AddOnUpgrade ? (upgrade as AddOnUpgrade).animationJson : null,
backgroundImageUrl: upgrade is AddOnUpgrade ? (upgrade as AddOnUpgrade).backgroundImageUrl : null,
images: upgrade.images.toList(),
shouldHavePadding: false,
),
if (!isAddon && upgrade is RoomUpgrade)
Positioned(
top: 16,
right: 16,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(32),
),
child: Text(
'${(upgrade as RoomUpgrade).roomSize} m2',
style: theme.textTheme.headlineMedium?.copyWith(fontSize: 11),
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(left: 8, right: 8, top: 16, bottom: 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
upgrade.name,
style: theme.textTheme.headlineMedium,
maxLines: 1,
overflow: TextOverflow.visible,
),
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
context.strings.total_charge_value(upgrade.price.toString()),
style: theme.textTheme.headlineMedium,
),
const SizedBox(width: 8),
showCounter
? UpgradesCounter(quantity: upgrade.quantity)
: ComwellRadioButton(
selected: isSelected,
onTap: () {
onTap.call(upgrade);
},
),
],
),
],
),
const SizedBox(height: 8),
Text(
context.strings.read_more_up_sales,
style: theme.textTheme.bodySmall?.copyWith(
color: sandColor[80],
decoration: TextDecoration.underline,
decorationColor: sandColor[80],
),
),
],
),
),
],
),
),
],
),
);
}
}