import 'dart:convert';

import 'package:flutter/material.dart';

import 'package:pshared/models/file/downloaded_file.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/sections/sample/data.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/sections/sample/download_button.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/sections/sample/header.dart';
import 'package:pweb/pages/dashboard/payouts/multiple/sections/sample/table.dart';
import 'package:pweb/utils/download.dart';


class FileFormatSampleSection extends StatelessWidget {
  const FileFormatSampleSection({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        FileFormatSampleHeader(),
        const SizedBox(height: 12),
        FileFormatSampleTable(rows: sampleRows),
        const SizedBox(height: 10),
        FileFormatSampleDownloadButton(onPressed: _downloadSampleCsv),
      ],
    );
  }

  Future<void> _downloadSampleCsv() async {
    await downloadFile(
      DownloadedFile(
        bytes: utf8.encode(buildSampleCsvContent()),
        filename: sampleFileName,
        mimeType: 'text/csv;charset=utf-8',
      ),
    );
  }
}
