// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:wyatt_ui_components/wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/src/components/cards/information_card/widgets/information_card_titles.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';

const _avatarAndTitlesSpacing = 25.0;

class PortfolioCardHeader extends StatelessWidget {
  const PortfolioCardHeader({
    this.logo,
    this.padding,
    this.radius,
    this.projectName,
    this.subtitle,
    this.keyword,
    this.secondaryBackgroundColors,
    super.key,
  });

  final Widget? logo;
  final double? padding;
  final double? radius;
  final TextWrapper? projectName;
  final TextWrapper? subtitle;
  final List<TextWrapper>? keyword;
  final Color? secondaryBackgroundColors;

  @override
  Widget build(BuildContext context) => Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              if (logo != null) logo!,
              const Gap(_avatarAndTitlesSpacing),
              Expanded(
                child: InformationCardTitles(
                  axis: Axis.horizontal,
                  title: projectName,
                  subtitle: subtitle,
                ),
              ),
            ],
          ),
          const Gap(10),
          Wrap(
            children: [
              if (keyword != null)
                ...keyword!.map(
                  (word) => Container(
                    margin: const EdgeInsets.all(3),
                    padding: const EdgeInsets.all(6),
                    decoration: BoxDecoration(
                      color: secondaryBackgroundColors ??
                          Theme.of(context)
                              .extension<CardThemeExtension>()
                              ?.secondaryBackgroundColor,
                      borderRadius: BorderRadius.circular(8),
                    ),
                    child: Text(
                      word.data,
                      style: word.style ?? context.textTheme.bodySmall,
                      textAlign: word.textAlign,
                      textDirection: word.textDirection,
                      softWrap: word.softWrap,
                      overflow: word.overflow,
                      maxLines: word.maxLines,
                      selectionColor: word.selectionColor,
                    ),
                  ),
                ),
            ],
          ),
        ],
      );
}
