<script type="text/javascript">
    $(document).ready(function(){
        $("#address").hide();
        $("#smsg").hide();
        $("#emsg").hide();
        $("#edit").click(function(){
            $("#address").show();
            $("#address_sublocality").focus();
        });
    });
    function onBoardClinic(id){
        $.ajax({
            url: "clinicdetail.php",
            data: 'act=OnBoard&id='+id,
            method: 'POST',
            success: function(response){
               res = JSON.parse(response);
               if(res.error){
                  $("#emsg").html(res.msg);  
                  $("#emsg").show();  
                  return false;
               }else{
                  location.reload();  
               }
            }
        });
    }

    function validate_address(){

   if($("#address_street").val()==''){
        $("#address_street").addClass('error');
        $("#address_street").focus();
        $("#msg_address_street").html('Please enter street').show();
        return false;
    }else{
        $("#address_street").removeClass('error');
        $("#msg_address_street").hide();
    }
   if($("#address_route").val()==''){
        $("#address_route").addClass('error');
        $("#address_route").focus();
        $("#msg_address_route").html('Please enter route').show();
        return false;
    }else{
        $("#address_route").removeClass('error');
        $("#msg_address_route").hide();
    }
    if($("#address_sublocality").val()==''){
        $("#address_sublocality").addClass('error');
        $("#address_sublocality").focus();
        $("#msg_address_sublocality").html('Please enter Sublocality').show();
        return false;
    }else{
        $("#address_sublocality").removeClass('error');
        $("#msg_address_sublocality").hide();
    }

    if($("#address_locality").val()==''){
        $("#address_locality").addClass('error');
        $("#address_locality").focus();
        $("#msg_address_locality").html('Please enter Locality').show();
        return false;
    }else{
        $("#address_locality").removeClass('error');
        $("#msg_address_locality").hide();
    }

    if($("#address_postal").val()==''){
        $("#address_postal").addClass('error');
        $("#address_postal").focus();
        $("#msg_address_postal").html('Please enter postal').show();
        return false;
    }else{
        $("#address_postal").removeClass('error');
        $("#msg_address_postal").hide();
    }
    if($("#address_level_1").val()==''){
        $("#address_level_1").addClass('error');
        $("#address_level_1").focus();
        $("#msg_address_level_1").html('Please enter address Level 1').show();
        return false;
    }else{
        $("#address_level_1").removeClass('error');
        $("#msg_address_level_1").hide();
    }

    if($("#address_level_1_short").val()==''){
        $("#address_level_1_short").addClass('error');
        $("#address_level_1_short").focus();
        $("#msg_address_level_1_short").html('Please enter address level 1 short').show();
        return false;
    }else{
        $("#address_level_1_short").removeClass('error');
        $("#msg_address_level_1_short").hide();
    }

    if($("#address_country").val()==''){
        $("#address_country").addClass('error');
        $("#address_country").focus();
        $("#msg_address_country").html('Please enter Country').show();
        return false;
    }else{
        $("#address_country").removeClass('error');
        $("#msg_address_country").hide();
    }

    
}
</script>
<div class="breadcrumb">
    <h1>Clinic</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>/cliniclist.php">Dashboard</a></li>
        <li>Clinic Details</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo ($clinicDetails->clinic_onBoard=='1') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Clinic OnBoard done.</div>" : '' ; ?>
    <?php echo ($clinicDetails->clinic_onBoard=='0') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Clinic OnBoard pending.</div>" : '' ; ?>
    
   </div>
