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';

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

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

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          width: 95,
          height: 95,
          decoration: ShapeDecoration(
              color: context.isDark ? AppColor.neutral50 : AppColor.neutral30,
              shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
              image: DecorationImage(
                fit: BoxFit.cover,
                image: NetworkImage(device.assetPhoto != null ? URLs.getFileUrl(device.assetPhoto!)! : "https://www.lasteelcraft.com/images/no-image-available.png"),
              )),
        ),
        15.width,
        Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                device.modelDefinition!.assetName!.cleanupWhitespace.capitalizeFirstOfEach.heading6(context),
                8.height,
                "${context.translation.assetNumber} : ${device.assetNumber}".bodyText(context),
                "${context.translation.modelName} : ${device.modelDefinition!.modelName}".cleanupWhitespace.capitalizeFirstOfEach.bodyText(context),
              ],
            ),
            Row(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                "${context.translation.serialNo} : ${device.assetSerialNo}".bodyText(context).expanded,
                4.width,
                selectButton ?? Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text(
                      context.translation.viewDetails,
                      style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)),
                    ),
                    4.width,
                    Icon(
                      Icons.arrow_forward,
                      color: AppColor.blueStatus(context),
                      size: 14,
                    )
                  ],
                ),
              ],
            )
          ],
        ).expanded
      ],
    ).toShadowContainer(context,padding: 12).onPress(() => onPressed(device));
  }
}
