import 'package:fis_ui/index.dart';
import 'package:fis_ui/interface/interactive_container.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';

class CustomChildInputOptionWidget extends StatelessWidget {
  final bool isActive;
  final String value;
  final Widget? suffixWidget;
  final VoidCallback onClick;
  final ValueChanged<String> onInputChanged;
  final TextEditingController? textController;

  const CustomChildInputOptionWidget({
    super.key,
    required this.isActive,
    required this.value,
    required this.onClick,
    required this.onInputChanged,
    this.suffixWidget,
    this.textController,
  });

  @override
  Widget build(BuildContext context) {
    return CustomChildOptionWidget(
      isActive: isActive,
      onClick: onClick,
      child: _buildInput(context),
    );
  }

  Widget _buildInput(BuildContext context) {
    final children = <Widget>[];
    children.add(
      FBorderInput(
        controller: textController ?? TextEditingController(text: value),
        textStyle: TextStyle(
          color: isActive ? LabColors.text200 : LabColors.text700,
        ),
        onTap: () {
          onClick.call();
        },
        onChanged: (value) {
          onInputChanged.call(value);
        },
      ),
    );
    if (suffixWidget != null) {
      children.add(suffixWidget!);
    }
    return Row(
      children: children,
      mainAxisAlignment: MainAxisAlignment.center,
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Divider(color: Colors.grey.shade100, height: 1);
  }
}

class CustomChildTextOptionWidget extends StatelessWidget {
  final bool isActive;
  final String text;
  final VoidCallback onClick;

  const CustomChildTextOptionWidget({
    super.key,
    required this.isActive,
    required this.text,
    required this.onClick,
  });

  @override
  Widget build(BuildContext context) {
    return CustomChildOptionWidget(
      child: Text(
        text,
        style: TextStyle(
          color: isActive ? LabColors.text200 : LabColors.text700,
        ),
      ),
      isActive: isActive,
      onClick: onClick,
    );
  }
}

class CustomChildOptionWidget extends StatelessWidget {
  final bool isActive;
  final Widget child;
  final VoidCallback onClick;

  const CustomChildOptionWidget({
    super.key,
    required this.isActive,
    required this.child,
    required this.onClick,
  });

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: Container(
        child: GestureDetector(
          onTap: () {
            onClick.call();
          },
          child: Container(
            padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 18),
            alignment: Alignment.center,
            color: isActive ? LabColors.base600 : LabColors.base200,
            child: child,
          ),
        ),
      ),
    );
  }
}

class FPlaceHolderInteractiveContainer extends FStatelessWidget
    implements FInteractiveContainer {
  const FPlaceHolderInteractiveContainer({super.key});

  @override
  FWidget build(BuildContext context) {
    return const FSizedBox();
  }

  @override
  String get pageName => "";
}
