import { _ as __nuxt_component_0 } from './Card-BkfpdQZ7.mjs';
import { a as __nuxt_component_1 } from './Button-Dgqz5RR8.mjs';
import { _ as __nuxt_component_2, u as useApi } from './useApi-CFWxoIea.mjs';
import { _ as __nuxt_component_3 } from './FormGroup-UXO0FHfr.mjs';
import { _ as __nuxt_component_4 } from './Select-ByGZz9s4.mjs';
import { _ as __nuxt_component_5 } from './Input-ckU7qZlb.mjs';
import { _ as __nuxt_component_6 } from './Badge-2SB8hHdz.mjs';
import { defineComponent, ref, computed, mergeProps, withCtx, unref, isRef, createVNode, createTextVNode, toDisplayString, openBlock, createBlock, createCommentVNode, Fragment, renderList, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrRenderComponent, ssrInterpolate, ssrRenderList, ssrRenderClass } from 'vue/server-renderer';
import { _ as _export_sfc } from './_plugin-vue_export-helper-1tPrXgE0.mjs';
import 'tailwind-merge';
import './selectMenu-B2FUotwL.mjs';
import './server.mjs';
import '../nitro/nitro.mjs';
import 'node:path';
import 'node:module';
import 'node:fs';
import 'node:os';
import 'dotenv';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:crypto';
import 'node:async_hooks';
import 'node:url';
import 'node:net';
import '@iconify/utils';
import 'consola';
import 'vue-router';
import '@vueuse/core';
import '@iconify/vue';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/utils';
import 'unhead/plugins';
import './nuxt-link-B3UD8izG.mjs';
import './index-Dy4Tu7MB.mjs';
import '@iconify/utils/lib/css/icon';
import 'perfect-debounce';

