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

<script type="text/javascript">
  en4.core.runonce.add(function(){
    <?php if( !$this->renderOne ): ?>
    var anchor = scriptJquery('#profile_polls').parent().parent();
    scriptJquery('#profile_polls_previous').css('display','<?php echo ( $this->paginator->getCurrentPageNumber() == 1 ? 'none' : '' ) ?>');
    scriptJquery('#profile_polls_next').css('display','<?php echo ( $this->paginator->count() == $this->paginator->getCurrentPageNumber() ? 'none' : '' ) ?>');

    scriptJquery('#profile_polls_previous').off('click').on('click', function(){
      en4.core.request.send(scriptJquery.ajax({
        url : en4.core.baseUrl + 'widget/index/content_id/' + <?php echo sprintf('%d', $this->identity) ?>,
        method : 'post',
        data : {
          format : 'html',
          subject : en4.core.subject.guid,
          page : <?php echo sprintf('%d', $this->paginator->getCurrentPageNumber() - 1) ?>
        }
      }), {
        'element' : anchor
      })
    });

    scriptJquery('#profile_polls_next').off('click').on('click', function(){
      en4.core.request.send(scriptJquery.ajax({
        url : en4.core.baseUrl + 'widget/index/content_id/' + <?php echo sprintf('%d', $this->identity) ?>,
        method : 'post',
        data : {
          format : 'html',
          subject : en4.core.subject.guid,
          page : <?php echo sprintf('%d', $this->paginator->getCurrentPageNumber() + 1) ?>
        }
      }), {
        'element' : anchor
      })
    });
    <?php endif; ?>
  });
</script>

<div class='polls_browse container no-padding'>
  <div class='grid_listing' id="profile_polls">
    <?php foreach ($this->paginator as $poll): ?>
      <div class="grid_listing_item" id="poll-item-<?php echo $poll->poll_id ?>">
        <article>
          <div class='grid_listing_item_thumb'>
            <?php echo $this->htmlLink($poll->getHref(), $this->itemBackgroundPhoto($poll, 'thumb.profile')) ?>
          </div>
          <div class="grid_listing_item_info">
            <div class="grid_listing_item_title">
              <?php echo $this->htmlLink($poll->getHref(), $poll->getTitle()) ?>
              <?php if( $poll->closed ): ?>
                <i class="icon_closed" data-bs-toggle="tooltip" title="<?php echo $this->translate("Closed")?>"></i>
              <?php endif ?>
            </div>
            <p class='grid_listing_item_owner d-flex flex-wrap gap-1'>
              <span>
                <?php echo $this->htmlLink($poll->getOwner()->getHref(), $poll->getOwner()->getTitle()) ?>
              </span>              
              <span>
                <?php echo $this->timestamp(strtotime($poll->creation_date)) ?>
              </span>
            </p>
            <div class="grid_listing_item_owner">
              <span><i class="">
                <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
                  <path d="M15 9V4.5C15 2.8425 13.6575 1.5 12 1.5H6C4.3425 1.5 3 2.8425 3 4.5V9C1.3425 9 0 10.3425 0 12V13.5C0 15.1575 1.3425 16.5 3 16.5H15C16.6575 16.5 18 15.1575 18 13.5V12C18 10.3425 16.6575 9 15 9ZM4.5 4.5C4.5 3.675 5.175 3 6 3H12C12.825 3 13.5 3.675 13.5 4.5V12H4.5V4.5ZM16.5 13.5C16.5 14.325 15.825 15 15 15H3C2.175 15 1.5 14.325 1.5 13.5V12C1.5 11.175 2.175 10.5 3 10.5V12.75C3 13.1625 3.3375 13.5 3.75 13.5H14.25C14.6625 13.5 15 13.1625 15 12.75V10.5C15.825 10.5 16.5 11.175 16.5 12V13.5ZM6.2175 8.325C5.925 8.0325 5.925 7.56 6.2175 7.2675C6.51 6.975 6.9825 6.975 7.275 7.2675L8.1525 8.145C8.3025 8.295 8.535 8.2875 8.685 8.145L10.7175 6.1125C11.01 5.82 11.4825 5.82 11.775 6.1125C12.0675 6.405 12.0675 6.8775 11.775 7.17L9.7425 9.2025C9.375 9.57 8.895 9.75 8.415 9.75C7.935 9.75 7.455 9.57 7.0875 9.2025L6.21 8.325H6.2175Z" fill="var(--theme-font-color-light)"/>
                </svg>
              </i><?php echo $this->translate(array('%s vote', '%s votes', $poll->vote_count), $this->locale()->toNumber($poll->vote_count)) ?></span>
              <span><i class="far fa-eye"></i><?php echo $this->translate(array('%s view', '%s views', $poll->view_count), $this->locale()->toNumber($poll->view_count)) ?></span>
            </div> 
          </div>
        </article>
      </div>
    <?php endforeach; ?>
  </div>
  <div class="profile_paginator">
    <div id="profile_polls_previous" class="paginator_previous">
      <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Previous'), array(
        'onclick' => '',
        'class' => 'buttonlink icon_previous'
      )); ?>
    </div>
    <div id="profile_polls_next" class="paginator_next">
      <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Next'), array(
        'onclick' => '',
        'class' => 'buttonlink_right icon_next'
      )); ?>
    </div>
  </div>
</div>

