import 'package:flutter/material.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart';
import 'package:test_sa/views/widgets/requests/request_status.dart';

import '../../../models/service_request/search_work_order.dart';

class WorkOrderItem extends StatelessWidget {
  final int index;
  final SearchWorkOrder item;
  final Function(SearchWorkOrder) onPressed;

  const WorkOrderItem({Key key, this.item, this.onPressed, this.index}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Subtitle _subtitle = AppLocalization.of(context).subtitle;
    Color itemColor = index % 2 == 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary;
    Color onItemColor = index % 2 != 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary;

    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4),
      child: ElevatedButton(
        style: ElevatedButton.styleFrom(
          padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
          backgroundColor: itemColor,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)),
          ),
        ),
        onPressed: () {
          onPressed(item);
        },
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        item.callRequest.callNo ?? "-----",
                        style: Theme.of(context).textTheme.headline6.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold),
                      ),
                      Text(
                        item.callRequest.asset.id.toString(),
                        style: Theme.of(context).textTheme.subtitle2.copyWith(
                              color: onItemColor,
                            ),
                      ),
                      Row(
                        children: [
                          Expanded(
                            child: Text(
                              _subtitle.assetName,
                              style: Theme.of(context).textTheme.subtitle2.copyWith(
                                    color: onItemColor,
                                  ),
                            ),
                          ),
                          //if (item.clientName != null)
                          Text(
                            item.callRequest.asset.assetNumber,
                            style: Theme.of(context).textTheme.subtitle2.copyWith(
                                  color: onItemColor,
                                ),
                          ),
                        ],
                      ),
                      Text(
                        item.calllastSituation.name,
                        style: Theme.of(context).textTheme.subtitle2.copyWith(
                              color: onItemColor,
                            ),
                      ),
                      Divider(
                        color: onItemColor,
                      ),
                      Row(
                        children: [
                          Expanded(
                            child: Text(
                              _subtitle.status,
                              style: Theme.of(context).textTheme.subtitle2.copyWith(
                                    color: onItemColor,
                                  ),
                            ),
                          ),
                          if (item.callRequest.status?.id != null) StatusLabel(label: item.callRequest.status.name, color: AColors.getGasStatusColor(item.callRequest.status.id)),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
