import 'package:flutter/material.dart';
import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/device/asset.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/views/widgets/item_views/info_header_widget.dart';
import 'package:test_sa/views/widgets/item_views/info_text_widget.dart';

class AssetItemListView extends StatelessWidget {
  final Asset device;
  final Function(Asset) onPressed;
  final Widget? selectButton;
  final bool isSelected;

  const AssetItemListView({Key? key, required this.device, required this.onPressed, this.selectButton, this.isSelected = false}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          width: 95,
          height: 95,
          decoration: ShapeDecoration(
              color: AppColor.dropDownBackground(context),
              shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10), side: BorderSide(color: AppColor.border2Color(context))),
              image: DecorationImage(
                fit: BoxFit.cover,
                image: NetworkImage(device.assetPhoto != null ? URLs.getFileUrl(device.assetPhoto!)! : "https://www.lasteelcraft.com/images/no-image-available.png"),
              )),
        ),
        12.width,
        Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                InfoHeaderWidget(device.modelDefinition!.assetName!.cleanupWhitespace),
                // device.modelDefinition!.assetName!.cleanupWhitespace.capitalizeFirstOfEach.heading6(context),
                if (context.userProvider.isEngineer && !(device.hasTrainingImageData ?? true)) ...[
                  2.height,
                  Text(
                    '*Upload Images for this asset',
                    style: AppTextStyles.tinyFont2.copyWith(color: AppColor.red30),
                  ),
                ],
                4.height,
                InfoTextWidget(label: context.translation.assetNumber, value: device.assetNumber),
                InfoTextWidget(label: context.translation.modelName, value: device.modelDefinition!.modelName),
                InfoTextWidget(label: context.translation.serialNo, value: device.assetSerialNo),
                // "${context.translation.assetNumber} : ${device.assetNumber}".bodyText(context),
                // "${context.translation.modelName} : ${device.modelDefinition!.modelName}".cleanupWhitespace.capitalizeFirstOfEach.bodyText(context),
              ],
            ),
            Align(
                alignment: Alignment.bottomRight,
                child: selectButton ??
                    Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text(
                          context.translation.viewDetails,
                          style: AppTextStyles.bodyText2.copyWith(color: AppColor.primary10),
                        ),
                        4.width,
                        const Icon(Icons.arrow_forward, color: AppColor.primary10, size: 14)
                      ],
                    ))
          ],
        ).expanded
      ],
    ).toShadowContainer(context, borderColor: isSelected ? AppColor.primary10 : Colors.transparent).onPress(() => onPressed(device));
  }
}
