import { _ as __nuxt_component_0 } from './nuxt-link-Cq8xZgFP.mjs';
import { defineComponent, ref, reactive, withAsyncContext, computed, mergeProps, withCtx, createTextVNode, toDisplayString, unref, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrRenderComponent, ssrInterpolate, ssrRenderAttr, ssrRenderClass, ssrIncludeBooleanAttr, ssrLooseContain, ssrLooseEqual, ssrRenderList } from 'vue/server-renderer';
import { _ as _export_sfc, b as useRouter, u as useI18n, a as useHead } from './server.mjs';
import { u as useNotification } from './useNotification-BqDqaGnC.mjs';
import { u as useApiError } from './useApiError-BSStUojq.mjs';
import { u as useFetch } from './fetch-B5NxMLIO.mjs';
import '../nitro/nitro.mjs';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'stream';
import 'events';
import 'http';
import 'crypto';
import 'buffer';
import 'zlib';
import 'https';
import 'net';
import 'tls';
import 'url';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'vue-router';
import '@prisma/client';
import '@prisma/adapter-better-sqlite3';
import 'fs';
import 'path';
import 'fs/promises';
import 'child_process';
import 'node:child_process';
import 'node:url';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/utils';
import '@vue/shared';

const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "new",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    useRouter();
    useNotification();
    useApiError();
    ref(null);
    const isDragging = ref(false);
    const submitting = ref(false);
    const autocompleting = ref(false);
    const { locale, t } = useI18n();
    const form = reactive({
      title: "",
      description: "",
      priority: "",
      parent: "",
      acceptanceCriteria: [""],
      attachments: []
    });
    const errors = reactive({
      title: "",
      description: "",
      attachments: ""
    });
    const { data: issues } = ([__temp, __restore] = withAsyncContext(() => useFetch("/api/issues", "$PR1V20I2qI")), __temp = await __temp, __restore(), __temp);
    const parentSuggestions = computed(() => {
      return (issues.value || []).slice(0, 10);
    });
    const isValid = computed(() => {
      return form.title.trim() && form.description.trim() && !errors.attachments;
    });
    const formatFileSize = (bytes) => {
      if (bytes < 1024) return `${bytes} B`;
      if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
      return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
    };
    useHead({
      title: "New Issue - AutoCode"
    });
    return (_ctx, _push, _parent, _attrs) => {
      const _component_NuxtLink = __nuxt_component_0;
      _push(`<div${ssrRenderAttrs(mergeProps({ class: "new-issue-page" }, _attrs))} data-v-78563ddb><header class="page-header" data-v-78563ddb>`);
      _push(ssrRenderComponent(_component_NuxtLink, {
        to: "/kanban",
        class: "back-link"
      }, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(` ← ${ssrInterpolate(_ctx.$t("nav.kanban"))}`);
          } else {
            return [
              createTextVNode(" ← " + toDisplayString(_ctx.$t("nav.kanban")), 1)
            ];
          }
        }),
        _: 1
      }, _parent));
      _push(`<h1 data-v-78563ddb>${ssrInterpolate(_ctx.$t("nav.newIssue"))}</h1></header><form class="issue-form card" data-v-78563ddb><div class="form-group" data-v-78563ddb><label class="form-label" for="title" data-v-78563ddb>${ssrInterpolate(_ctx.$t("issue.title"))} <span class="required" data-v-78563ddb>*</span></label><div class="title-row" data-v-78563ddb><input id="title"${ssrRenderAttr("value", unref(form).title)} type="text" class="${ssrRenderClass([{ "has-error": unref(errors).title }, "form-input"])}" required data-v-78563ddb><button type="button" class="btn-autocomplete"${ssrIncludeBooleanAttr(unref(autocompleting) || !unref(form).title.trim()) ? " disabled" : ""}${ssrRenderAttr("title", _ctx.$t("autocomplete.tooltip"))} data-v-78563ddb>`);
      if (unref(autocompleting)) {
        _push(`<span class="spinner" data-v-78563ddb></span>`);
      } else {
        _push(`<span class="sparkle" data-v-78563ddb>✨</span>`);
      }
      _push(` ${ssrInterpolate(unref(autocompleting) ? _ctx.$t("autocomplete.loading") : _ctx.$t("autocomplete.button"))}</button></div>`);
      if (unref(errors).title) {
        _push(`<span class="error-text" data-v-78563ddb>${ssrInterpolate(unref(errors).title)}</span>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div><div class="form-group" data-v-78563ddb><label class="form-label" for="description" data-v-78563ddb>${ssrInterpolate(_ctx.$t("issue.description"))} <span class="required" data-v-78563ddb>*</span></label><textarea id="description" class="${ssrRenderClass([{ "has-error": unref(errors).description }, "form-input"])}" rows="8" required data-v-78563ddb>${ssrInterpolate(unref(form).description)}</textarea><p class="form-hint" data-v-78563ddb>${ssrInterpolate(_ctx.$t("form.markdownSupported"))}</p>`);
      if (unref(errors).description) {
        _push(`<span class="error-text" data-v-78563ddb>${ssrInterpolate(unref(errors).description)}</span>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div><div class="form-row" data-v-78563ddb><div class="form-group" data-v-78563ddb><label class="form-label" for="priority" data-v-78563ddb>${ssrInterpolate(_ctx.$t("issue.priority"))}</label><select id="priority" class="form-input" data-v-78563ddb><option value="" data-v-78563ddb${ssrIncludeBooleanAttr(Array.isArray(unref(form).priority) ? ssrLooseContain(unref(form).priority, "") : ssrLooseEqual(unref(form).priority, "")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("form.select"))}</option><option value="low" data-v-78563ddb${ssrIncludeBooleanAttr(Array.isArray(unref(form).priority) ? ssrLooseContain(unref(form).priority, "low") : ssrLooseEqual(unref(form).priority, "low")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("priority.low"))}</option><option value="medium" data-v-78563ddb${ssrIncludeBooleanAttr(Array.isArray(unref(form).priority) ? ssrLooseContain(unref(form).priority, "medium") : ssrLooseEqual(unref(form).priority, "medium")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("priority.medium"))}</option><option value="high" data-v-78563ddb${ssrIncludeBooleanAttr(Array.isArray(unref(form).priority) ? ssrLooseContain(unref(form).priority, "high") : ssrLooseEqual(unref(form).priority, "high")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("priority.high"))}</option><option value="critical" data-v-78563ddb${ssrIncludeBooleanAttr(Array.isArray(unref(form).priority) ? ssrLooseContain(unref(form).priority, "critical") : ssrLooseEqual(unref(form).priority, "critical")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("priority.critical"))}</option></select></div><div class="form-group" data-v-78563ddb><label class="form-label" for="parent" data-v-78563ddb>${ssrInterpolate(_ctx.$t("issue.parent"))}</label><input id="parent"${ssrRenderAttr("value", unref(form).parent)} type="text" class="form-input"${ssrRenderAttr("placeholder", _ctx.$t("form.parentPlaceholder"))} list="parent-suggestions" data-v-78563ddb><datalist id="parent-suggestions" data-v-78563ddb><!--[-->`);
      ssrRenderList(unref(parentSuggestions), (issue) => {
        _push(`<option${ssrRenderAttr("value", issue.key)} data-v-78563ddb>${ssrInterpolate(issue.title)}</option>`);
      });
      _push(`<!--]--></datalist></div></div><div class="form-group" data-v-78563ddb><label class="form-label" data-v-78563ddb>${ssrInterpolate(_ctx.$t("issue.acceptanceCriteria"))}</label><div class="criteria-list" data-v-78563ddb><!--[-->`);
      ssrRenderList(unref(form).acceptanceCriteria, (_, index) => {
        _push(`<div class="criteria-item" data-v-78563ddb><input${ssrRenderAttr("value", unref(form).acceptanceCriteria[index])} type="text" class="form-input"${ssrRenderAttr("placeholder", _ctx.$t("form.criteriaPlaceholder"))} data-v-78563ddb><button type="button" class="btn-icon" data-v-78563ddb>×</button></div>`);
      });
      _push(`<!--]--><button type="button" class="btn btn-secondary btn-sm" data-v-78563ddb> + ${ssrInterpolate(_ctx.$t("form.addCriteria"))}</button></div></div><div class="form-group" data-v-78563ddb><label class="form-label" data-v-78563ddb>${ssrInterpolate(_ctx.$t("issue.attachments"))}</label><div class="${ssrRenderClass([{ dragover: unref(isDragging) }, "dropzone"])}" data-v-78563ddb><input type="file" multiple class="file-input" data-v-78563ddb><p data-v-78563ddb>${ssrInterpolate(_ctx.$t("form.dropFiles"))}</p><button type="button" class="btn btn-secondary btn-sm" data-v-78563ddb>${ssrInterpolate(_ctx.$t("form.browse"))}</button></div>`);
      if (unref(form).attachments.length) {
        _push(`<ul class="attachments-list" data-v-78563ddb><!--[-->`);
        ssrRenderList(unref(form).attachments, (file, index) => {
          _push(`<li data-v-78563ddb><span class="file-name" data-v-78563ddb>${ssrInterpolate(file.name)}</span><span class="file-size" data-v-78563ddb>${ssrInterpolate(formatFileSize(file.size))}</span><button type="button" class="btn-icon" data-v-78563ddb>×</button></li>`);
        });
        _push(`<!--]--></ul>`);
      } else {
        _push(`<!---->`);
      }
      if (unref(errors).attachments) {
        _push(`<span class="error-text" data-v-78563ddb>${ssrInterpolate(unref(errors).attachments)}</span>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div><div class="form-actions" data-v-78563ddb>`);
      _push(ssrRenderComponent(_component_NuxtLink, {
        to: "/kanban",
        class: "btn btn-secondary"
      }, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(`${ssrInterpolate(_ctx.$t("form.cancel"))}`);
          } else {
            return [
              createTextVNode(toDisplayString(_ctx.$t("form.cancel")), 1)
            ];
          }
        }),
        _: 1
      }, _parent));
      _push(`<button type="submit" class="btn btn-primary"${ssrIncludeBooleanAttr(unref(submitting) || !unref(isValid)) ? " disabled" : ""} data-v-78563ddb>${ssrInterpolate(unref(submitting) ? _ctx.$t("form.creating") : _ctx.$t("form.create"))}</button></div></form></div>`);
    };
  }
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/issue/new.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const _new = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-78563ddb"]]);

export { _new as default };
//# sourceMappingURL=new-DMctSKBX.mjs.map
