@php 
session_start();
$_SESSION['mc_user_id'] = Auth::user()->id;
@endphp
<meta name="csrf-token" content="{{ csrf_token() }}">
<link id="style" href="{{asset('assets/libs/bootstrap/css/bootstrap.min.css')}}" rel="stylesheet" >
<link href="{{asset('assets/css/toastr.min.css')}}" rel="stylesheet" >
<link href="{{asset('components/builder/style/grapes.min.css')}}" rel="stylesheet" >
<link href="{{asset('components/builder/style/material.css')}}" rel="stylesheet" >
<link href="{{asset('components/builder/style/tooltip.css')}}" rel="stylesheet" >
<link href="{{asset('components/builder/style/grapesjs-preset-newsletter.css')}}" rel="stylesheet" >
<link href="{{asset('assets/css/sweetalert.css')}}" rel="stylesheet" >

<script src="{{asset('assets/js/jquery.min.js')}}"></script>
<script src="{{asset('components/builder/dist/grapes.min.js')}}"></script>
<script src="{{asset('components/builder/dist/grapesjs-preset-newsletter.min.js')}}"></script>
<script src="{{asset('assets/js/sweetalert.min.js')}}"></script>
<script src="{{asset('assets/js/toastr.min.js')}}"></script>
<script src="{{asset('components/ckeditor/ckeditor.js')}}"></script>
<script src="{{asset('components/builder/dist/grapesjs-plugin-ckeditor.min.js')}}"></script>

<style>body, html{ height: 100%; margin: 0;}</style>
<?php
$images = [];
$images_folder= public_path()."/images/users/".Auth::user()->id."/gallery/";
if(is_dir($images_folder)) {
  $files = scandir($images_folder);
  foreach($files as $file) {
    if($file != '.' && $file != '..') {
      $url = url('/')."/images/users/".Auth::user()->id."/gallery/".$file;
      array_push($images, $url);
    }
  }
}
?>
<body>
  <div class="col-md-12 my-1">
    <input type="text" class="form-control" id="template-name" name="name" value="{{ $name ?? '' }}" placeholder="{{ __('app.name') }}">
    <input type="hidden" id='action' name="action" value="{{$action}}">
    <input type="hidden" id='id' name="id" value="{{$id}}">
  </div>
  <div id="gjs">
    {!! !empty($html) ? $html : '' !!}
  </div>
<span id="clean-canvas" data-value="{{__('app.clean_canvas')}}"></span>
<span id="builder-msg-name-required" data-value="{{__('app.builder_msg_name_required')}}"></span>
<span id="msg-saved" data-value="{{__('app.msg_saved')}}"></span>
<span id="builder-mgs-cancel" data-value="{{__('app.builder_mgs_cancel')}}"></span>
</body>
<script type="text/javascript">
  $.ajaxSetup({
    headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
  });
  var images_array = <?php echo json_encode($images); ?>;
</script>
<script src="{{asset('assets/js/builder.js')}}"></script>