import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/enum_extensions.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/modules/asset_delivery_module/pages/history_log_view.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';

class AssetDeliveryStageTabPage extends StatefulWidget {
  String title;
  Widget detailWidget;
  int? tableId;

  AssetDeliveryStageTabPage({
    Key? key,
    required this.title,
    required this.detailWidget,
    this.tableId,
  }) : super(key: key);

  @override
  _AssetDeliveryStageTabPageState createState() {
    return _AssetDeliveryStageTabPageState();
  }
}

class _AssetDeliveryStageTabPageState extends State<AssetDeliveryStageTabPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Theme.of(context).scaffoldBackgroundColor,
        appBar: DefaultAppBar(
          title: widget.title,
        ),
        body: DefaultTabController(
          length: 2,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(left: 16.toScreenWidth, right: 16.toScreenWidth, top: 12.toScreenHeight),
                decoration: BoxDecoration(
                  color: AppColor.tabBarBackground(context),
                  border: Border.all(color: AppColor.tabBarBorder(context)),
                  borderRadius: BorderRadius.circular(20),
                ),
                child: TabBar(
                  padding: EdgeInsets.symmetric(vertical: 4.toScreenHeight, horizontal: 4.toScreenWidth),
                  labelColor: context.isDark ? AppColor.neutral30 : AppColor.black20,
                  unselectedLabelColor: context.isDark ? AppColor.neutral30 : AppColor.black20,
                  unselectedLabelStyle: AppTextStyles.bodyText,
                  labelStyle: AppTextStyles.bodyText,
                  indicatorPadding: EdgeInsets.zero,
                  indicatorSize: TabBarIndicatorSize.tab,
                  dividerColor: Colors.transparent,
                  overlayColor: WidgetStateProperty.all(Colors.transparent),
                  indicator: BoxDecoration(
                      color: AppColor.background(context),
                      borderRadius: BorderRadius.circular(15),
                      boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 5, offset: const Offset(0, 0), spreadRadius: 0)]),
                  tabs: [
                    Tab(text: context.translation.details, height: 57.toScreenHeight),
                    Tab(text: context.translation.historyLogs, height: 57.toScreenHeight),
                  ],
                ),
              ),
              // 12.height,
              TabBarView(
                children: [
                  widget.detailWidget,
                  AssetDeliveryHistoryLogView(
                    tableItemId: widget.tableId,
                  ),
                ],
              ).expanded,
            ],
          ),
        ));
  }

  String getPageTitle({AssetDeliveryStageEnum? deliveryStage}) {
    if (deliveryStage == AssetDeliveryStageEnum.deliveryInspection) {
      return 'Delivery Inspection'.addTranslation;
    }
    if (deliveryStage == AssetDeliveryStageEnum.technicalInspection) {
      return 'Technical Inspection'.addTranslation;
    }
    if (deliveryStage == AssetDeliveryStageEnum.endUserAcceptance) {
      return 'End-User Acceptance'.addTranslation;
    } else {
      return 'Details'.addTranslation;
    }
  }
}
