import 'package:flutter/material.dart';

class ResponsiveLayout extends StatelessWidget {
  final Widget sidebar;
  final Widget body;
  final String title;

  const ResponsiveLayout({
    super.key,
    required this.sidebar,
    required this.body,
    required this.title,
  });

  static const double sidebarBreakpoint = 800;
  static const double sidebarWidth = 240.0;

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

    if (isWide) {
      return Scaffold(
        body: Row(
          children: [
            SizedBox(width: sidebarWidth, child: sidebar),
            Expanded(child: body),
          ],
        ),
      );
    }

    // Narrow: use Drawer
    return Scaffold(
      appBar: AppBar(
        title: Text(
          title,
          style: const TextStyle(fontWeight: FontWeight.w700, fontSize: 18),
        ),
        leading: Builder(
          builder: (ctx) => IconButton(
            icon: const Icon(Icons.menu_rounded),
            onPressed: () => Scaffold.of(ctx).openDrawer(),
          ),
        ),
      ),
      drawer: Drawer(
        width: sidebarWidth,
        child: sidebar,
      ),
      body: body,
    );
  }
}
