<?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="coworking-container">
    
</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/coworking/' . $username) ?>");
        if( response.ok ) {
            iframe.src = "<?php echo base_url('/blog/coworking/' . $username) ?>"
            linkEditPage.href = "<?php echo base_url('/blog/coworking/' . $username) ?>";
        } else {
            iframe.src = "<?php echo base_url('/blog/coworking-default') ?>";
            linkEditPage.href = "<?php echo base_url('/blog/wp-admin/post-new.php?post_type=coworking') ?>"
        }
        
        document.querySelector('.edit-page.fixed-bottom').appendChild(linkEditPage);
        document.querySelector('.coworking-container').appendChild(iframe);
    })()
</script>