<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
?>


<?php $settings = Engine_Api::_()->getApi('settings', 'core'); ?>

<?php if($this->type == 2) { ?>

<div id="browserpush_tip" class="browserpush_tip hide_push_popup">
  <div class="browserpush_tip_inner">
    <div class="browserpush_tip_icon">
      <?php if(empty($this->logo)) { ?>
      	<img src="application/modules/Browserpush/externals/images/bell-icon.png" alt="" />
      <?php } else { ?>
				<?php $logo = Engine_Api::_()->core()->getFileUrl($this->logo, true); ?>
				<?php if($logo) { ?>
      		<img src="<?php echo $logo['image']; ?>" alt="<?php echo $logo['alt_text'] ?? '' ; ?>" />
				<?php } else { ?>
					<img src="application/modules/Browserpush/externals/images/bell-icon.png" alt="" />
				<?php } ?>
      <?php } ?>
    </div>
    <div class="browserpush_tip_content">
      <div class="browserpush_tip_title"><?php echo $this->translate($this->title); ?></div>
      <div class="browserpush_tip_des"><?php echo $this->translate($this->descr); ?></div>
    </div>
    <div class="browserpush_tip_buttons"> <a href="javascript:void(0);" class="browserpush_button browserpush_button_alt browserpush_hide hide_pushnotnow"><?php echo $this->translate("I'll do this later");?></a> <a href="javascript:void(0);" class="browserpush_button browserpush_button_main browserpush_hide hide_pushallow"><?php echo $this->translate("Allow");?></a> </div>
  </div>
</div>
<?php } else if($this->type == 1){ ?>
<?php //Bell option  ?>
<div id="browserpush_tip" class="browserpush_notification_button">
	<a data-active="1" href="javascript:;" id="browserpush_bell" class="ajaxPrevent _browser"><i id="browsepush_bell_icon"></i></a>
  <p id="subscribe_browertip" class="_tip"><?php echo $this->translate('Click to subscribe.'); ?></p>
  <div id="browserpush_notification_bubble" class="browserpush_notification_bubble hide_push_popup">
    <div class="browserpush_notification_bubble_content">
      <div class="_icon">
        <?php if(empty($this->logo)) { ?>
        	<img src="application/modules/Browserpush/externals/images/notification.png" alt="" />
        <?php } else { ?>
					<?php $logo = Engine_Api::_()->core()->getFileUrl($this->logo, true); ?>
					<?php if($logo) { ?>
						<img src="<?php echo $logo['image']; ?>" alt="<?php echo $logo['alt_text'] ?? '' ; ?>" />
					<?php } else { ?>
						<img src="application/modules/Browserpush/externals/images/notification.png" alt="" />
					<?php } ?>
        <?php } ?>
      </div>
      <div class="_cont">
        <div class="_title"><?php echo $this->translate($this->title); ?></div>
        <div class="_des"><?php echo $this->translate($this->descr); ?></div>
      </div>
    </div>
    <div class="browserpush_notification_bubble_buttons">
      <div><a href="javascript:void(0);" class="hide_pushnotnow"><?php echo $this->translate("I'll do this later");?></a></div>
      <div><a href="javascript:void(0);" class="hide_pushallow"><?php echo $this->translate("Allow");?></a></div>
    </div>
  </div>
  
  <div id="browserpush_notification_bubble_unsubscribe" class="browserpush_notification_bubble _unsubscribe" style="display:none;">
    <div class="browserpush_notification_bubble_content">
      <div class="_icon">
        <?php if(empty($this->logo)) { ?>
        <img src="application/modules/Browserpush/externals/images/notification-off.png" alt="" />
        <?php } else { ?>
					<?php $logo = Engine_Api::_()->core()->getFileUrl($this->logo, true); ?>
					<?php if($logo) { ?>
						<img src="<?php echo $logo['image']; ?>" alt="<?php echo $logo['alt_text'] ?? '' ; ?>" />
					<?php } else { ?>
						<img src="application/modules/Browserpush/externals/images/notification-off.png" alt="" />
					<?php } ?>
        <?php } ?>
      </div>
      <div class="_cont">
        <div class="_title"><?php echo $this->translate("Are you sure you want to unsubscribe?"); ?></div>
        <div class="_des"><?php echo $this->translate("Go to your browser’s Notification setting and configure it according to your choice."); ?></div>
      </div>
    </div>
    <div class="browserpush_notification_bubble_buttons">
      <div><a href="javascript:void(0);" id="unsubscribe_popup_close" onclick="unsubscribeNotification();"><?php echo $this->translate("Okay");?></a></div>
    </div>
  </div>
  
</div>
<?php } else if($this->type == 3) { ?>
<div id="browserpush_tip" class="browserpush_notification_popup_wrapper  hide_push_popup">
<div class="browserpush_notification_popup_overlay browserpush_hide_popup"></div>
<?php if(empty($this->logo)) { ?>
<div class="browserpush_notification_popup" style="background-image:url(application/modules/Browserpush/externals/images/popup-bg.jpg);height:<?php echo $this->height; ?>px;width:<?php echo $this->width; ?>px;">
  <?php } else { ?>
  <div class="browserpush_notification_popup" style="background-image:url(<?php echo Engine_Api::_()->core()->getFileUrl($this->logo); ?>);height:<?php echo $this->height; ?>px;width:<?php echo $this->width; ?>px;">
    <?php } ?>
    <section> <a href="javascript:void(0);" class="browserpush_notification_popup_close browserpush_hide_popup hide_pushnotnow"></a>
      <div class="browserpush_notification_popup_content">
        <div class="_title"><?php echo $this->translate($this->title); ?></div>
        <div class="_des"><?php echo $this->translate($this->descr); ?></div>
      </div>
      <div class="browserpush_notification_popup_button"> <a href="javascript:void(0);" class="browserpush_hide_popup  hide_pushnotnow"><?php echo $this->translate("I'll do this later");?></a> <a href="javascript:void(0);" class="browserpush_hide_popup hide_pushallow"><?php echo $this->translate("Allow");?></a> </div>
    </section>
  </div>
</div>
<?php } ?>
<?php if(Engine_Api::_()->getApi('settings', 'core')->getSetting('browserpush.percontainer',1)) { ?>
<div id="browsepush_browser_permission_container" class="browsepush_browser_permission_container">
  <div id="browsepush_browser_permission_box" class="browsepush_browser_permission_box" style="display:none;"> <i></i>
    <?php  $web_title = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.site.title', 'My Community');
    $des = $this->translate('Always receive notifications to stay updated on new posts & activities on your content and account on ').$web_title.'.'; ?>
    <span><?php echo $this->translate(Engine_Api::_()->getApi('settings', 'core')->getSetting('browserpush.textpercontai', $des)); ?></span> </div>
</div>
<?php } ?>

