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 AssetDetailBottomSheet extends StatelessWidget {
  Asset? asset;

  AssetDetailBottomSheet(this.asset, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        (asset?.modelDefinition?.assetName?.cleanupWhitespace.capitalizeFirstOfEach ?? "-").heading5(context),
        16.height,
        AspectRatio(
          aspectRatio: 358 / 136,
          child: Container(
            width: 95,
            height: 95,
            decoration: ShapeDecoration(
                color: AppColor.neutral30,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10),
                ),
                image: DecorationImage(
                  fit: BoxFit.cover,
                  image: NetworkImage(asset?.assetPhoto != null ? URLs.getFileUrl(asset!.assetPhoto)! : "https://www.lasteelcraft.com/images/no-image-available.png"),
                )),
          ),
        ),
        16.height,
        Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    "${context.translation.assetNo}: ${asset!.assetNumber}".bodyText(context),
                    "${context.translation.modelName}: ${asset!.modelDefinition?.modelName}".bodyText(context),
                    "${context.translation.supplier}: ${asset!.supplier?.suppliername?.cleanupWhitespace.capitalizeFirstOfEach ?? "-"}".bodyText(context),
                    "${context.translation.manufacture}: ${asset!.modelDefinition?.manufacturerName?.cleanupWhitespace.capitalizeFirstOfEach}".bodyText(context),
                    //"${context.translation.location}: ${assetModel.site.custName?.cleanupWhitespace?.capitalizeFirstOfEach}".bodyText(context),
                  ],
                ).expanded,
                8.width,
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    "${context.translation.snNo}: ${asset!.assetSerialNo}".bodyText(context),
                    "${context.translation.site}: ${asset?.site?.custName?.cleanupWhitespace.capitalizeFirstOfEach ?? "-"}".bodyText(context),
                    "${context.translation.building}: ${asset?.building?.name?.cleanupWhitespace.capitalizeFirstOfEach ?? "-"}".bodyText(context),
                    "${context.translation.floor}: ${asset?.floor?.name?.cleanupWhitespace.capitalizeFirstOfEach ?? "-"}".bodyText(context),
                    "${context.translation.md}: ${asset?.department?.departmentName?.cleanupWhitespace.capitalizeFirstOfEach ?? "-"}".bodyText(context),
                    "${context.translation.room}: ${asset?.room?.value ?? "-"}".bodyText(context),
                  ],
                ).expanded,
              ],
            ),
            8.height,
            if ((asset?.modelDefinition?.assetDescription ?? "").isNotEmpty) ...[
              8.height,
              const Divider(color: AppColor.neutral30, height: 1, thickness: 1),
              8.height,
              asset!.modelDefinition!.assetDescription!.bodyText(context),
            ]
          ],
        )
      ],
    ).paddingAll(16);
  }
}
