import 'package:flutter/material.dart';
import 'package:tm_app/core/theme/colors.dart';
import 'package:tm_app/core/utils/date_utils.dart';
import 'package:tm_app/core/utils/size_config.dart';
import 'package:tm_app/data/services/model/tender_data/tender_data.dart';
import 'package:tm_app/views/detail/widgets/status_tag.dart';
import 'package:tm_app/views/detail/widgets/tender_detail_info_section.dart';
import 'package:tm_app/views/detail/widgets/tender_document_section.dart';
import 'package:tm_app/views/detail/widgets/tender_location_section.dart';

class TenderDetailHeader extends StatelessWidget {
  final bool isScreenBig;
  final TenderData detail;

  const TenderDetailHeader({
    required this.isScreenBig,
    required this.detail,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.backgroundColor,
        borderRadius: BorderRadius.circular(5),
        border: Border.all(width: 0.5, color: AppColors.grey50),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildDateAndStatus(),
          SizedBox(height: 12.0.h()),
          _buildTitle(),
          SizedBox(height: 10.0.h()),
          Divider(color: AppColors.grey20),
          SizedBox(height: 5.0.h()),
          TenderDetailInfoSection(isScreenBig: isScreenBig, detail: detail),
          TenderLocationSection(detail: detail),
          SizedBox(height: 16.0.h()),
          TenderDocumentSection(detail: detail),
        ],
      ),
    );
  }

  Widget _buildDateAndStatus() => Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
      Text(
        timeConvertor(detail.publicationDate!),
        style: TextStyle(
          color: AppColors.grey60,
          fontWeight: FontWeight.w400,
          fontSize: 12.0.sp(),
        ),
      ),
      StatusTag(
        text: detail.procurementTypeCode ?? '',
        textColor: AppColors.cyanTeal,
        backgroundColor: AppColors.cyanAqua,
      ),
    ],
  );

  Widget _buildTitle() => Text(
    detail.title ?? '',
    style: TextStyle(
      color: AppColors.grey80,
      fontWeight: FontWeight.w600,
      fontSize: 18.0.sp(),
    ),
  );
}