<script type="text/javascript">
// cookie get and set function
function setCookie(cname, cvalue, exdays) {
	var d = new Date();
	d.setTime(d.getTime() + (exdays*24*60*60*1000));
	var browserpushnoti = "browserpushnoti="+d.toGMTString();
	document.cookie = cname + "=" + cvalue + "; " + browserpushnoti;
} 

function getCookieBrowserPush(cname) {
	var name = cname + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1);
    if (c.indexOf(name) != -1) return c.substring(name.length,c.length);
	}
	return "";
}

function unsubscribeNotification() {
  //Notification.close();
  scriptJquery('#browserpush_notification_bubble_unsubscribe').hide();
  if(scriptJquery ('#browserpush_tip').hasClass('showpulldown')) {
    scriptJquery('#browserpush_tip').removeClass('showpulldown');
  }
}

var browserDays = '<?php echo Engine_Api::_()->getApi('settings', 'core')->getSetting('browserpush.days', 5); ?>';
en4.core.runonce.add(function(){
  scriptJquery ('.hide_pushnotnow').click(function(){
    if(browserDays > 0) {
      setCookie("browser_ispopup",'browserpopo', browserDays);
    }
    scriptJquery ('.hide_push_popup').hide();
    if(scriptJquery ('#browserpush_tip').hasClass('showpulldown')) {
        scriptJquery('#browserpush_tip').removeClass('showpulldown');
    }
  });
});

en4.core.runonce.add(function(){
  scriptJquery ('.hide_pushallow').click(function(){
    requestPermission();
    scriptJquery ('.hide_push_popup').hide();
  });
});

en4.core.runonce.add(function(){
  
  var permission = Notification.permission;
  var dataActive = scriptJquery('#browserpush_bell').attr('data-active');
  scriptJquery ('#browserpush_bell').click(function() {
    if(permission != 'granted' && scriptJquery('#browserpush_bell').attr('data-active') == 1) { 
      if(scriptJquery ('#browserpush_tip').hasClass('showpulldown')) {
        scriptJquery('#browserpush_tip').removeClass('showpulldown');
        scriptJquery ('.hide_push_popup').hide();
        //scriptJquery('#subscribe_browertip').show();
      } else {
        scriptJquery('#browserpush_tip').addClass('showpulldown');
        scriptJquery ('.hide_push_popup').show();
        //scriptJquery('#subscribe_browertip').hide();
      }
    } else {
      if(scriptJquery ('#browserpush_tip').hasClass('showpulldown')) {
        scriptJquery('#browserpush_tip').removeClass('showpulldown');
        scriptJquery ('#browserpush_notification_bubble').hide();
        scriptJquery('#browserpush_notification_bubble_unsubscribe').hide();
      } else {
        scriptJquery('#browserpush_tip').addClass('showpulldown');
        scriptJquery ('#browserpush_notification_bubble').hide();
        scriptJquery('#browserpush_notification_bubble_unsubscribe').show();
      }
    }
  });
  
  scriptJquery ('#browsepush_browser_permission_container').click(function() {
    scriptJquery('#browsepush_browser_permission_container').hide();
  });
});

en4.core.runonce.add(function() {
  scriptJquery(document.body).addEvent('click', function(event){
    if(event.target.id != 'browserpush_notification_bubble' && event.target.id != 'browserpush_bell' && event.target.id != 'browsepush_bell_icon' && event.target.id != 'unsubscribe_popup_close') {
      scriptJquery('#browserpush_notification_bubble').hide();
      scriptJquery('#browserpush_tip').removeClass('showpulldown');
      if(scriptJquery('#browserpush_notification_bubble_unsubscribe'))
        scriptJquery('#browserpush_notification_bubble_unsubscribe').hide();
    }
  });
});
</script>
