<?php defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' ); ?>
<style>
  body {
    overflow: hidden;
  }
  .embed__wp {
    width: 100%;
    height: 100vh;
  }
</style>
<?php if ( intval($this->zuser->data->role) === 1 ): ?>
<div class="edit-page fixed-bottom">

</div>
<?php endif ?>

<div class="progress-karya-container">
  <lottie-player
    src="<?php echo base_url('assets/default/lottiefiles/loading.json') ?>"
    speed="1"
    class="loading mx-auto"
    style="width: 100%; max-width: 500px; height: 200px;"
    mode="normal"
    loop
    autoplay
  ></lottie-player>
</div>

<script>
    const iframe = document.createElement('iframe');
    iframe.classList.add('embed__wp');
    
    const linkEditPage = document.createElement('a');
    linkEditPage.classList.add('btn', 'btn-primary');
    linkEditPage.innerText = "Edit Page";
    linkEditPage.target = "_blank";
    
    (async () => {
        const response = await fetch("<?php echo base_url('/blog/progress-karya/' . $username) ?>");
        if( response.ok ) {
            iframe.src = "<?php echo base_url('/blog/progress-karya/' . $username) ?>"
            linkEditPage.href = "<?php echo base_url('/blog/progress-karya/' . $username) ?>";
        } else {
            iframe.src = "<?php echo base_url('/blog/progress-karya-default') ?>";
            linkEditPage.href = "<?php echo base_url('/blog/wp-admin/post-new.php?post_type=progress-karya') ?>"
        }
        
        document.querySelector('.edit-page.fixed-bottom').appendChild(linkEditPage);
        document.querySelector('.progress-karya-container').innerHTML = '';
        document.querySelector('.progress-karya-container').appendChild(iframe);
    })()
</script>