import 'package:flutter/material.dart';
import 'package:test_sa/models/lookup.dart';

import '../../../controllers/localization/localization.dart';
import '../../../models/service_request/search_work_order.dart';
import '../../../models/subtitle.dart';
import '../../app_style/colors.dart';
import '../../app_style/sizing.dart';

class WorkOrderDetails extends StatelessWidget {
  final SearchWorkOrder item;
  Lookup assetType;

  WorkOrderDetails({@required this.item, this.assetType, Key key}) : super(key: key);
  Subtitle _subtitle;

  @override
  Widget build(BuildContext context) {
    _subtitle = AppLocalization.of(context).subtitle;
    return Column(
      children: [
        Container(
          padding: EdgeInsets.all(10),
          decoration: BoxDecoration(
            color: AColors.inputFieldBackgroundColor,
            border: Border.all(
              color: Color(0xffefefef),
            ),
            borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
            // boxShadow: const [
            //   AppStyle.boxShadow
            // ]
          ),
          child: Column(
            children: [
              _buildRow(_subtitle.callId, item.callRequest?.id?.toString() ?? "", context),
              _buildRow(_subtitle.assetNumber, item.callRequest?.asset?.assetNumber ?? "", context),
              _buildRow("WO No", item.workOrderNo, context),
              _buildRow(_subtitle.assetName, item.callRequest?.asset?.assetNumber ?? '', context),
              _buildRow(_subtitle.department, item.callRequest?.asset?.department ?? '', context),
              _buildRow(_subtitle.assetSN, item.callRequest?.asset?.assetSerialNo ?? '', context),
              _buildRow(_subtitle.model, item.callRequest?.asset?.modelDefinition?.modelName ?? "", context),
              _buildRow("Manufacturer", item.callRequest?.asset?.modelDefinition?.manufacturerName ?? "", context),
              _buildRow(_subtitle.site, item.callRequest?.asset?.site?.custName ?? "", context),
            ],
          ),
        ),
        const SizedBox(height: 8),
        Container(
          padding: EdgeInsets.all(10),
          height: 55,
          decoration: BoxDecoration(
            color: AColors.inputFieldBackgroundColor,
            border: Border.all(
              color: Color(0xffefefef),
            ),
            borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
          ),
          child: _buildRow("Asset Type", assetType?.name ?? (item.assetType?.name ?? ""), context),
        )
      ],
    );
  }

  Widget _buildRow(String title, String value, BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Text(
          title + " : ",
          style: Theme.of(context).textTheme.subtitle2.copyWith(fontWeight: FontWeight.bold),
        ),
        //if (item.clientName != null)
        Text(
          value,
          style: Theme.of(context).textTheme.subtitle2.copyWith(),
        ),
      ],
    );
  }
}
