import { html, htmlResponse } from "https://esm.town/v/postpostscript/html";
import { Layout } from "https://esm.town/v/postpostscript/htmlComponentLibrary";
import { getValNameFromUrl } from "https://esm.town/v/postpostscript/meta";
import { Ribbon } from "https://esm.town/v/postpostscript/Ribbon";
import { vueSfc, vueSfcInline } from "https://esm.town/v/postpostscript/vue";
export const CounterSetup = vueSfc(
"CounterSetup",
`
<script setup lang="ts">
const model = defineModel<number>()
</script>
<template>
<button @click="model += 1">inc from setup</button>
</template>
<style scoped>
button {
color: green;
}
</style>
`,
);
export const CounterModule = vueSfc(
"CounterModule",
`
<script lang="ts">
export default {
props: {
modelValue: {
type: Number,
required: true,
},
},
emits: ['update:modelValue'],
}
</script>
<template>
<button @click="$emit('update:modelValue', $props.modelValue + 1)">inc from module</button>
</template>
<style scoped>
button {
color: red;
}
</style>
`,
);
export default function(req: Request) {
return htmlResponse`
${
Layout({
ribbonProps: {
title: 'fork me on val.town',
fork: true,
},
}, {
default: () =>
html`
${vueSfcInline`
<script setup lang="ts">
import { ref } from "vue"
import { CounterSetup, CounterModule } from "${import.meta.url}";
const value = ref(0)
</script>
<template>
<p>counter: {{ value }}</p>
<CounterSetup v-model="value" />
<CounterModule v-model="value" />
</template>
`}
`,
})
}
`;
}