"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const React = require('react');
const kanban = require('../../../../../../../ui/src/components/kanban.cjs');
const utils = require('../../../../../../../ui/src/lib/utils.cjs');
const columnContent = require('./column-content.cjs');

function KanbanBoardComponent({
  columns,
  kanbanState,
  onKanbanChange,
  onAddTask,
  onEditTask,
  onEditColumn,
  onDeleteColumn
}) {
  const orderedColumns = React.useMemo(() => {
    const columnMap = new Map(columns.map((c) => [c.id, c]));
    return Object.keys(kanbanState).map((columnId) => {
      const column = columnMap.get(columnId);
      if (!column) return null;
      return {
        ...column,
        tasks: kanbanState[columnId] || []
      };
    }).filter(
      (c) => c !== null
    );
  }, [columns, kanbanState]);
  const mdClass = React.useMemo(() => {
    const gridClassMap = {
      1: "md:grid-cols-1",
      2: "md:grid-cols-2",
      3: "md:grid-cols-3",
      4: "md:grid-cols-4",
      5: "md:grid-cols-5",
      6: "md:grid-cols-6"
    };
    return gridClassMap[orderedColumns.length] || "md:grid-cols-6";
  }, [orderedColumns.length]);
  return /* @__PURE__ */ jsxRuntime.jsxs(
    kanban.Kanban,
    {
      orientation: "horizontal",
      value: kanbanState,
      onValueChange: onKanbanChange,
      getItemValue: (item) => item.id,
      children: [
        /* @__PURE__ */ jsxRuntime.jsx(
          kanban.KanbanBoard,
          {
            className: utils.cn(
              "flex flex-col gap-4 md:auto-rows-fr md:grid-cols-1 md:grid min-h-[400px]",
              mdClass
            ),
            children: orderedColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(
              columnContent.ColumnContent,
              {
                column,
                onAddTask: () => onAddTask(column.id),
                onEditTask: (taskId) => onEditTask(column.id, taskId),
                onEditColumn: () => onEditColumn(column.id),
                onDeleteColumn: () => onDeleteColumn(column.id)
              },
              column.id
            ))
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx(kanban.KanbanOverlay, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-full rounded-md bg-primary/10" }) })
      ]
    }
  );
}
const KanbanBoard = React.memo(KanbanBoardComponent);

exports.KanbanBoard = KanbanBoard;
