@extends('layouts.website.website')
@section('content')
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper site-min-height">
            <!-- page start-->
            <div class="col-md-9">
                <section class="panel">
                    <header class="panel-heading">
                        Send Email
                        <div id="templatebar" class="pull-right col-md-6 btn-toolbar">
                            <button class="btn green pull-right" onclick="location.href = 'email/sent'" type="button">
                                Sent Messages
                            </button>
                            <button class="btn green pull-right" onclick="location.href = 'email/manualEmailTemplate'" type="button">
                                Template
                            </button>
                            <button class="btn green pull-right" data-toggle="modal" data-target="#myModal1" type="button">
                                Add Template
                            </button>
                        </div>
                    </header>

                    <div class="panel-body">
                        <form role="form" class="clearfix" action="email/send" method="post">
                            <label class="control-label"> Send Email To </label>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="radio" id="optionsRadios2" value="bloodgroupwise" />
                                    Donor
                                </label>
                            </div>

                            <div class="radio pos_client">
                                <label>
                                    Select Blood Group
                                    <select class="form-control m-bot15" name="bloodgroup" value="">
                                        <option value="A+"> A+ </option>
                                        <option value="A-"> A- </option>
                                        <option value="B+"> B+ </option>
                                        <option value="B-"> B- </option>
                                        <option value="AB+"> AB+ </option>
                                        <option value="AB-"> AB- </option>
                                        <option value="O+"> O+ </option>
                                        <option value="O-"> O- </option>
                                    </select>
                                </label>
                            </div>

                            <div class="radio">
                                <label>
                                    <input type="radio" name="radio" id="optionsRadios2" value="single_patient" />
                                    Single Patient
                                </label>
                            </div>

                            <div class="radio single_patient">
                                <label>
                                    Search Patient Name / ID
                                    <select class="form-control m-bot15" id="patientchoose" name="patient" value="">
                                        <!--<option value="">  </option> -->
                                    </select>
                                </label>
                            </div>

                            <div class="radio">
                                <label>
                                    <input type="radio" name="radio" id="optionsRadios2" value="other" />
                                    Others
                                </label>
                            </div>

                            <div class="radio other">
                                <label> Email Address <input type="email" name="other_email" value="" class="form-control" /> </label>
                            </div>

                            <div class="">
                                <label>
                                    Select Template
                                    <select class="form-control m-bot15" id="selUser5" name="templatess" style="width: 100%;">
                                        <!-- <option value='0'>Select Template</option>-->
                                    </select>
                                </label>
                            </div>

                            <div class="form-group">
                                <label class="control-label">Subject</label>
                                <input type="text" class="form-control" name="subject" rows="10" />
                            </div>

                            <div class="form-group">
                                <label class="control-label">Message</label>
                                <input type="button" name="myBtn" value="{phone}" onClick="addtext(this);" />
                                <input type="button" name="myBtn" value="{email}" onClick="addtext(this);" />
                                <input type="button" name="myBtn" value="{company}" onClick="addtext(this);" />
                                <input type="button" name="myBtn" value="{address}" onClick="addtext(this);" />
                                <input type="button" name="myBtn" value="{name}" onClick="addtext(this);" />
                                <input type="button" name="myBtn" value="{lastname}" onClick="addtext(this);" />
                                <input type="button" name="myBtn" value="{firstname}" onClick="addtext(this);" />
                                <br />
                                <br />
                                <br />
                                <textarea class="ckeditor" id="editor1" name="message" value="" cols="70" rows="10"></textarea>
                            </div>
                            <input type="hidden" name="id" value="" />

                            <div class="form-group col-md-12">
                                <button type="submit" name="submit" class="btn btn-info col-md-3 pull-right"><i class="fa fa-location-arrow"></i> Send Email</button>
                            </div>
                        </form>
                    </div>
                </section>
            </div>
            <!-- page end-->
        </section>
    </section>
    <!--main content end-->

    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">Add New Template</h4>
                </div>
                <div class="modal-body">
                    <form role="form" name="myform1" action="email/addNewManualTemplate" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="exampleInputEmail1"> Template Name</label>
                            <input type="text" class="form-control" name="name" id="exampleInputEmail1" value="" placeholder="" required />
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1"> Message Template</label><br />
                            <input type="button" name="myBtn" value="{phone}" onClick="addtext1(this);" />
                            <input type="button" name="myBtn" value="{email}" onClick="addtext1(this);" />
                            <input type="button" name="myBtn" value="{company}" onClick="addtext1(this);" />
                            <input type="button" name="myBtn" value="{address}" onClick="addtext1(this);" />
                            <input type="button" name="myBtn" value="{name}" onClick="addtext1(this);" />
                            <input type="button" name="myBtn" value="{lastname}" onClick="addtext1(this);" />
                            <input type="button" name="myBtn" value="{firstname}" onClick="addtext1(this);" />
                            <br />
                            <br />
                            <br />

                            <textarea class="ckeditor" id="editor2" name="message" value="" cols="70" rows="10" placeholder="" required> </textarea>
                        </div>
                        <input type="hidden" name="id" value="" />
                        <input type="hidden" name="type" value="email" />
                        <button type="submit" name="submit" class="btn btn-info">Submit</button>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">Send SMS To Voters</h4>
                </div>
                <div class="modal-body">
                    <form role="form" action="email/sendVoterAreaWise" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="exampleInputEmail1">Message</label>
                            <textarea cols="50" rows="10" class="form-control" name="message" id="exampleInputEmail1" value=""> </textarea>
                        </div>
                        <input type="hidden" id="area_id" value="" name="area_id" />
                        <button type="submit" name="submit" class="btn btn-info submit_button">Submit</button>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">Send SMS To All Volunteer</h4>
                </div>
                <div class="modal-body">
                    <form role="form" action="email/sendVolunteer" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="exampleInputEmail1">Message</label>
                            <textarea cols="50" rows="10" class="form-control" name="message" id="exampleInputEmail1" value=""> </textarea>
                        </div>
                        <button type="submit" name="submit" class="btn btn-info submit_button">Submit</button>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">Send SMS To Volunteers</h4>
                </div>
                <div class="modal-body">
                    <form role="form" action="email/sendVolunteerAreaWise" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="exampleInputEmail1">Message</label>
                            <textarea cols="50" rows="10" class="form-control" name="message" id="exampleInputEmail1" value=""> </textarea>
                        </div>
                        <input type="hidden" id="area_idd" value="" name="area_id" />
                        <button type="submit" name="submit" class="btn btn-info submit_button">Submit</button>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $(".voterAW").click(function () {
                $("#area_id").val($(this).attr("data-id"));
                $("#myModal2").modal("show");
            });
            $(".volunteerAW").click(function () {
                $("#area_idd").val($(this).attr("data-id"));
                $("#myModal4").modal("show");
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            $(".pos_client").hide();
            $("input[type=radio][name=radio]").change(function () {
                if (this.value == "bloodgroupwise") {
                    $(".pos_client").show();
                } else {
                    $(".pos_client").hide();
                }
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            $(".single_patient").hide();
            $("input[type=radio][name=radio]").change(function () {
                if (this.value == "single_patient") {
                    $(".single_patient").show();
                } else {
                    $(".single_patient").hide();
                }
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            $(".other").hide();
            $("input[type=radio][name=radio]").change(function () {
                if (this.value == "other") {
                    $(".other").show();
                } else {
                    $(".other").hide();
                }
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            $(".staff").hide();
            $("input[type=radio][name=radio]").change(function () {
                if (this.value == "staff") {
                    $(".staff").show();
                } else {
                    $(".staff").hide();
                }
            });
        });
    </script>
    <script>
        $(document).ready(function () {
            $("#selUser5").select2({
                placeholder: "Select Template",
                allowClear: true,
                // ajax: {
                //     url: "email/getManualEmailTemplateinfo",
                //     type: "post",
                //     dataType: "json",
                //     delay: 250,
                //     data: function (params) {
                //         return {
                //             searchTerm: params.term, // search term
                //         };
                //     },
                //     processResults: function (response) {
                //         return {
                //             results: response,
                //         };
                //     },
                //     cache: true,
                // },
            });
        });
    </script>
    <script>
        $(document).ready(function () {
            $("#selUser5").on("change", function () {
                var iid = $(this).val();
                var type = "email";

                $.ajax({
                    url: "email/getManualEmailTemplateMessageboxText?id=" + iid + "&type=" + type,
                    method: "GET",
                    data: "",
                    dataType: "json",
                }).success(function (response) {
                    CKEDITOR.instances["editor1"].setData(response.user.message);
                    //  $('#myform').find('[name="message"]').val(response.user.message).end();
                });
            });
        });
    </script>
    <script>
        $(document).ready(function () {
            $(".flashmessage").delay(3000).fadeOut(100);
        });
    </script>
    <script>
        function addtext(ele) {
            var fired_button = ele.value;
            var value = CKEDITOR.instances.editor1.getData();
            value += fired_button;

            // console.log(value);
            CKEDITOR.instances["editor1"].setData(value);
            //  console.log(fired_button);
            //document.myform.message.value += fired_button;
        }
    </script>
    <script>
        function addtext1(ele) {
            var fired_button = ele.value;
            var value = CKEDITOR.instances.editor2.getData();
            value += fired_button;

            // console.log(value);
            CKEDITOR.instances["editor2"].setData(value);
        }
    </script>
    <script>
        $(document).ready(function () {
            $("#patientchoose").select2({
                placeholder: "Search Patient Name / ID",
                allowClear: true,
                ajax: {
                    url: "patient/getPatientinfo",
                    type: "post",
                    dataType: "json",
                    delay: 250,
                    data: function (params) {
                        return {
                            searchTerm: params.term, // search term
                        };
                    },
                    processResults: function (response) {
                        return {
                            results: response,
                        };
                    },
                    cache: true,
                },
            });
        });
    </script>



@endsection
