
<?php

$Money='<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 24 24" width="50" height="50" style="&#10;    fill: #529ffd;&#10;"><path d="M21,6H5c-.859,0-1.672-.372-2.235-.999,.55-.614,1.349-1.001,2.235-1.001H23c.553,0,1-.448,1-1s-.447-1-1-1H5C2.239,2,0,4.239,0,7v10c0,2.761,2.239,5,5,5H21c1.657,0,3-1.343,3-3V9c0-1.657-1.343-3-3-3Zm1,13c0,.551-.448,1-1,1H5c-1.654,0-3-1.346-3-3V6.998c.854,.639,1.904,1.002,3,1.002H21c.552,0,1,.449,1,1v10Zm-2-5c0,.552-.448,1-1,1s-1-.448-1-1,.448-1,1-1,1,.448,1,1Z" style="&#10;&#10;"/></svg>';
$view='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="40" width="40" version="1.1" viewBox="0 0 512 512" enable-background="new 0 0 512 512" style="&#10;    fill: #529ffd;&#10;"> <g> <path d="m494.8,241.4l-50.6-49.4c-50.1-48.9-116.9-75.8-188.2-75.8s-138.1,26.9-188.2,75.8l-50.6,49.4c-11.3,12.3-4.3,25.4 0,29.2l50.6,49.4c50.1,48.9 116.9,75.8 188.2,75.8s138.1-26.9 188.2-75.8l50.6-49.4c4-3.8 11.7-16.4 0-29.2zm-238.8,84.4c-38.5,0-69.8-31.3-69.8-69.8 0-38.5 31.3-69.8 69.8-69.8 38.5,0 69.8,31.3 69.8,69.8 0,38.5-31.3,69.8-69.8,69.8zm-195.3-69.8l35.7-34.8c27-26.4 59.8-45.2 95.7-55.4-28.2,20.1-46.6,53-46.6,90.1 0,37.1 18.4,70.1 46.6,90.1-35.9-10.2-68.7-29-95.7-55.3l-35.7-34.7zm355,34.8c-27,26.3-59.8,45.1-95.7,55.3 28.2-20.1 46.6-53 46.6-90.1 0-37.2-18.4-70.1-46.6-90.1 35.9,10.2 68.7,29 95.7,55.4l35.6,34.8-35.6,34.7z"/> </g> </svg>';
?>
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">-->
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.min.css">-->
<style>
    .custom-as {
        border-radius: 15px;
    }

    .custom-as .name {
        display: inline-block;
        text-align: center;
        font-size: 1.3rem;
        color: #fff;
        margin-right: 10px;
    }

    .custom-as .card-body-custom img {
        width: 140px;
        clip-path: circle(50%);
        /* clip-path: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%); */
        /* margin: 0 auto 10px; */
        display: inline-block;
    }

    .custom-as .cost {
        padding: 10px 0px 10px 10px;
        display: block;
        font-weight: bold;
        text-shadow: 0 0 white;
        border-bottom: 1px solid;
    }

    .canvas-profile-doctor {
        /* background: #c6edd4; */
        background: linear-gradient(to bottom, #3770e7, #9bb0da);
        padding: 20px;
        border-radius: 10px;
    }

    span.tahsilat {
        font-size: 14px;
        text-align: right;
        margin-top: 10px;
    }

    .list-item-counsultant {
        display: flex;
        align-items: center;
        justify-content: space-around;
    }

    .item-user-counsultant {
        font-size: 1.2rem;
        color: #529ffd;
        padding: 20px 60px;
        border-radius: 10px;
        box-shadow: 0 2px 5px #00000024;
        margin: 20px;
        width: 50%;
    }
    .item-user-counsultant > div {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
}

span.toman,
span.view-name {
    font-size: 0.8rem;
    color: #529ffd;
}
.item-user-counsultant svg {
    margin-bottom: 10px;
}
span.name-consultant {
    text-align: right;
}

.about-counsultant {
    padding: 20px;
    text-align: justify;
    font-size: 0.9rem;
    color: #6c6c6c;
}
.button-eram {
    padding: 10px;
    border-radius: 10px;
    margin: 0 5px;
}

.button-eram-start {
    background: #53b953;
    color: #fff;
}
.button-eram-next {
    background: #63b2c5;
    color: #fff;
}

.owl-stage
{
    padding: unset !important;
}

</style>

<?php
//echo '<pre>';
//var_dump($emergency_consultant_plan);
//echo '</pre>';
//exit();
$cbUserIns = &CBuser::getInstance((int)$emergency_consultant_id);
$consultant_user = $cbUserIns->getUserData();
$consultant_name = $consultant_user->get('name');
// dump ($consultant_user,'consultant_user')

// $number = 20000;
// echo number_format ($number , 3 , "," , "," );

?>



    <style>
        .owl-carousel .f{
            /*width: 400px;*/
        }
    </style>
    <div class="container">
        <div class="row">
            <div class="col-md-6 offset-md-3">
<!--            <div class="owl-carousel"  style="direction: ltr">-->

                <div id="carouselExampleIndicators" class="carousel slide">


                    <div class="carousel-inner">

                        <div class="carousel-item active">
                                <div class="card custom-as" data-consultantid="<?=$emergency_consultant_id; ?>" style="direction: rtl">
                                    <div class="card-body-custom">
                                        <!-- avatar consultant -->
                                        <div class="align-items-center canvas-profile-doctor d-flex gap-3">
                                            <img src='/images/comprofiler/<?php echo $consultant_user->get('avatar'); ?>'>
                                            <div class="card-title d-flex flex-column mb-3 name">
                                                <span class="name-consultant"><?= $consultant_name; ?></span>
                                                <span class="tahsilat"><?php echo $consultant_user->get('cb_tahsilat'); ?></span>
                                            </div>

                                        </div>
                                        <div class="list-item-counsultant">
                                            <div class="item-user-counsultant">
                                                <div>
                                                    <?php //echo $Money; ?>
                                                    <span class="Money-counsultant txt-item-consultant"><?php echo $emergency_consultant_plan->price; ?></span>
                                                    <span class="toman">تومان</span>
                                                </div>
                                            </div>
                                            <div class="item-user-counsultant">
                                                <div>
                                                    <?php //echo $view; ?>
                                                    <span class="view-users txt-item-consultant"><?php echo $consultant_user->get('hits'); ?></span>
                                                    <span class="view-name">بازدید</span>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- Consultant fee -->
                                        <div class="mb-2 about-counsultant">
                                            <span>تخصص</span>
                                            <!-- About the teacher -->
                                            <?php echo $consultant_user->get('cb_aboutme'); ?>
                                        </div>
                                        <!-- <div class="card-subtitle text-muted mb-4">مشاوره اورژانسی؛ زمینه </div> -->

                                        <div style="text-align: center">
                                            <form action="" method="post">
                                                <input type="hidden" name="start_url" value="<?= JRoute::_('index.php?option=com_reservation&view=firstqst&uid=' . $emergency_consultant_id . '&pid=' . $emergency_consultant_plan->id . '', false); ?>">
                                                <input type="hidden" name="step_2" value="true">
                                                <input type="hidden" name="selectedConsultant" value="<?= $emergency_consultant_id; ?>">
                                                <button class="button-eram button-eram-start" type="submit" name="do" value="start">شروع مشاوره</button>
                                                <button class="button-eram button-eram-next" type="submit" name="do" value="find_next">یافتن مشاور بعدی</button>
                                                <button class="button-eram" type="submit" name="do" value="cancel">ثبت مجدد درخواست</button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                        </div>




                    </div>
                    <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
                        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                        <span class="visually-hidden">Previous</span>
                    </button>
                    <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
                        <span class="carousel-control-next-icon" aria-hidden="true"></span>
                        <span class="visually-hidden">Next</span>
                    </button>

                    <div class="carousel-indicators" style="margin-bottom: -30px; flex-direction: row-reverse">
                        <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1" style="position:relative;">
                            <img src='/images/comprofiler/<?php echo $consultant_user->get('avatar'); ?>' style="position: absolute; right: 0">
                        </button>

                    </div>

                </div>

<!--            </div>-->
            </div>

        </div>
    </div>

<div class="spinner-parent">
    <div class="spinner-border" role="status" style="display: none">
        <span class="visually-hidden">Loading...</span>
    </div>
</div>



<style>

    .emergency-spinner
    {
        overflow: hidden;
    }

    .emergency-spinner .spinner-parent
    {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        background: #fff;
        left: 0;
        display: flex;
        justify-content: center;
        z-index: 100;
    }
    .emergency-spinner .spinner-parent > div
    {
        align-self: center;
        display: block !important;
    }

    /*.custom-carousel-control-next*/
    /*{*/
    /*    background: red !important;*/
    /*}*/

    /*.custom-carousel-control-prev*/
    /*{*/
    /*    background: red !important;*/
    /*}*/

    .carousel-control-next, .carousel-control-prev
    {
        background: #ccc ;
    }

</style>

<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>-->
<script>

    jQuery(document).ready(function($){

        // $('.carousel button').click(function (e){
        //
        //     e.preventDefault()
        //     alert(78)
        //
        // })


        function carousel_process(e)
        {
            let ajax_flag= false
            let slide_len= $('[data-consultantid]').length

            if (e.direction == 'right')
            {
                if (e.from +1 == slide_len)
                {
                    ajax_flag= true
                }
            }

            if (e.direction == 'left')
            {
                if (e.from == 0)
                {
                    ajax_flag= true

                }
            }


            if( ajax_flag )
            {
                let data= {}
                let consultant_ids= []
                $('[data-consultantid]').each(function(i, el){

                    consultant_ids[i]= $(el).data('consultantid')
                });

                data['consultant_ids']= consultant_ids
                ajax(data, $('#carouselExampleIndicators'), e)
            }


            if (e.to +1 == slide_len)
            {
                $('.carousel-control-next').addClass('custom-carousel-control-next');
            }
            else
            {
                $('.carousel-control-next').removeClass('custom-carousel-control-next');
            }


            if (e.to == 0)
            {
                $('.carousel-control-prev').addClass('custom-carousel-control-prev');
            }
            else
            {
                $('.carousel-control-prev').removeClass('custom-carousel-control-prev');
            }
        }


        $(document).on('slide.bs.carousel', '#carouselExampleIndicators', e =>{

            carousel_process(e)

        })



        let token= Joomla.getOptions('csrf.token')

        function ajax(data, _this, bse)
        {

            enable_body_spinner()
            $.ajax({
                url: 'index.php?option=com_ajax&module=emergencyconsultant&format=json&method=consultantsInQueue',
                method: 'post',
                data: {token: token, consultant_ids: data.consultant_ids, to: bse.to, direction: bse.direction, from: bse.from},
                success: function (msg)
                {
                    disable_body_spinner()
                    if (msg.data.status)
                    {
                        _this.html(msg.data.carousel)
                        let carousel_ins= new bootstrap.Carousel($('#carouselExampleIndicators')[0])

                    }
                    console.log(msg);
                },
                error: function (err){
                    console.log(err)
                }
            })
        }

        function enable_body_spinner()
        {
            $('body').addClass('emergency-spinner');
        }
        function disable_body_spinner()
        {
            $('body').removeClass('emergency-spinner');
        }


        $('.carousel-control-prev').click(function (){


            let e= {
                from: 0,
                to: undefined,
                direction: 'left'
            }

            carousel_process(e)
        });
        $('.carousel-control-next').click(function (){

            let e= {
                from: 0,
                to: undefined,
                direction: 'right'
            }

            carousel_process(e)
        });

        // var owl = $('.owl-carousel');
        // owl.owlCarousel({
        //     // autoWidth: true,
        //     // center: true,
        //     stagePadding: 25,
        //     loop:false,
        //     margin:10,
        //     nav:true,
        //     responsive:{
        //         0:{
        //             items:1
        //         },
        //         600:{
        //             items:1
        //         },
        //         1000:{
        //             items:1
        //         }
        //     }
        // })
        //
        // owl.on('changed.owl.carousel', function (){
        //     $('.button-eram-next').click()
        // })

    });



</script>