import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/presentation/gen/assets.gen.dart';
import 'package:krow/core/presentation/styles/kw_box_decorations.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';

class ShiftKeyResponsibilitiesWidget extends StatelessWidget {
  final String text;

  final bool isExpanded;
  final bool expandable;

  final VoidCallback onTap;

  const ShiftKeyResponsibilitiesWidget(
      {super.key,
      required this.text,
      required this.expandable,
      required this.isExpanded,
      required this.onTap});

  @override
  Widget build(BuildContext context) {
    return AnimatedSize(
      duration: const Duration(milliseconds: 300),
      clipBehavior: Clip.antiAlias,
      alignment: Alignment.topCenter,
      child: Container(
        clipBehavior: Clip.antiAlias,
        height: isExpanded ? null : 40,
        margin: const EdgeInsets.only(top: 8, left: 16, right: 16),
        padding: const EdgeInsets.all(12),
        decoration: KwBoxDecorations.primaryLight12,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            expandable ? expandableTitle() : fixedTitle(),
            const Gap(16),
            Text(
              text,
              style: AppTextStyles.bodySmallReg
                  .copyWith(color: AppColors.blackGray),
            ),
          ],
        ),
      ),
    );
  }

  Widget fixedTitle() {
    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
      Text('${'key_responsibilities'.tr()}:'.toUpperCase(),
          style: AppTextStyles.captionReg
              .copyWith(color: AppColors.blackCaptionText)),
    ]);
  }

  Widget expandableTitle() {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        color: Colors.transparent,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('additional_information'.tr().toUpperCase(),
                    style: AppTextStyles.bodySmallReg
                        .copyWith(color: AppColors.blackGray)),
              ],
            ),
            AnimatedRotation(
                duration: const Duration(milliseconds: 150),
                turns: isExpanded ? -0.5 : 0,
                child: Assets.images.icons.caretDown.svg(
                    width: 16,
                    height: 16,
                    colorFilter: const ColorFilter.mode(
                        AppColors.blackBlack, BlendMode.srcIn))),
          ],
        ),
      ),
    );
  }
}
