"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const React = require('react');
const button = require('../../../../../../../ui/src/components/button.cjs');
const input = require('../../../../../../../ui/src/components/input.cjs');
const label = require('../../../../../../../ui/src/components/label.cjs');
const kanbanHooks = require('../../hooks/kanban-hooks.cjs');

function ColumnForm({
  boardId,
  columnId,
  column,
  onClose,
  onSuccess
}) {
  const isEditing = !!columnId;
  const { createColumn, updateColumn, isCreating, isUpdating } = kanbanHooks.useColumnMutations();
  const [title, setTitle] = React.useState(column?.title || "");
  const [error, setError] = React.useState(null);
  const isPending = isCreating || isUpdating;
  const handleSubmit = async (e) => {
    e.preventDefault();
    setError(null);
    if (!title.trim()) {
      setError("Title is required");
      return;
    }
    try {
      if (isEditing && columnId) {
        await updateColumn(columnId, { title });
      } else {
        await createColumn({ title, boardId });
      }
      onSuccess();
    } catch (err) {
      setError(err instanceof Error ? err.message : "An error occurred");
    }
  };
  return /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, className: "space-y-4", children: [
    /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
      /* @__PURE__ */ jsxRuntime.jsx(label.Label, { htmlFor: "title", children: "Title *" }),
      /* @__PURE__ */ jsxRuntime.jsx(
        input.Input,
        {
          id: "title",
          value: title,
          onChange: (e) => setTitle(e.target.value),
          placeholder: "e.g., To Do",
          disabled: isPending
        }
      )
    ] }),
    error && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md", children: error }),
    /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2 pt-2", children: [
      /* @__PURE__ */ jsxRuntime.jsx(button.Button, { type: "submit", disabled: isPending, children: isPending ? isEditing ? "Updating..." : "Creating..." : isEditing ? "Update Column" : "Create Column" }),
      /* @__PURE__ */ jsxRuntime.jsx(
        button.Button,
        {
          type: "button",
          variant: "outline",
          onClick: onClose,
          disabled: isPending,
          children: "Cancel"
        }
      )
    ] })
  ] });
}

exports.ColumnForm = ColumnForm;
