<script setup lang="ts">
import { ref } from "vue";
import { useMainStore } from "@/stores/main";
import { required } from "@/utils";
import { useI18n } from "vue-i18n";

const mainStore = useMainStore();
const { t } = useI18n();
const valid = ref(true);
const dialog = ref(false);
const title = ref("");
const Form = ref();

async function Submit() {
  setTimeout(() => {
    dialog.value = true;
  }, 2000);
  await (Form as any).value.validate();
  if (valid.value) {
    valid.value = false;
  }
}
</script>

<template>
  <v-container fluid>
    <v-card class="ma-3 pa-3">
      <v-card-title primary-title>
        <h3 class="card-title mb-3">{{ t("makeArticle") }}</h3>
      </v-card-title>
      <v-card-text>
        <v-form v-model="valid" ref="Form">
          <v-text-field
            :label="$t('articleTitle')"
            v-model="title"
            :rules="required()"
            prepend-icon="title"
          >
          </v-text-field>
          <v-text-field :label="$t('articleLink')" prepend-icon="link">
          </v-text-field>
          <v-textarea
            :label="$t('articleContent')"
            prepend-icon="edit_document"
          ></v-textarea>
        </v-form>
      </v-card-text>
      <v-card-actions>
        <v-spacer></v-spacer>
        <v-btn @click="Submit" :disabled="!valid">
          {{ t("send") }}
        </v-btn>
      </v-card-actions>
    </v-card>

    <template>
      <div class="text-center">
        <v-dialog v-model="dialog" width="auto">
          <v-card>
            <v-card-text>
              <section class="d-flex flex-column align-center">
                <v-icon
                  style="font-size: 70px"
                  icon="info"
                  color="orange-darken-3"
                />
                <p class="mt-3">文章處理需要約 5-10 分鐘，敬請耐心等候</p>
              </section>
            </v-card-text>
            <v-card-actions>
              <v-btn color="primary" block @click="dialog = false">
              {{ t("close") }}</v-btn>
            </v-card-actions>
          </v-card>
        </v-dialog>
      </div>
    </template>
  </v-container>
</template>

<style lang="scss">
</style>
