import 'package:flutter/material.dart';

import 'package:pweb/controllers/payouts/multiple_payouts.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/panels/source_quote/widget.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/panels/upload_panel/widget.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/sections/upload_csv/panel_card.dart';


class UploadCsvLayout extends StatelessWidget {
  const UploadCsvLayout({super.key, required this.controller});

  final MultiplePayoutsController controller;

  @override
  Widget build(BuildContext context) {
    final hasFile = controller.selectedFileName != null;
    return LayoutBuilder(
      builder: (context, constraints) {
        final useHorizontal = constraints.maxWidth >= 760;
        if (!useHorizontal) {
          return Column(
            children: [
              PanelCard(child: UploadPanel(controller: controller)),
              if (hasFile) ...[
                const SizedBox(height: 12),
                SourceQuotePanel(controller: controller),
              ],
            ],
          );
        }

        if (!hasFile) {
          return PanelCard(child: UploadPanel(controller: controller));
        }

        return IntrinsicHeight(
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Expanded(
                flex: 3,
                child: PanelCard(child: UploadPanel(controller: controller)),
              ),
              const SizedBox(width: 12),
              Expanded(
                flex: 5,
                child: SourceQuotePanel(controller: controller),
              ),
            ],
          ),
        );
      },
    );
  }
}
