<?php $__env->startSection('content'); ?>
	<div class="page-wrapper">
    <div class="row page-titles">

        <div class="col-md-5 align-self-center">
            <h3 class="text-themecolor"><?php echo e(trans('lang.app_setting_global')); ?></h3>
        </div>
        <div class="col-md-7 align-self-center">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo e(url('/dashboard')); ?>"><?php echo e(trans('lang.dashboard')); ?></a></li>
                <li class="breadcrumb-item active"><?php echo e(trans('lang.app_setting_global')); ?></li>
            </ol>
        </div>
    </div>

        <div class="card-body">
      	   <div id="data-table_processing" class="dataTables_processing panel panel-default" style="display: none;"><?php echo e(trans('lang.processing')); ?></div>
                 <div class="row vendor_payout_create">
                    <div class="vendor_payout_create-inner">
                        <fieldset>
                            <legend><i class="mr-3 fa fa-facebook"></i><?php echo e(trans('lang.app_setting_global')); ?></legend>
                    
                            <div class="form-group row width-100">
                                <label class="col-5 control-label"><?php echo e(trans('lang.app_setting_app_name')); ?></label>
                                <div class="col-7">
                                  <input type="text" class="form-control application_name">
                                  <div class="form-text text-muted">
                                    <?php echo e(trans("lang.app_setting_app_name_help")); ?>

                                  </div>
                                </div>
                            </div>

                           <!--  <div class="form-group row width-50">
                              <label class="col-5 control-label"><?php echo e(trans('lang.app_setting_app_short_description')); ?></label>
                              <div class="col-7">
                                <input type="text" class="form-control application_description">
                                <div class="form-text text-muted">
                                  <?php echo e(trans("lang.app_setting_app_short_description_help")); ?>

                                </div>
                              </div>
                            </div> -->
                    
                            <div class="form-group row width-50">
                              <label class="col-3 control-label"><?php echo e(trans('lang.upload_app_logo')); ?></label>
                              <input type="file" class="col-7" onChange="handleFileSelect(event)">
                              <div id="uploding_image"></div>
                              <div class="logo_img_thumb"></div>  
                            </div>

                            <div class="form-group row width-50">
                              <label class="col-5 control-label"><?php echo e(trans('lang.menu_placeholder_image')); ?></label>
                              <input type="file" class="col-7" onChange="handleFileSelectplaceholder(event)">
                              <div id="uploading_placeholder"></div>
                              <div class="placeholder_img_thumb">  
                              </div> 
                            </div>
                        </fieldset>
                      </div>
                    </div>     
                  </div>

                  <div class="form-group col-12 text-center btm-btn">
                    <button type="button" class="btn btn-primary save_global_settings_btn" ><i class="fa fa-save"></i> <?php echo e(trans('lang.save')); ?></button>
                    <a href="<?php echo e(url('/dashboard')); ?>" class="btn btn-default"><i class="fa fa-undo"></i><?php echo e(trans('lang.cancel')); ?></a>
                  </div>
        </div>    

 <?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
<script>
    
    var database = firebase.firestore();
    var ref = database.collection('settings').doc("globalSettings");
    var refPlaceholderImage = database.collection('settings').doc("placeHolderImage");
    
    var photo = "";
    var placeholderphoto = '';
    $(document).ready(function(){
        jQuery("#data-table_processing").show();
        ref.get().then( async function(snapshots){
            var globalSettings = snapshots.data();
            console.log(globalSettings);
            jQuery("#data-table_processing").hide();
            $(".application_name").val(globalSettings.applicationName);
            //$(".application_description").val(globalSettings.shortDescription);
            photo = globalSettings.appLogo;
            $(".logo_img_thumb").append('<img class="rounded" style="width:50px" src="'+photo+'" alt="image">');
        })

            refPlaceholderImage.get().then( async function(snapshots){
            var placeholderImage = snapshots.data();
            jQuery("#data-table_processing").hide();
            placeholderphoto = placeholderImage.image;
            $(".placeholder_img_thumb").append('<img class="rounded" style="width:50px" src="'+placeholderphoto+'" alt="image">');           
        })


        $(".save_global_settings_btn").click(function(){

            var applicationName = $(".application_name").val();
           // var applicationDescription = $(".application_description").val();
            if(applicationName == ''){
              alert("Please enter application name");
            }else{
                database.collection('settings').doc("globalSettings").update({'applicationName':applicationName,
                    //'shortDescription':applicationDescription,
                    'appLogo':photo}).then(function(result) {

                   database.collection('settings').doc('placeHolderImage').update({'image':placeholderphoto}).then(function(result) {
                      window.location.href = '<?php echo e(url("settings/app/globals")); ?>';
                        })

                                            
                });
            }

        })
    })


var storageRef = firebase.storage().ref('images');
function handleFileSelect(evt) {
  var f = evt.target.files[0];
  var reader = new FileReader();

  reader.onload = (function(theFile) {
    return function(e) {
        
      var filePayload = e.target.result;
      var hash = CryptoJS.SHA256(Math.random() + CryptoJS.SHA256(filePayload));
        var val =f.name;       
      var ext=val.split('.')[1];
      var docName=val.split('fakepath')[1];
      var filename = (f.name).replace(/C:\\fakepath\\/i, '')

      var timestamp = Number(new Date());      
      var uploadTask = storageRef.child(filename).put(theFile);
      console.log(uploadTask);
      uploadTask.on('state_changed', function(snapshot){
      var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
      console.log('Upload is ' + progress + '% done');
      jQuery("#uploding_image").text("Image is uploading...");

    }, function(error) {

    }, function() {
        uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
            jQuery("#uploding_image").text("Upload is completed");
            photo = downloadURL;

      });   
    });
    
    };
  })(f);
  reader.readAsDataURL(f);
} 



function handleFileSelectplaceholder(evt) {
  var f = evt.target.files[0];
  var reader = new FileReader();

  reader.onload = (function(theFile) {
    return function(e) {
        
      var filePayload = e.target.result;
      var hash = CryptoJS.SHA256(Math.random() + CryptoJS.SHA256(filePayload));
        var val =f.name;       
      var ext=val.split('.')[1];
      var docName=val.split('fakepath')[1];
      var filename = (f.name).replace(/C:\\fakepath\\/i, '')

      var timestamp = Number(new Date());      
      var uploadTask = storageRef.child(filename).put(theFile);
      console.log(uploadTask);
      uploadTask.on('state_changed', function(snapshot){
      var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
      console.log('Upload is ' + progress + '% done');
      jQuery("#uploading_placeholder").text("Image is uploading...");

    }, function(error) {

    }, function() {
        uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
            jQuery("#uploading_placeholder").text("Upload is completed");
            placeholderphoto = downloadURL;

      });   
    });
    
    };
  })(f);
  reader.readAsDataURL(f);
}
</script>



<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/customer/www/gromartadmin.siswebapp.com/resources/views/settings/app/global.blade.php ENDPATH**/ ?>