import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rasadyar_core/presentation/common/app_color.dart';
import 'package:rasadyar_core/presentation/common/app_fonts.dart';

import 'new_tab.dart';

class CupertinoSegmentedControlDemo extends StatefulWidget {
  const CupertinoSegmentedControlDemo({super.key});

  @override
  State<CupertinoSegmentedControlDemo> createState() =>
      _CupertinoSegmentedControlDemoState();
}

class _CupertinoSegmentedControlDemoState
    extends State<CupertinoSegmentedControlDemo> {
  int _selectedSegment = 0;

  // The data for the segments
  final Map<int, Widget> _segments = const {
    0: Text('Segment 1'),
    1: Text('Segment 2'),
    2: Text('Segment 3'),
  };

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          CupertinoSlidingSegmentedControl<int>(
            children: _segments,
            groupValue: _selectedSegment,

            onValueChanged: (int? value) {
              setState(() {
                _selectedSegment = value!;
              });
            },
          ),
          const SizedBox(height: 20),
          Text(
            'Selected Segment: ${_selectedSegment + 1}',
            style: const TextStyle(fontSize: 24),
          ),
        ],
      ),
    );
  }
}

class CupertinoSegmentedControlDemo2 extends StatefulWidget {
  const CupertinoSegmentedControlDemo2({super.key});

  @override
  State<CupertinoSegmentedControlDemo2> createState() =>
      _CupertinoSegmentedControlDemoState2();
}

class _CupertinoSegmentedControlDemoState2
    extends State<CupertinoSegmentedControlDemo2> {
  int _selectedSegment = 0;

  // The data for the segments
  final Map<int, Widget> _segments = {
    0:Container(
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(50)
      ),
      child: Text('لاشه', style: AppFonts.yekan13),
    ),
    1: Container(
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(50)
      ),
      child: Text('زنده', style: AppFonts.yekan13),
    ),
  };

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          NewCupertinoSegmentedControl<int>(
            padding: EdgeInsetsDirectional.symmetric(
              horizontal: 20,
              vertical: 10,
            ),
            children: _segments,
            groupValue: _selectedSegment,
            selectedColor: AppColor.blueNormal,
            unselectedColor: Colors.white,
            borderColor: Colors.grey.shade300,
            onValueChanged: (int value) {
              setState(() {
                _selectedSegment = value;
              });
            },
          ),
          const SizedBox(height: 20),
          Text(
            'Selected Segment: ${_selectedSegment + 1}',
            style: const TextStyle(fontSize: 24),
          ),
        ],
      ),
    );
  }
}
