import 'package:flutter/material.dart';

import '../../../common/painter/wave_painter.dart';
import '../../../common/theme/theme.dart';

class CustomAppBar extends StatelessWidget {
  final String title;
  final bool isBack;
  const CustomAppBar({super.key, required this.title, this.isBack = true});

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;

    return FlexibleSpaceBar(
      titlePadding: EdgeInsets.only(left: isBack ? 50 : 20, bottom: 16),
      title: Text(
        title,
        style: AppStyle.xl.copyWith(
          color: AppColor.textWhite,
          fontSize: 18,
          fontWeight: FontWeight.w600,
        ),
      ),
      background: Container(
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            colors: AppColor.primaryGradient,
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
          ),
        ),
        child: Stack(
          children: [
            // Static decorative circles (right side)
            Positioned(
              top: -20,
              right: -30,
              child: Container(
                width: 120,
                height: 120,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: AppColor.textWhite.withOpacity(0.08),
                ),
              ),
            ),
            Positioned(
              top: 30,
              right: 20,
              child: Container(
                width: 60,
                height: 60,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: AppColor.textWhite.withOpacity(0.05),
                ),
              ),
            ),

            // Static decorative circles (left side)
            Positioned(
              top: 10,
              left: -20,
              child: Container(
                width: 80,
                height: 80,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: AppColor.textWhite.withOpacity(0.04),
                ),
              ),
            ),

            // Static sparkle icons
            ...List.generate(4, (index) {
              return Positioned(
                left: (index * 90.0) % size.width,
                top: 20 + (index * 25.0),
                child: Icon(
                  Icons.auto_awesome,
                  size: 10 + (index % 3) * 3,
                  color: AppColor.textWhite.withOpacity(0.2),
                ),
              );
            }),

            // Wave pattern (static)
            Positioned.fill(
              child: CustomPaint(
                painter: WavePainter(
                  animation: 0.0,
                  color: AppColor.textWhite.withOpacity(0.1),
                ),
              ),
            ),

            // Gradient overlay for depth
            Container(
              decoration: BoxDecoration(
                gradient: RadialGradient(
                  center: const Alignment(0.3, -0.2),
                  radius: 1.2,
                  colors: [
                    Colors.transparent,
                    AppColor.primaryGradient.first.withOpacity(0.1),
                    Colors.transparent,
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
