import 'package:design/design.dart';
import 'package:flutter/material.dart';
import 'package:guru_utils/guru_utils.dart';

part 'banner.g.dart';

@DesignSpec(width: 750, height: 1624)
abstract class AdsBannerDesignSpec implements BasicDesignSpec {
  @SpecSize(SpecWidth(750), SpecOrigin(50))
  Size get mobileBannerSize;

  @SpecSize(SpecWidth(750), SpecOrigin(90))
  Size get padBannerSize;

  Size get bannerSize => GuruUtils.isTablet ? padBannerSize : mobileBannerSize;

  static AdsBannerDesignSpec get() => _AdsBannerDesignSpec.get();
}

class AdsBannerOverlay extends StatefulWidget {
  const AdsBannerOverlay({Key? key}) : super(key: key);

  @override
  State createState() => _AdsBannerOverlayState();
}

class _AdsBannerOverlayState extends State<AdsBannerOverlay> {
  @override
  Widget build(BuildContext context) {
    final designSpec = AdsBannerDesignSpec.get();
    final bannerSize = designSpec.bannerSize;
    return CustomSingleChildLayout(
        delegate: _AdsBannerPositionDelegate(bannerSize),
        child: Material(
          child: SizedBox.fromSize(
            size: bannerSize,
            child: const DecoratedBox(
              decoration: BoxDecoration(color: Colors.red),
            ),
          ),
        ));
  }
}

class _AdsBannerPositionDelegate extends SingleChildLayoutDelegate {
  final Size size;

  _AdsBannerPositionDelegate(this.size);

  @override
  bool shouldRelayout(covariant SingleChildLayoutDelegate oldDelegate) {
    return false;
  }

  @override
  BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
    return BoxConstraints(minHeight: size.height, maxHeight: size.height);
  }

  @override
  Size getSize(BoxConstraints constraints) {
    return size;
  }
}
