part of 'pages.dart';

class AlertPage extends StatefulWidget {
  static const routeName = '/alert_page';

  @override
  _AlertPageState createState() => _AlertPageState();
}

class _AlertPageState extends State<AlertPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: LLSColors.PRIMARY,
        leading: InkWell(
          onTap: () {
            Navigator.pop(context);
          },
          child: Icon(
            CupertinoIcons.back,
            color: LLSColors.WHITE,
          ),
        ),
        title: const Text(
          'Alert',
          style: TextStyle(fontSize: 17),
        ),
        centerTitle: true,
      ),
      body: ListView(
        children: <Widget>[
          const Padding(
            padding: EdgeInsets.only(left: 15, top: 30),
            child: LLSLabel(
              text: 'Basic Alert',
              type: LLSLabelType.typo4,
              dividerWidth: 25,
              dividerColor: LLSColors.SECONDARY,
            ),
          ),
          Column(
            children: [
              LLSButton(
                onPressed: () {
                  LLSAlert.show(context, title: "Data Berhasil disimpan");
                },
                shape: LLSButtonShape.rounded,
                child: Text(
                  'Tap to View'
                ),
                color: LLSColors.PRIMARY
              ),
            ],
          ),

          const Padding(
            padding: EdgeInsets.only(left: 15, top: 30),
            child: LLSLabel(
              text: 'Alert with title and subtitle',
              type: LLSLabelType.typo5,
              dividerWidth: 25,
              dividerColor: LLSColors.SECONDARY,
            ),
          ),
          Column(
            children: [
              LLSButton(
                onPressed: () {
                  LLSAlert.show(context, title: "Success", subtitle: "Data Berhasil disimpan");
                },
                shape: LLSButtonShape.rounded,
                child: Text(
                  'Tap to View'
                ),
                color: LLSColors.PRIMARY
              ),
            ],
          ),

          const Padding(
            padding: EdgeInsets.only(left: 15, top: 30),
            child: LLSLabel(
              text: 'Confirm Dialog',
              type: LLSLabelType.typo5,
              dividerWidth: 25,
              dividerColor: LLSColors.SECONDARY,
            ),
          ),
          Column(
            children: [
              LLSButton(
                onPressed: () {
                  LLSAlert.show(context,
                    title: "Hey you!",
                    subtitle: "Are you sure you want to log out?",
                    style: LLSAlertStyle.confirm,
                    showCancelButton: true,
                    onPress: (bool isConfirm) {
                      if (isConfirm) {
                        LLSAlert.show(context, style: LLSAlertStyle.success , title: "Success!");
                        return false;
                      }
                      return true;
                    }
                  );
                },
                shape: LLSButtonShape.rounded,
                child: Text(
                  'Tap to View'
                ),
                color: LLSColors.PRIMARY
              ),
            ],
          ),

          const Padding(
            padding: EdgeInsets.only(left: 15, top: 30),
            child: LLSLabel(
              text: 'Confirm Dialog with Loading',
              type: LLSLabelType.typo5,
              dividerWidth: 25,
              dividerColor: LLSColors.SECONDARY,
            ),
          ),
          Column(
            children: [
              LLSButton(
                onPressed: () {
                  LLSAlert.show(context,
                    subtitle: "Do you want to delete this data?",
                    style: LLSAlertStyle.confirm,
                    showCancelButton: true,
                    onPress: (bool isConfirm) {
                      if (isConfirm) {
                        LLSAlert.show(context, subtitle: "Loading...", style: LLSAlertStyle.loading);
                        Future.delayed(Duration(seconds: 2),() {
                          LLSAlert.show(context, subtitle: "Success!", style: LLSAlertStyle.success);
                        });
                        return false;
                      }
                      return true;
                    }
                  );
                },
                shape: LLSButtonShape.rounded,
                child: Text(
                  'Tap to View'
                ),
                color: LLSColors.PRIMARY
              ),
            ],
          ),
        ],
      ),
    );
  }
}