const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "schedule",
  __ssrInlineRender: true,
  setup(__props) {
    const api = useApi();
    const data = ref(null);
    const loading = ref(false);
    const saving = ref(false);
    const fixing = ref(false);
    const removingId = ref(null);
    const removingCurrent = ref(false);
    const loadError = ref("");
    const actionMessage = ref("");
    const actionOk = ref(false);
    const selectedCron = ref("");
    const envFile = ref("");
    const presetOptions = computed(
      () => {
        var _a, _b;
        return ((_b = (_a = data.value) == null ? void 0 : _a.presets) != null ? _b : []).map((p) => ({
          label: `${p.label} (${p.cron})`,
          value: p.cron
        }));
      }
    );
    const currentEntry = computed(() => {
      var _a, _b;
      return (_b = (_a = data.value) == null ? void 0 : _a.entries.find((e) => e.current)) != null ? _b : null;
    });
    const backendLabel = computed(() => {
      var _a;
      const b = (_a = data.value) == null ? void 0 : _a.backend;
      if (b === "launchd") return "LaunchAgent";
      if (b === "schtasks") return "Task Scheduler";
      return "cron";
    });
    function syncFormFromCurrent(entry) {
      var _a;
      if (entry == null ? void 0 : entry.cron) {
        selectedCron.value = entry.cron;
        const ei = entry.extraArgs.indexOf("-e");
        envFile.value = ei >= 0 && entry.extraArgs[ei + 1] ? entry.extraArgs[ei + 1] : "";
      } else if ((_a = data.value) == null ? void 0 : _a.presets[0]) {
        selectedCron.value = data.value.presets[0].cron;
        envFile.value = "";
      }
    }
    async function reload() {
      var _a, _b, _c;
      loading.value = true;
      loadError.value = "";
      try {
        data.value = await api("/api/schedule");
        syncFormFromCurrent(currentEntry.value);
      } catch (err) {
        const msg = (_c = (_b = (_a = err == null ? void 0 : err.data) == null ? void 0 : _a.statusMessage) != null ? _b : err == null ? void 0 : err.message) != null ? _c : "Failed to load schedules";
        loadError.value = msg;
      } finally {
        loading.value = false;
      }
    }
    function flash(ok, message) {
      actionOk.value = ok;
      actionMessage.value = message;
    }
    async function saveSchedule() {
      var _a, _b, _c;
      saving.value = true;
      actionMessage.value = "";
      try {
        const res = await api("/api/schedule", {
          method: "POST",
          body: { cron: selectedCron.value, envFile: envFile.value || void 0 }
        });
        flash(true, res.message);
        await reload();
      } catch (err) {
        const msg = (_c = (_b = (_a = err == null ? void 0 : err.data) == null ? void 0 : _a.statusMessage) != null ? _b : err == null ? void 0 : err.message) != null ? _c : "Failed to set schedule";
        flash(false, msg);
      } finally {
        saving.value = false;
      }
    }
    async function removeRow(id) {
      var _a, _b, _c;
      removingId.value = id;
      actionMessage.value = "";
      try {
        const res = await api(`/api/schedule/${id}`, {
          method: "DELETE"
        });
        flash(true, res.message);
        await reload();
      } catch (err) {
        const msg = (_c = (_b = (_a = err == null ? void 0 : err.data) == null ? void 0 : _a.statusMessage) != null ? _b : err == null ? void 0 : err.message) != null ? _c : "Failed to remove schedule";
        flash(false, msg);
      } finally {
        removingId.value = null;
      }
    }
    async function removeCurrent() {
      const entry = currentEntry.value;
      if (!entry) return;
      removingCurrent.value = true;
      try {
        await removeRow(entry.id);
      } finally {
        removingCurrent.value = false;
      }
    }
    async function runFix() {
      var _a, _b, _c;
      fixing.value = true;
      actionMessage.value = "";
      try {
        const res = await api(
          "/api/schedule/fix",
          { method: "POST" }
        );
        flash(true, res.message);
        await reload();
      } catch (err) {
        const msg = (_c = (_b = (_a = err == null ? void 0 : err.data) == null ? void 0 : _a.statusMessage) != null ? _b : err == null ? void 0 : err.message) != null ? _c : "Failed to fix schedules";
        flash(false, msg);
      } finally {
        fixing.value = false;
      }
    }
    return (_ctx, _push, _parent, _attrs) => {
      const _component_UCard = __nuxt_component_0;
      const _component_UButton = __nuxt_component_1;
      const _component_UAlert = __nuxt_component_2;
      const _component_UFormGroup = __nuxt_component_3;
      const _component_USelect = __nuxt_component_4;
      const _component_UInput = __nuxt_component_5;
      const _component_UBadge = __nuxt_component_6;
      _push(`<div${ssrRenderAttrs(mergeProps({ class: "schedule-page" }, _attrs))} data-v-a7d25770>`);
      _push(ssrRenderComponent(_component_UCard, null, {
        header: withCtx((_, _push2, _parent2, _scopeId) => {
          var _a, _b, _c, _d, _e, _f;
          if (_push2) {
            _push2(`<div class="flex items-center justify-between gap-3 flex-wrap" data-v-a7d25770${_scopeId}><div data-v-a7d25770${_scopeId}><h1 class="text-lg font-semibold" data-v-a7d25770${_scopeId}>Schedule</h1><p class="text-xs text-gray-500 mt-1" data-v-a7d25770${_scopeId}> Automatic <code data-v-a7d25770${_scopeId}>aidev run</code> for <code data-v-a7d25770${_scopeId}>${ssrInterpolate(((_a = unref(data)) == null ? void 0 : _a.currentCwd) || "\u2014")}</code>`);
            if (unref(data)) {
              _push2(`<span class="ml-2 text-gray-400" data-v-a7d25770${_scopeId}> via ${ssrInterpolate(unref(backendLabel))}</span>`);
            } else {
              _push2(`<!---->`);
            }
            _push2(`</p></div><div class="flex items-center gap-2" data-v-a7d25770${_scopeId}>`);
            _push2(ssrRenderComponent(_component_UButton, {
              color: "gray",
              variant: "ghost",
              size: "sm",
              loading: unref(loading),
              disabled: unref(loading),
              onClick: reload
            }, {
              default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(` Refresh `);
                } else {
                  return [
                    createTextVNode(" Refresh ")
                  ];
                }
              }),
              _: 1
            }, _parent2, _scopeId));
            if ((_b = unref(data)) == null ? void 0 : _b.fixSupported) {
              _push2(ssrRenderComponent(_component_UButton, {
                color: "gray",
                variant: "soft",
                size: "sm",
                loading: unref(fixing),
                disabled: unref(fixing) || !((_c = unref(data)) == null ? void 0 : _c.entries.length),
                onClick: runFix
              }, {
                default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                  if (_push3) {
                    _push3(` Fix paths `);
                  } else {
                    return [
                      createTextVNode(" Fix paths ")
                    ];
                  }
                }),
                _: 1
              }, _parent2, _scopeId));
            } else {
              _push2(`<!---->`);
            }
            _push2(`</div></div>`);
          } else {
            return [
              createVNode("div", { class: "flex items-center justify-between gap-3 flex-wrap" }, [
                createVNode("div", null, [
                  createVNode("h1", { class: "text-lg font-semibold" }, "Schedule"),
                  createVNode("p", { class: "text-xs text-gray-500 mt-1" }, [
                    createTextVNode(" Automatic "),
                    createVNode("code", null, "aidev run"),
                    createTextVNode(" for "),
                    createVNode("code", null, toDisplayString(((_d = unref(data)) == null ? void 0 : _d.currentCwd) || "\u2014"), 1),
                    unref(data) ? (openBlock(), createBlock("span", {
                      key: 0,
                      class: "ml-2 text-gray-400"
                    }, " via " + toDisplayString(unref(backendLabel)), 1)) : createCommentVNode("", true)
                  ])
                ]),
                createVNode("div", { class: "flex items-center gap-2" }, [
                  createVNode(_component_UButton, {
                    color: "gray",
                    variant: "ghost",
                    size: "sm",
                    loading: unref(loading),
                    disabled: unref(loading),
                    onClick: reload
                  }, {
                    default: withCtx(() => [
                      createTextVNode(" Refresh ")
                    ]),
                    _: 1
                  }, 8, ["loading", "disabled"]),
                  ((_e = unref(data)) == null ? void 0 : _e.fixSupported) ? (openBlock(), createBlock(_component_UButton, {
                    key: 0,
                    color: "gray",
                    variant: "soft",
                    size: "sm",
                    loading: unref(fixing),
                    disabled: unref(fixing) || !((_f = unref(data)) == null ? void 0 : _f.entries.length),
                    onClick: runFix
                  }, {
                    default: withCtx(() => [
                      createTextVNode(" Fix paths ")
                    ]),
                    _: 1
                  }, 8, ["loading", "disabled"])) : createCommentVNode("", true)
                ])
              ])
            ];
          }
        }),
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          var _a, _b;
          if (_push2) {
            if (unref(loadError)) {
              _push2(ssrRenderComponent(_component_UAlert, {
                color: "red",
                variant: "soft",
                title: unref(loadError),
                class: "mb-4"
              }, null, _parent2, _scopeId));
            } else {
              _push2(`<!---->`);
            }
            if (unref(actionMessage)) {
              _push2(ssrRenderComponent(_component_UAlert, {
                color: unref(actionOk) ? "green" : "red",
                variant: "soft",
                title: unref(actionOk) ? "Done" : "Failed",
                description: unref(actionMessage),
                class: "mb-4"
              }, null, _parent2, _scopeId));
            } else {
              _push2(`<!---->`);
            }
            _push2(ssrRenderComponent(_component_UCard, {
              class: "mb-4",
              ui: { body: { padding: "p-4" } }
            }, {
              header: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(`<h2 class="text-base font-semibold" data-v-a7d25770${_scopeId2}>Schedule this project</h2>`);
                } else {
                  return [
                    createVNode("h2", { class: "text-base font-semibold" }, "Schedule this project")
                  ];
                }
              }),
              default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(`<p class="text-sm text-gray-600 mb-4" data-v-a7d25770${_scopeId2}> Sets or replaces the schedule for the connected working directory. Only preset intervals are supported (same as <code data-v-a7d25770${_scopeId2}>aidev schedule set</code>). </p><div class="grid gap-4 md:grid-cols-2" data-v-a7d25770${_scopeId2}>`);
                  _push3(ssrRenderComponent(_component_UFormGroup, { label: "Interval" }, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(ssrRenderComponent(_component_USelect, {
                          modelValue: unref(selectedCron),
                          "onUpdate:modelValue": ($event) => isRef(selectedCron) ? selectedCron.value = $event : null,
                          options: unref(presetOptions)
                        }, null, _parent4, _scopeId3));
                      } else {
                        return [
                          createVNode(_component_USelect, {
                            modelValue: unref(selectedCron),
                            "onUpdate:modelValue": ($event) => isRef(selectedCron) ? selectedCron.value = $event : null,
                            options: unref(presetOptions)
                          }, null, 8, ["modelValue", "onUpdate:modelValue", "options"])
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                  _push3(ssrRenderComponent(_component_UFormGroup, {
                    label: "Custom env file",
                    help: "Optional \u2014 passed as -e to the scheduled run (same as CLI)."
                  }, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(ssrRenderComponent(_component_UInput, {
                          modelValue: unref(envFile),
                          "onUpdate:modelValue": ($event) => isRef(envFile) ? envFile.value = $event : null,
                          placeholder: "/path/to/.env.aidev",
                          autocomplete: "off"
                        }, null, _parent4, _scopeId3));
                      } else {
                        return [
                          createVNode(_component_UInput, {
                            modelValue: unref(envFile),
                            "onUpdate:modelValue": ($event) => isRef(envFile) ? envFile.value = $event : null,
                            placeholder: "/path/to/.env.aidev",
                            autocomplete: "off"
                          }, null, 8, ["modelValue", "onUpdate:modelValue"])
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                  _push3(`</div><div class="mt-4 flex items-center gap-2" data-v-a7d25770${_scopeId2}>`);
                  _push3(ssrRenderComponent(_component_UButton, {
                    color: "primary",
                    size: "sm",
                    loading: unref(saving),
                    disabled: unref(saving) || !unref(selectedCron),
                    onClick: saveSchedule
                  }, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(`${ssrInterpolate(unref(currentEntry) ? "Update schedule" : "Enable schedule")}`);
                      } else {
                        return [
                          createTextVNode(toDisplayString(unref(currentEntry) ? "Update schedule" : "Enable schedule"), 1)
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                  if (unref(currentEntry)) {
                    _push3(ssrRenderComponent(_component_UButton, {
                      color: "red",
                      variant: "soft",
                      size: "sm",
                      loading: unref(removingCurrent),
                      disabled: unref(removingCurrent),
                      onClick: removeCurrent
                    }, {
                      default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                        if (_push4) {
                          _push4(` Remove for this project `);
                        } else {
                          return [
                            createTextVNode(" Remove for this project ")
                          ];
                        }
                      }),
                      _: 1
                    }, _parent3, _scopeId2));
                  } else {
                    _push3(`<!---->`);
                  }
                  _push3(`</div>`);
                } else {
                  return [
                    createVNode("p", { class: "text-sm text-gray-600 mb-4" }, [
                      createTextVNode(" Sets or replaces the schedule for the connected working directory. Only preset intervals are supported (same as "),
                      createVNode("code", null, "aidev schedule set"),
                      createTextVNode("). ")
                    ]),
                    createVNode("div", { class: "grid gap-4 md:grid-cols-2" }, [
                      createVNode(_component_UFormGroup, { label: "Interval" }, {
                        default: withCtx(() => [
                          createVNode(_component_USelect, {
                            modelValue: unref(selectedCron),
                            "onUpdate:modelValue": ($event) => isRef(selectedCron) ? selectedCron.value = $event : null,
                            options: unref(presetOptions)
                          }, null, 8, ["modelValue", "onUpdate:modelValue", "options"])
                        ]),
                        _: 1
                      }),
                      createVNode(_component_UFormGroup, {
                        label: "Custom env file",
                        help: "Optional \u2014 passed as -e to the scheduled run (same as CLI)."
                      }, {
                        default: withCtx(() => [
                          createVNode(_component_UInput, {
                            modelValue: unref(envFile),
                            "onUpdate:modelValue": ($event) => isRef(envFile) ? envFile.value = $event : null,
                            placeholder: "/path/to/.env.aidev",
                            autocomplete: "off"
                          }, null, 8, ["modelValue", "onUpdate:modelValue"])
                        ]),
                        _: 1
                      })
                    ]),
                    createVNode("div", { class: "mt-4 flex items-center gap-2" }, [
                      createVNode(_component_UButton, {
                        color: "primary",
                        size: "sm",
                        loading: unref(saving),
                        disabled: unref(saving) || !unref(selectedCron),
                        onClick: saveSchedule
                      }, {
                        default: withCtx(() => [
                          createTextVNode(toDisplayString(unref(currentEntry) ? "Update schedule" : "Enable schedule"), 1)
                        ]),
                        _: 1
                      }, 8, ["loading", "disabled"]),
                      unref(currentEntry) ? (openBlock(), createBlock(_component_UButton, {
                        key: 0,
                        color: "red",
                        variant: "soft",
                        size: "sm",
                        loading: unref(removingCurrent),
                        disabled: unref(removingCurrent),
                        onClick: removeCurrent
                      }, {
                        default: withCtx(() => [
                          createTextVNode(" Remove for this project ")
                        ]),
                        _: 1
                      }, 8, ["loading", "disabled"])) : createCommentVNode("", true)
                    ])
                  ];
                }
              }),
              _: 1
            }, _parent2, _scopeId));
            _push2(ssrRenderComponent(_component_UCard, null, {
              header: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(`<h2 class="text-base font-semibold" data-v-a7d25770${_scopeId2}>All schedules</h2>`);
                } else {
                  return [
                    createVNode("h2", { class: "text-base font-semibold" }, "All schedules")
                  ];
                }
              }),
              default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  if (unref(data) && !unref(data).entries.length) {
                    _push3(`<p class="text-sm text-gray-600" data-v-a7d25770${_scopeId2}> No aidev schedules are configured on this machine. </p>`);
                  } else if (unref(data)) {
                    _push3(`<div class="overflow-x-auto" data-v-a7d25770${_scopeId2}><table class="schedule-table w-full text-sm text-gray-900 dark:text-gray-100" data-v-a7d25770${_scopeId2}><thead data-v-a7d25770${_scopeId2}><tr data-v-a7d25770${_scopeId2}><th data-v-a7d25770${_scopeId2}>ID</th><th data-v-a7d25770${_scopeId2}>Directory</th><th data-v-a7d25770${_scopeId2}>Schedule</th><th data-v-a7d25770${_scopeId2}>Cron</th><th data-v-a7d25770${_scopeId2}>Args</th><th data-v-a7d25770${_scopeId2}></th></tr></thead><tbody data-v-a7d25770${_scopeId2}><!--[-->`);
                    ssrRenderList(unref(data).entries, (row) => {
                      _push3(`<tr class="${ssrRenderClass(
                        row.current ? "bg-green-50 dark:bg-green-950/50" : void 0
                      )}" data-v-a7d25770${_scopeId2}><td data-v-a7d25770${_scopeId2}>${ssrInterpolate(row.id)}</td><td data-v-a7d25770${_scopeId2}><code class="cwd-cell text-gray-800 dark:text-gray-200" data-v-a7d25770${_scopeId2}>${ssrInterpolate(row.cwd)}</code>`);
                      if (row.current) {
                        _push3(ssrRenderComponent(_component_UBadge, {
                          color: "green",
                          variant: "soft",
                          size: "xs",
                          class: "ml-2"
                        }, {
                          default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                            if (_push4) {
                              _push4(` this project `);
                            } else {
                              return [
                                createTextVNode(" this project ")
                              ];
                            }
                          }),
                          _: 2
                        }, _parent3, _scopeId2));
                      } else {
                        _push3(`<!---->`);
                      }
                      _push3(`</td><td data-v-a7d25770${_scopeId2}>${ssrInterpolate(row.label)}</td><td data-v-a7d25770${_scopeId2}><code class="text-gray-800 dark:text-gray-200" data-v-a7d25770${_scopeId2}>${ssrInterpolate(row.cron || "\u2014")}</code></td><td data-v-a7d25770${_scopeId2}>`);
                      if (row.extraArgs.length) {
                        _push3(`<code class="text-gray-800 dark:text-gray-200" data-v-a7d25770${_scopeId2}>${ssrInterpolate(row.extraArgs.join(" "))}</code>`);
                      } else {
                        _push3(`<span class="text-gray-500 dark:text-gray-400" data-v-a7d25770${_scopeId2}>\u2014</span>`);
                      }
                      _push3(`</td><td class="text-right" data-v-a7d25770${_scopeId2}>`);
                      _push3(ssrRenderComponent(_component_UButton, {
                        color: "red",
                        variant: "ghost",
                        size: "xs",
                        loading: unref(removingId) === row.id,
                        disabled: unref(removingId) !== null,
                        onClick: ($event) => removeRow(row.id)
                      }, {
                        default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                          if (_push4) {
                            _push4(` Remove `);
                          } else {
                            return [
                              createTextVNode(" Remove ")
                            ];
                          }
                        }),
                        _: 2
                      }, _parent3, _scopeId2));
                      _push3(`</td></tr>`);
                    });
                    _push3(`<!--]--></tbody></table></div>`);
                  } else {
                    _push3(`<!---->`);
                  }
                } else {
                  return [
                    unref(data) && !unref(data).entries.length ? (openBlock(), createBlock("p", {
                      key: 0,
                      class: "text-sm text-gray-600"
                    }, " No aidev schedules are configured on this machine. ")) : unref(data) ? (openBlock(), createBlock("div", {
                      key: 1,
                      class: "overflow-x-auto"
                    }, [
                      createVNode("table", { class: "schedule-table w-full text-sm text-gray-900 dark:text-gray-100" }, [
                        createVNode("thead", null, [
                          createVNode("tr", null, [
                            createVNode("th", null, "ID"),
                            createVNode("th", null, "Directory"),
                            createVNode("th", null, "Schedule"),
                            createVNode("th", null, "Cron"),
                            createVNode("th", null, "Args"),
                            createVNode("th")
                          ])
                        ]),
                        createVNode("tbody", null, [
                          (openBlock(true), createBlock(Fragment, null, renderList(unref(data).entries, (row) => {
                            return openBlock(), createBlock("tr", {
                              key: row.id,
                              class: row.current ? "bg-green-50 dark:bg-green-950/50" : void 0
                            }, [
                              createVNode("td", null, toDisplayString(row.id), 1),
                              createVNode("td", null, [
                                createVNode("code", { class: "cwd-cell text-gray-800 dark:text-gray-200" }, toDisplayString(row.cwd), 1),
                                row.current ? (openBlock(), createBlock(_component_UBadge, {
                                  key: 0,
                                  color: "green",
                                  variant: "soft",
                                  size: "xs",
                                  class: "ml-2"
                                }, {
                                  default: withCtx(() => [
                                    createTextVNode(" this project ")
                                  ]),
                                  _: 1
                                })) : createCommentVNode("", true)
                              ]),
                              createVNode("td", null, toDisplayString(row.label), 1),
                              createVNode("td", null, [
                                createVNode("code", { class: "text-gray-800 dark:text-gray-200" }, toDisplayString(row.cron || "\u2014"), 1)
                              ]),
                              createVNode("td", null, [
                                row.extraArgs.length ? (openBlock(), createBlock("code", {
                                  key: 0,
                                  class: "text-gray-800 dark:text-gray-200"
                                }, toDisplayString(row.extraArgs.join(" ")), 1)) : (openBlock(), createBlock("span", {
                                  key: 1,
                                  class: "text-gray-500 dark:text-gray-400"
                                }, "\u2014"))
                              ]),
                              createVNode("td", { class: "text-right" }, [
                                createVNode(_component_UButton, {
                                  color: "red",
                                  variant: "ghost",
                                  size: "xs",
                                  loading: unref(removingId) === row.id,
                                  disabled: unref(removingId) !== null,
                                  onClick: ($event) => removeRow(row.id)
                                }, {
                                  default: withCtx(() => [
                                    createTextVNode(" Remove ")
                                  ]),
                                  _: 1
                                }, 8, ["loading", "disabled", "onClick"])
                              ])
                            ], 2);
                          }), 128))
                        ])
                      ])
                    ])) : createCommentVNode("", true)
                  ];
                }
              }),
              _: 1
            }, _parent2, _scopeId));
            if (unref(data) && !unref(data).fixSupported) {
              _push2(ssrRenderComponent(_component_UAlert, {
                color: "amber",
                variant: "soft",
                title: "Fix paths unavailable on Windows",
                description: "Re-run schedule set for each project if binaries or paths changed.",
                class: "mt-4"
              }, null, _parent2, _scopeId));
            } else {
              _push2(`<!---->`);
            }
            if (((_a = unref(data)) == null ? void 0 : _a.backend) === "launchd") {
              _push2(ssrRenderComponent(_component_UAlert, {
                color: "blue",
                variant: "soft",
                title: "macOS uses LaunchAgents",
                class: "mt-4"
              }, {
                description: withCtx((_2, _push3, _parent3, _scopeId2) => {
                  if (_push3) {
                    _push3(` Schedules run in your GUI session so AI tools can access the login Keychain. Cron is not used on macOS. `);
                  } else {
                    return [
                      createTextVNode(" Schedules run in your GUI session so AI tools can access the login Keychain. Cron is not used on macOS. ")
                    ];
                  }
                }),
                _: 1
              }, _parent2, _scopeId));
            } else {
              _push2(`<!---->`);
            }
          } else {
            return [
              unref(loadError) ? (openBlock(), createBlock(_component_UAlert, {
                key: 0,
                color: "red",
                variant: "soft",
                title: unref(loadError),
                class: "mb-4"
              }, null, 8, ["title"])) : createCommentVNode("", true),
              unref(actionMessage) ? (openBlock(), createBlock(_component_UAlert, {
                key: 1,
                color: unref(actionOk) ? "green" : "red",
                variant: "soft",
                title: unref(actionOk) ? "Done" : "Failed",
                description: unref(actionMessage),
                class: "mb-4"
              }, null, 8, ["color", "title", "description"])) : createCommentVNode("", true),
              createVNode(_component_UCard, {
                class: "mb-4",
                ui: { body: { padding: "p-4" } }
              }, {
                header: withCtx(() => [
                  createVNode("h2", { class: "text-base font-semibold" }, "Schedule this project")
                ]),
                default: withCtx(() => [
                  createVNode("p", { class: "text-sm text-gray-600 mb-4" }, [
                    createTextVNode(" Sets or replaces the schedule for the connected working directory. Only preset intervals are supported (same as "),
                    createVNode("code", null, "aidev schedule set"),
                    createTextVNode("). ")
                  ]),
                  createVNode("div", { class: "grid gap-4 md:grid-cols-2" }, [
                    createVNode(_component_UFormGroup, { label: "Interval" }, {
                      default: withCtx(() => [
                        createVNode(_component_USelect, {
                          modelValue: unref(selectedCron),
                          "onUpdate:modelValue": ($event) => isRef(selectedCron) ? selectedCron.value = $event : null,
                          options: unref(presetOptions)
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "options"])
                      ]),
                      _: 1
                    }),
                    createVNode(_component_UFormGroup, {
                      label: "Custom env file",
                      help: "Optional \u2014 passed as -e to the scheduled run (same as CLI)."
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_UInput, {
                          modelValue: unref(envFile),
                          "onUpdate:modelValue": ($event) => isRef(envFile) ? envFile.value = $event : null,
                          placeholder: "/path/to/.env.aidev",
                          autocomplete: "off"
                        }, null, 8, ["modelValue", "onUpdate:modelValue"])
                      ]),
                      _: 1
                    })
                  ]),
                  createVNode("div", { class: "mt-4 flex items-center gap-2" }, [
                    createVNode(_component_UButton, {
                      color: "primary",
                      size: "sm",
                      loading: unref(saving),
                      disabled: unref(saving) || !unref(selectedCron),
                      onClick: saveSchedule
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(unref(currentEntry) ? "Update schedule" : "Enable schedule"), 1)
                      ]),
                      _: 1
                    }, 8, ["loading", "disabled"]),
                    unref(currentEntry) ? (openBlock(), createBlock(_component_UButton, {
                      key: 0,
                      color: "red",
                      variant: "soft",
                      size: "sm",
                      loading: unref(removingCurrent),
                      disabled: unref(removingCurrent),
                      onClick: removeCurrent
                    }, {
                      default: withCtx(() => [
                        createTextVNode(" Remove for this project ")
                      ]),
                      _: 1
                    }, 8, ["loading", "disabled"])) : createCommentVNode("", true)
                  ])
                ]),
                _: 1
              }),
              createVNode(_component_UCard, null, {
                header: withCtx(() => [
                  createVNode("h2", { class: "text-base font-semibold" }, "All schedules")
                ]),
                default: withCtx(() => [
                  unref(data) && !unref(data).entries.length ? (openBlock(), createBlock("p", {
                    key: 0,
                    class: "text-sm text-gray-600"
                  }, " No aidev schedules are configured on this machine. ")) : unref(data) ? (openBlock(), createBlock("div", {
                    key: 1,
                    class: "overflow-x-auto"
                  }, [
                    createVNode("table", { class: "schedule-table w-full text-sm text-gray-900 dark:text-gray-100" }, [
                      createVNode("thead", null, [
                        createVNode("tr", null, [
                          createVNode("th", null, "ID"),
                          createVNode("th", null, "Directory"),
                          createVNode("th", null, "Schedule"),
                          createVNode("th", null, "Cron"),
                          createVNode("th", null, "Args"),
                          createVNode("th")
                        ])
                      ]),
                      createVNode("tbody", null, [
                        (openBlock(true), createBlock(Fragment, null, renderList(unref(data).entries, (row) => {
                          return openBlock(), createBlock("tr", {
                            key: row.id,
                            class: row.current ? "bg-green-50 dark:bg-green-950/50" : void 0
                          }, [
                            createVNode("td", null, toDisplayString(row.id), 1),
                            createVNode("td", null, [
                              createVNode("code", { class: "cwd-cell text-gray-800 dark:text-gray-200" }, toDisplayString(row.cwd), 1),
                              row.current ? (openBlock(), createBlock(_component_UBadge, {
                                key: 0,
                                color: "green",
                                variant: "soft",
                                size: "xs",
                                class: "ml-2"
                              }, {
                                default: withCtx(() => [
                                  createTextVNode(" this project ")
                                ]),
                                _: 1
                              })) : createCommentVNode("", true)
                            ]),
                            createVNode("td", null, toDisplayString(row.label), 1),
                            createVNode("td", null, [
                              createVNode("code", { class: "text-gray-800 dark:text-gray-200" }, toDisplayString(row.cron || "\u2014"), 1)
                            ]),
                            createVNode("td", null, [
                              row.extraArgs.length ? (openBlock(), createBlock("code", {
                                key: 0,
                                class: "text-gray-800 dark:text-gray-200"
                              }, toDisplayString(row.extraArgs.join(" ")), 1)) : (openBlock(), createBlock("span", {
                                key: 1,
                                class: "text-gray-500 dark:text-gray-400"
                              }, "\u2014"))
                            ]),
                            createVNode("td", { class: "text-right" }, [
                              createVNode(_component_UButton, {
                                color: "red",
                                variant: "ghost",
                                size: "xs",
                                loading: unref(removingId) === row.id,
                                disabled: unref(removingId) !== null,
                                onClick: ($event) => removeRow(row.id)
                              }, {
                                default: withCtx(() => [
                                  createTextVNode(" Remove ")
                                ]),
                                _: 1
                              }, 8, ["loading", "disabled", "onClick"])
                            ])
                          ], 2);
                        }), 128))
                      ])
                    ])
                  ])) : createCommentVNode("", true)
                ]),
                _: 1
              }),
              unref(data) && !unref(data).fixSupported ? (openBlock(), createBlock(_component_UAlert, {
                key: 2,
                color: "amber",
                variant: "soft",
                title: "Fix paths unavailable on Windows",
                description: "Re-run schedule set for each project if binaries or paths changed.",
                class: "mt-4"
              })) : createCommentVNode("", true),
              ((_b = unref(data)) == null ? void 0 : _b.backend) === "launchd" ? (openBlock(), createBlock(_component_UAlert, {
                key: 3,
                color: "blue",
                variant: "soft",
                title: "macOS uses LaunchAgents",
                class: "mt-4"
              }, {
                description: withCtx(() => [
                  createTextVNode(" Schedules run in your GUI session so AI tools can access the login Keychain. Cron is not used on macOS. ")
                ]),
                _: 1
              })) : createCommentVNode("", true)
            ];
          }
        }),
        _: 1
      }, _parent));
      _push(`</div>`);
    };
  }
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/schedule.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const schedule = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a7d25770"]]);

export { schedule as default };
//# sourceMappingURL=schedule-Pz7_wUvq.mjs.map
