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

$element = $this->element;
$name = $element->getName();
$id = $element->getAttrib('id') ? $element->getAttrib('id') : $name;
$previewSrc = (string) $element->getAttrib('preview_src');
$sizeText = $element->getAttrib('size_text') ? $element->getAttrib('size_text') : 'Size 124 x 40px (max. 45MB)';
$urlPlaceholder = $element->getAttrib('url_placeholder') ? $element->getAttrib('url_placeholder') : 'By URL';
$removeElement = (string) $element->getAttrib('remove_element');
$staticBaseUrl = isset($this->staticBaseUrl) ? $this->staticBaseUrl : '';
$show_edit = $element->getAttrib('show_edit') ? $element->getAttrib('show_edit') : false;
$show_delete = $element->getAttrib('show_delete') ? $element->getAttrib('show_delete') : false;
$isCover = $element->getAttrib('isCover') ? $element->getAttrib('isCover') : false;

$inputAttribs = $element->getAttribs();
foreach( array(
  'helper',
  'preview_src',
  'size_text',
  'url_placeholder',
  'remove_element',
  'upload_label',
  'take_photo_label',
  'drop_label',
  'class',
	'show_edit',
	'show_delete',
	'isCover',
) as $attrib ) {
  if( isset($inputAttribs[$attrib]) ) {
    unset($inputAttribs[$attrib]);
  }
}
$inputAttribs['id'] = $id;
$inputAttribs['class'] = trim((string) $element->getAttrib('class') . ' core-media-upload-input');
if( !$element->getAttrib('accept') ) {
  $inputAttribs['accept'] = 'image/*';
}
?>
<div class="core-media-upload media_upload_wrapper" data-core-media-upload="<?php echo $this->escape($id); ?>"<?php if( $removeElement ): ?> data-remove-element="<?php echo $this->escape($removeElement); ?>"<?php endif; ?>>
  <?php echo $this->formFile($name, $inputAttribs); ?>
  <input type="hidden" name="<?php echo $this->escape($name); ?>_camera" id="<?php echo $this->escape($id); ?>_camera" data-media-upload-camera-data />
  <div class="media-upload-dropzone media_uploader_box" tabindex="0">
    <div class="media_uploader_box_content">
      <p class="media_upload_text">
        <?php echo $this->translate('Drag & Drop Or'); ?>
        <a href="javascript:void(0);" data-media-upload-trigger><?php echo $this->translate('Upload'); ?></a>
        <?php echo $this->translate('Or'); ?>
        <a href="javascript:void(0);" data-media-upload-camera><?php echo $this->translate('Take Photo'); ?></a>
        <?php echo $this->translate('Or'); ?>
      </p>
      <div class="media_uploader_upload_url">
        <input type="text" name="<?php echo $this->escape($name); ?>_url" id="<?php echo $this->escape($id); ?>_url" placeholder="<?php echo $this->escape($this->translate($urlPlaceholder)); ?>" data-media_uploader_upload_url />
        <button type="button" data-media_uploader_upload_url-submit title="<?php echo $this->escape($this->translate('Use URL')); ?>">
          <i>
            <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
              <path d="M2.91681 13.9993C2.91681 8.77462 2.91681 6.16225 4.53993 4.53913C6.16304 2.91602 8.77541 2.91602 14.0001 2.91602C19.2249 2.91602 21.8372 2.91602 23.4604 4.53913C25.0835 6.16225 25.0835 8.77462 25.0835 13.9993C25.0835 19.2241 25.0835 21.8364 23.4604 23.4596C21.8372 25.0827 19.2249 25.0827 14.0001 25.0827C8.77541 25.0827 6.16304 25.0827 4.53993 23.4596C2.91681 21.8364 2.91681 19.2241 2.91681 13.9993Z" stroke="currentColor" stroke-width="1.75"/>
              <path d="M18.6668 9.04102C19.1501 9.04102 19.5418 8.64927 19.5418 8.16602C19.5418 7.68277 19.1501 7.29102 18.6668 7.29102V8.16602V9.04102ZM9.3335 7.29102C8.85025 7.29102 8.4585 7.68277 8.4585 8.16602C8.4585 8.64926 8.85025 9.04102 9.3335 9.04102L9.3335 8.16602L9.3335 7.29102ZM10.4545 13.6052C10.1186 13.9526 10.1278 14.5065 10.4752 14.8425C10.8226 15.1784 11.3765 15.1691 11.7125 14.8218L11.0835 14.2135L10.4545 13.6052ZM12.4534 12.797L11.8244 12.1887H11.8244L12.4534 12.797ZM15.547 12.797L16.1759 12.1887L16.1759 12.1887L15.547 12.797ZM16.2878 14.8218C16.6238 15.1691 17.1777 15.1784 17.5251 14.8425C17.8725 14.5065 17.8818 13.9526 17.5458 13.6052L16.9168 14.2135L16.2878 14.8218ZM13.1252 19.8327C13.1252 20.3159 13.5169 20.7077 14.0002 20.7077C14.4834 20.7077 14.8752 20.3159 14.8752 19.8327H14.0002L13.1252 19.8327ZM18.6668 8.16602V7.29102L9.3335 7.29102L9.3335 8.16602L9.3335 9.04102L18.6668 9.04102V8.16602ZM11.0835 14.2135L11.7125 14.8218L13.0824 13.4053L12.4534 12.797L11.8244 12.1887L10.4545 13.6052L11.0835 14.2135ZM15.547 12.797L14.918 13.4053L16.2878 14.8218L16.9168 14.2135L17.5458 13.6052L16.1759 12.1887L15.547 12.797ZM12.4534 12.797L13.0824 13.4053C13.4643 13.0103 13.6905 12.7791 13.8723 12.6357C14.0351 12.5072 14.051 12.541 14.0002 12.541V11.666V10.791C13.4963 10.791 13.1033 11.0133 12.7883 11.2618C12.4922 11.4954 12.1716 11.8297 11.8244 12.1887L12.4534 12.797ZM15.547 12.797L16.1759 12.1887C15.8287 11.8297 15.5081 11.4954 15.212 11.2618C14.897 11.0133 14.5041 10.791 14.0002 10.791V11.666V12.541C13.9493 12.541 13.9652 12.5072 14.1281 12.6357C14.3098 12.7791 14.536 13.0103 14.918 13.4053L15.547 12.797ZM14.0002 11.666L13.1252 11.666L13.1252 19.8327L14.0002 19.8327H14.8752L14.8752 11.666H14.0002Z" fill="currentColor"/>
            </svg>
          </i>
        </button>
      </div>
      <span class="media_uploader_box_hint"><?php echo $this->escape($this->translate($sizeText)); ?></span>
    </div>
  </div>
  <div class="media_uploader_preview_item <?php if( $isCover ): ?> media-preview-cover <?php endif; ?>" <?php if( !$previewSrc ): ?> style="display:none;"<?php endif; ?> data-media-upload-preview>
    <div class="media_uploader_preview_item_img">
      <img<?php if( $previewSrc ): ?> src="<?php echo $this->escape($previewSrc); ?>"<?php endif; ?> alt="" data-media-upload-preview-img<?php if( !$previewSrc ): ?> style="display:none;"<?php endif; ?> />
    </div>
    <div class="media_preview_footer">
      <span class="media_uploader_file_size" data-media_uploader_box_hint></span>
			<?php if( $show_edit || $show_delete ): ?>
				<div class="media_preview_actions">
				<?php if( $show_edit ): ?>
						<button type="button" class="media-edit-btn" data-media-upload-trigger title="<?php echo $this->escape($this->translate('Change')); ?>"><i class="fa fa-pencil"></i></button>
				<?php endif; ?>
					<?php if( $show_delete ): ?>
						<button type="button" class="media-delete-btn" data-media-upload-remove title="<?php echo $this->escape($this->translate('Remove')); ?>"><i class="fi fi-rr-trash"></i></button>
					<?php endif; ?>
				</div>
			<?php endif; ?>
    </div>
  </div>
</div>
<script type="text/javascript">
  if (window.EngineMediaUpload) {
    window.EngineMediaUpload.init(document);
  }
</script>
