<!DOCTYPE html>
<html>

<head>
    <title>duckdown - editor</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="https://unpkg.com/vue@3.0.2"></script>
    <script type="text/javascript" src="https://unpkg.com/lodash@4.16.0"></script>
    <script type="text/javascript" src="https://unpkg.com/axios@0.21.0"></script>
    <link rel="shortcut icon" href="{{ handler.asset_url('logo.svg') }}" />
    <link rel="stylesheet" href="{{ handler.asset_url('editor.css') }}" />
</head>

<body>
    <div id="app" v-cloak>
        <table class="table">
            <tr class="menu">
                <th class="breadcrumb">
                    <a @click="back(0)">
                        <svg class="logo">
                            <use xlink:href="{{ handler.asset_url('logo.svg') }}#duck" /></svg>
                    </a>
                    <a v-for="(item, index) in path_items" @click="back(index+1)">/{{! item }}</a>
                </th>
                <th>
                    <button @click="remove()" v-bind:disabled="!can_save">Remove</button>
                    <button @click="save()" v-bind:disabled="!can_save">Save</button>
                    <input type="text" v-model="file">
                </th>
                <th>
                    <a href="https://www.markdownguide.org/cheat-sheet/" target="duckdown-help">
                        <button>Help</button>
                    </a>
                    <a href="/">
                        <button>Site</button>
                    </a>
                    <button @click="reset()">Reset</button>
                    <button @click="images=true" :class="{active:images}">
                        Images
                    </button>
                    <button @click="images=false" :class="{active:!images}">
                        Preview
                    </button>
                    <div class="alert" v-if="message">
                        <svg class="feather">
                            <use xlink:href="{{ handler.asset_url('feather-sprite.svg') }}#alert-triangle" /></svg>
                        {{! message }}
                    </div>
                </th>
            </tr>
            <tr>
                <td class="files">
                    <ul class="listing">
                        <li v-for="item in folders" @click="path=item.path">
                            <svg class="feather">
                                <use xlink:href="{{ handler.asset_url('feather-sprite.svg') }}#folder" /></svg>
                            {{! item.name }}
                        </li>
                        <li v-for="item in files" @click="load(item.path)">
                            <svg class="feather">
                                <use xlink:href="{{ handler.asset_url('feather-sprite.svg') }}#file" /></svg>
                            {{! item.name }}
                        </li>
                    </ul>
                </td>
                <td class="entry">
                    <textarea :value="content" @input="update"></textarea>
                </td>
                <td class="preview">
                    <s3browser v-show="images"></s3browser>
                    <div v-html="mdown" v-show="!images"></div>
                </td>
            </tr>
        </table>
    </div>
    <script type="text/html" id="s3_browser">
        <div class="s3browser">
            <p class="breadcrumb">
                <a @click="back(0)">path:</a>
                <a v-for="(item, index) in path_items" @click="back(index+1)">/{{! item }}</a>
            </p>
            <p class="upload">
                <form enctype="multipart/form-data" @submit.prevent="uploadFiles">
                    <input type="file" ref="file" multiple="multiple">
                    <input type="submit" value="Upload Image" name="submit">
                    <span class="icn-spinner" v-if="loading">
                        <svg class="feather">
                            <use xlink:href="{{ handler.asset_url('feather-sprite.svg') }}#loader" /></svg>
                    </span>
                </form>
            </p>
            <p class="error" v-if="error">{{! error }}</p>
            <ul class="listing">
                <li v-for="item in folders" @click="path=item.Prefix">
                    <svg class="feather">
                        <use xlink:href="{{ handler.asset_url('feather-sprite.svg') }}#folder" /></svg>
                    {{! item.name }}
                </li>
                <li v-for="item in files" @click="file=item.Key">
                    <svg class="feather">
                        <use xlink:href="{{ handler.asset_url('feather-sprite.svg') }}#image" /></svg>
                    {{! item.name }}
                </li>
            </ul>
            <div class="image-preview" v-if="filepath">
                <button @click="copytoclipboard">
                    <svg class="feather">
                        <use xlink:href="{{ handler.asset_url('feather-sprite.svg') }}#clipboard" />
                    </svg>
                </button>
                <img :src="filepath" />
            </div>
        </div>
    </script>
    <script type="text/javascript">
        window.duckdown_config = {
            "imgPath": "{{ handler.img_path }}"
        }
    </script>
    <script src="{{ handler.asset_url('editor.js') }}" type="module"></script>
</body>

</html>