</div>
<div class="row">
   <div class="col-md-12">
       <div class="card">
        <div class="tab-content" id="myTabContent">
            <div class="tab-pane fade show active" id="invoice" role="tabpanel" aria-labelledby="invoice-tab">
                <div id="print-area">
                    <div class="row">
                        <div class="col-md-6">
                            <h4 class="font-weight-bold"><?php echo $clinicDetails->clinic_name ?></h4>
                            <p>#<?php echo $clinicDetails->clinic_unique_id ?> / <?php echo $clinicDetails->clinic_id ?></p>
                            <p><?php echo $clinicDetails->user_fname ?>  <?php echo $clinicDetails->user_lname ?> / <?php echo $clinicDetails->speciality_name ?></p>
                        </div>
                        <div class="col-md-6 text-sm-right">
                            <?php
                            if(isset($clinicDetails->clinic_onBoard) && is_array(json_decode($clinicDetails->clinic_onBoard,1)))
                            {
                                $cliniconBoard = json_decode($clinicDetails->clinic_onBoard,1);
                            }
                             
                            ?>
                            <!-- <p><strong>On Board: </strong> <?php echo ($clinicDetails->clinic_onBoard=='1'?"True": "False") ?></p> -->
                            <p><strong>On Board: </strong> <?php echo ($cliniconBoard['status']=='1'?"True": "False") ?></p>
                            <p><strong>Status: </strong> <?php echo ($clinicDetails->clinic_status=='1'?"True": "False") ?></p>
                        </div>
                    </div>
                    <div class="mt-3 mb-4 border-top"></div>
                    <div class="row mb-5">
                        <div class="col-md-4 mb-3 mb-sm-0">
                            <!-- <span id="edit" style="cursor: pointer;"><i class="i-Edit"></i> Edit</span> -->
                            <h5 class="font-weight-bold">Address</h5>
                            <b>Street</b> : <?php echo $clinicDetails->address_street ?><br/>
                            <b>Route</b> : <?php echo $clinicDetails->address_route ?><br/>
                            <b>Sublocality</b> : <?php echo $clinicDetails->address_sublocality ?><br/>
                            <b>Neighborhood</b> : <?php echo $clinicDetails->address_neighborhood ?><br/>
                            <b>Locality</b> : <?php echo $clinicDetails->address_locality ?><br/>
                            <b>Postal</b> : <?php echo $clinicDetails->address_postal ?><br/>
                            <b>Country</b> : <?php echo $clinicDetails->address_country ?><br/>
                            <b>Administrator Level</b> : <?php echo $clinicDetails->address_level_1 ?><br/>
                            <b>Administrator Level Short</b> : <?php echo $clinicDetails->address_level_1_short ?><br/>
                            <b>Suite</b> : <?php echo $clinicDetails->address_suite ?><br/>
                            <b>Lat</b> : <?php echo $clinicDetails->address_latitude ?><br/>
                            <b>Long</b> : <?php echo $clinicDetails->address_longitude ?><br/>
                        </div>
                        <div class="col-md-4">
                            <h5 class="font-weight-bold">Contact Info</h5>
                            <b>Email</b> : <?php echo $clinicDetails->clinic_email ?> / <b><?php echo (!is_null($clinicDetails->clinic_email_verified)?"Verifield" : "Unverified")  ?></b><br/>
                            <b>Phone</b> : <?php echo $clinicDetails->clinic_phone ?> / <b><?php echo (!is_null($clinicDetails->clinic_phone_verified)?"Verifield" : "Unverified")  ?></b><br/>
                            <b>Website</b> : <?php echo $clinicDetails->clinic_website ?><br/>
                            <b>Url</b> : <?php echo $clinicDetails->clinic_url ?><br/>
                            <b>Domain</b> : <?php 
                                            $domainObj = new domain();
                                            $domainDetails = $domainObj->fromId($clinicDetails->clinic_domain);
                                            echo $domainDetails->domain_title; 
                                            ?>
                             <br/>
                             <?php if($clinicDetails->clinic_primary_speciality != ''){ ?>
                             <b>Speciality</b> : <?php 
                                            $specialityObj = new speciality();
                                            $specialityfields = array('speciality_id','speciality_name');
                                            $specialitywhere = "speciality_id IN (".$clinicDetails->clinic_primary_speciality.")";
                                            $specialitydata = array('fields'=>$specialityfields,'where'=>$specialitywhere);
                                            $specialityDetails = $specialityObj->getAllRecords($specialitydata);
                                            foreach($specialityDetails as $specality_value)
                                            {
                                                $SpecalityName .= $specality_value->speciality_name.",";
                                            }
                                            echo rtrim($SpecalityName,",");
                                            ?>
                             <br/>
                            <?php } ?>
                            <b>PMS Status</b> : <?php echo $clinicDetails->clinic_pmsStatus ?><br/>
                            <b>MapPMS Status</b> : <?php echo $clinicDetails->clinic_mapPmsStatus ?><br/>
                            <b>API Key</b> : <?php echo $clinicDetails->clinic_api_key ?><br/>
                            <b>Metadata</b> : <?php echo $clinicDetails->clinic_metadata ?><br/>
                             <b>Seodata</b> : <?php echo $clinicDetails->clinic_seodata ?><br/>
                            <b>Setting</b> : <?php echo $clinicDetails->clinic_setting ?><br/>
                            <p></p>
                        </div>
                        <div class="col-md-4">
                            <h5 class="font-weight-bold">Card Info</h5>
                            <?php 
                                if($allCards && count($allCards)>0){
                                    $hasCard =true;
                                    foreach ($allCards as $key => $card) {?>
                                         <b>Provider</b> : <?php echo $card->doctor_fullname ?><br/>
                                         <b>Last 4 digit</b> : ... <?php echo $card->stripecard_last4 ?> / <b><?php echo $card->stripecard_brand ?></b>
                                         <hr style="margin:10px 0;" />
                                   <?php  }
                                }else{
                                    $hasCard =false; ?>
                                    <b style="color: red;">Not any cards added yet!</b>
                                    <hr style="margin:10px 0;" />
                                <?php } ?>
                            <?php 
                                if($clinicDetails->clinic_metadata!="" && is_array(json_decode($clinicDetails->clinic_metadata,1))){
                                    $metadata = json_decode($clinicDetails->clinic_metadata,1);
                                    if(array_key_exists("reviewOn", $metadata) && $metadata['reviewOn']!=""){
                                        $hasReview =true; ?>
                                      <b style="color: green;">Review : Selected - <?php echo $metadata['reviewOn'] ?></b>
                                    <hr style="margin:10px 0;" />
                                    <?php }else{
                                        $hasReview =false;
                                    }

                                    if(array_key_exists("clinicTnC", $metadata) && $metadata['clinicTnC']){
                                        $hasTNC =true; ?>
                                      <b style="color: green;">TnC : Accepted</b>
                                    <hr style="margin:10px 0;" />
                                    <?php }else{
                                        $hasTNC =false;
                                        }
                                }else{
                                    $hasReview = false;
                                    $hasTNC = false;?>
                                    <b style="color: red;">Review : Please select review option</b><br/>
                                    from where you want to fetch your review. clinic->setting 
                                    <hr style="margin:10px 0;" />
                                    <b style="color: red;">Please read and accept term & condition. clinic->setting </b>
                                    <hr style="margin:10px 0;" />
                                <?php }
                               
                                if($clinicDetails->clinic_onBoard!="1" && $clinicDetails->address_sublocality!=""  && !is_null($clinicDetails->clinic_phone_verified) && !is_null($clinicDetails->clinic_email_verified)  && $hasReview && $hasTNC && $hasCard ){?>
                                    <a href="javascript:void(0);" onclick="onBoardClinic('<?php echo $clinicDetails->clinic_id ?>')"><button class="btn btn-primary mb-sm-0 mb-3 print-invoice">OnBoard Now</button></a>
                               <?php }
                             ?>
                             <span id="smsg" style="color: green;"></span>
                             <span id="emsg" style="color: red;"></span>

                        </div>
                    </div>
                    <div class="row" id="address">
                        
        
            <div class="card-body">
                <form action="" id='frm-clinic' method="post" enctype="multipart/form-data" onsubmit="return validate_address();">
                    <input type="hidden" id="address_id" name="address_id" value="<?php echo $clinicDetails->address_id ?>" />
                 
                    <div class="card-title mb-3">Address</div>
                    <div class="row">
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_street">Street <span class="asterisk">*</span></label>
                            <input type="text"  id="address_street" name="address_street" value="<?php echo $clinicDetails->address_street ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_street"></div>
                        </div>    
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_route">Route <span class="asterisk">*</span></label>
                            <input type="text"  id="address_route" name="address_route" value="<?php echo $clinicDetails->address_route ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_route"></div>
                        </div> 
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_sublocality">Sublocality <span class="asterisk">*</span></label>
                            <input type="text"  id="address_sublocality" name="address_sublocality" value="<?php echo $clinicDetails->address_sublocality ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_sublocality"></div>
                        </div>   
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_neighborhood">Neighborhood</label>
                            <input type="text"  id="address_neighborhood" name="address_neighborhood" value="<?php echo $clinicDetails->address_neighborhood ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_neighborhood"></div>
                        </div>
                        
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_locality">Locality <span class="asterisk">*</span></label>
                            <input type="text"  id="address_locality" name="address_locality" value="<?php echo $clinicDetails->address_locality ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_locality"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_postal">postal <span class="asterisk">*</span></label>
                            <input type="text"  id="address_postal" name="address_postal" value="<?php echo $clinicDetails->address_postal ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_postal"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_level_1">Administrator level Area <span class="asterisk">*</span></label>
                            <input type="text"  id="address_level_1" name="address_level_1" value="<?php echo $clinicDetails->address_level_1 ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_level_1"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_level_1_short">Administrator level Area Short <span class="asterisk">*</span></label>
                            <input type="text"  id="address_level_1_short" name="address_level_1_short" value="<?php echo $clinicDetails->address_level_1_short ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_level_1_short"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_suite">Suite</label>
                            <input type="text"  id="address_suite" name="address_suite" value="<?php echo $clinicDetails->address_suite ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_suite"></div>
                        </div>
                        <div class="col-md-4 form-group mb-3">
                            <label for="address_country">Country</label>
                            <input type="text"  id="address_country" name="address_country" value="<?php echo $clinicDetails->address_country ?>" class="form-control">
                            <div class="invalid-tooltip" id="msg_address_country"></div>
                        </div>
                        <div class="col-md-12">
                            <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
                        </div>
                       </div>
                       
                   </form>
                    </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
   </div> 
</div>