<template>
	<div id="app">
		<div class="bsky_comment" v-if="cid_root">
			<span v-for="i in api_json.data" class="comment">
				<p class="comment-body" v-if="i.cid_root == cid_root">
					<span v-if="i.did.replace('did:plc:', '') != ''">
						{{ axios_check('/icon/' + i.did.replace('did:plc:', '') + '.jpg') }}
					</span>
					<span v-if="url_check == true && i.did.replace('did:plc:', '') != ''">
						<img :src="'/icon/' + i.did.replace('did:plc:', '') + '.jpg'" class="comment"/>
					</span>
					<span v-else-if="i.avatar">
						<img :src="i.avatar" class="comment"/>
					</span>
					<span class="comment-time" v-if="i.updated_at"><a :href="i.bsky_url" v-if="i.bsky_url">{{ moment(i.updated_at) }}</a></span> <span class="comment-handle" v-if="i.handle"><a :href="'https://' + i.bsky_url.split('/').slice(2,5).join('/')" v-if="i.bsky_url">@{{ i.handle.replace('.bsky.social', '') }}</a></span>
					<span class="comment-text" v-if="i.text">{{ i.text }}</span>
				</p>
			</span>
		</div>
	</div>
</template>

<script>
import {
	Hooper,
  Slide,
  Progress as HooperProgress,
  Pagination as HooperPagination,
  Navigation as HooperNavigation
} from 'hooper';

import 'hooper/dist/hooper.css';
import axios from 'axios'
import moment from "moment";
import fs from 'fs';

var page = 21;
var loc = window.location.pathname;

export default {
  name: 'App',
  components: {
			Hooper,
    Slide,
    HooperProgress,
    HooperPagination,
    HooperNavigation
  },
  data() {
    return {
					loc: window.location.pathname,
					bsky_pds: "https://bsky.social/xrpc",
					bsky_handle: "yui.syui.ai",
					bsky_cursor: null,
					bsky_cid: "",
					bsky_json: null,
					api_url: null,
					api_json: null,
					cid_root: null,
					uri_root: null,
					comment_open: false,
					comment_first: null,
					loading: true,
					avatar_url: "",
					f: null,
					url_check: true,
					url: "/",
					products: [...Array(Number(page)).keys()],
				};
		},
		methods: {
			moment(date) {
				return moment.utc(date).local().format("YYYY.MM.DD");
			},
			load() {
				this.loading = false;
			},
			axios_check(url) {
				axios.get(url)
					.then(response => { 
						this.avatar_url = url;
						this.url_check = true
					})
					.catch(error => {
						this.url_check = false;
						this.avatar_url = "/icon/ai.jpg"
					});
			}
		},
		mounted() {
			if (window.location.host === "localhost:8080") {
				this.api_url = "/api/";
			} else if (window.location.host === "localhost:1313"){
				this.api_url = "https://api.syui.ai";
			} else if (window.location.host === "192.168.11.12:8080"){
				this.api_url = "/api/";
			} else {
				if (location.protocol !== "https:") {
					location.replace("https:" + location.href.substring(location.protocol.length));
				}
				this.api_url = "https://api.syui.ai";
			}
			let url = this.api_url + "/users/2/ma?itemsPerPage=4000";
			axios
				.get(url,{ crossdomain: true })
				.then(
					response => {this.api_json = response
						this.cid_root = this.api_json.data.find((v) => v.blog_url == loc).cid;
						this.uri_root = this.api_json.data.find((v) => v.blog_url == loc).uri;
					}
				);
		}
};
</script>

<style>
body {
	margin: 0px;
}

a {
	text-decoration: none;
}

a span.icon-ai {
	color: #ddd700;
}

.page_n{text-align:center;height:50px}
.hooper-pagination{position:fixed}
.hooper-next,.hooper-prev{background-color:rgba(184,207,224,.24)}
.hooper-indicator{
	background-color:#000;
	display:none;
}

.hooper{
	height:100%;
	text-align:center;
}

.hooper-progress {
	height: 12px;
}

.hooper-progress-inner {
	background-color: #ddd700;
}

button {
	padding: 10px;
	margin: 5px;
	background-color: #fff700;
	color: #313131;
	border: solid 2px;
}

ul.hooper-track {
	padding: 0px;
}

.hooper-list img {
	width:400px;
	border: solid 3px #313131;
	margin: 20px;
}

.page {
	text-align:center;
	background-color: #f1f1f1;
	padding: 50px 0 50px 0;
}

.page a img {
	border: solid 2px #313131;
	width:100px;
	margin: auto;
	display: block;
}

.page_title {
	text-align:center;
	background-color: #313131;
	padding: 100px 0 50px 0;
}

.page_title a img {
	width:100px;
	margin: auto;
	display: block;
}

.page_title head, td, tr, th {
	padding:10px;
	background: #fff;
	border: solid 1px #fff;
}

table {
	text-align: center;
	margin-left: auto;
	margin-right: auto;
	word-break: break-all;
}

.page_data table tbody > thead, td, tr, th {
	background: #fff;
	border: solid 1px #fff;
	padding: 15px 25px 15px 25px;
}

th.row {
	background: #313131;
	border:none;
}

footer {
	text-align: center;
	background: #313131;
	color: #fff;
	padding:50px 0 30px 0;
}

.loading {
	text-align: center;
	font-size: 30px;
	margin-top:100px;
}

span.comment-time {
	float: right;
	padding: 0 5px 0 5px;
	color: #999;
}

span.comment-time a {
	color: #999;
}

span.comment-time a:hover {
	color: rgb(16, 131, 254);
}

span.comment-handle {
	padding: 0 5px 0 5px;
	position: absolute;
}

span.comment-handle a {
	color: #313131;
}

img.comment {
	width:60px;
}

p.comment-body {
	padding: 5px 40px 15px 40px;
	border-bottom: solid 1px #eee;
}

span.comment-text {
	padding:10px;
}

button.comment_open {
	padding:20px 40px 20px 40px;
	background-color: rgba(184,207,224,.24);
	border: none;
	margin:0;
}
button.comment_open:hover {
	color: rgb(16, 131, 254);
}

.comment_open {
	text-align: center;
	width: 100%;
}

.comment_open p a {
	color: rgb(16, 131, 254);
}

.bsky_comment {
	background-color: #fff;
	width: 600px;
	margin: 0px auto;
	border: solid 1px #eee;
}

.bsky_comment_embed {
	background-color: #fff;
	width: 600px;
	margin: 0px auto;
}

.comment {
	background-color: #fff;
}

@media screen and (max-width:1000px) { 
	img {
		width:100%;
	}
	.bsky_comment {
		width:auto;
	}
	.bsky_comment_embed {
		width:auto;
	}
	.page_title a img {
		width:100%;
	}
	.page a img {
		width:160px;
	}
	.hooper-list img {
		border: solid 0px #fff;
		margin:20px 0 0 0;
		width:100%;
	}
	p.comment-body {
		padding: 5px;
	}
	.page_data table tbody > thead, td, tr, th {
		padding:10px;
	}
}

</style>
