"use client";
import { readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
import { createCrud, updateCrud, deleteCrud } from "@open-mercato/ui/backend/utils/crud";
function createStaffActivitiesAdapter(translator) {
  return {
    list: async ({ entityId }) => {
      const params = new URLSearchParams({
        pageSize: "50",
        sortField: "occurredAt",
        sortDir: "desc"
      });
      if (entityId) params.set("entityId", entityId);
      const payload = await readApiResultOrThrow(
        `/api/staff/activities?${params.toString()}`,
        void 0,
        { errorMessage: translator("staff.teamMembers.detail.activities.loadError", "Failed to load activities.") }
      );
      return Array.isArray(payload?.items) ? payload.items : [];
    },
    create: async ({ entityId, activityType, subject, body, occurredAt, customFields }) => {
      await createCrud("staff/activities", {
        entityId,
        activityType,
        subject: subject ?? void 0,
        body: body ?? void 0,
        occurredAt: occurredAt ?? void 0,
        ...customFields ? { customFields } : {}
      }, {
        errorMessage: translator("staff.teamMembers.detail.activities.error", "Failed to save activity")
      });
    },
    update: async ({ id, patch }) => {
      await updateCrud("staff/activities", {
        id,
        entityId: patch.entityId,
        activityType: patch.activityType,
        subject: patch.subject ?? void 0,
        body: patch.body ?? void 0,
        occurredAt: patch.occurredAt ?? void 0,
        ...patch.customFields ? { customFields: patch.customFields } : {}
      }, {
        errorMessage: translator("staff.teamMembers.detail.activities.error", "Failed to save activity")
      });
    },
    delete: async ({ id }) => {
      await deleteCrud("staff/activities", {
        id,
        errorMessage: translator("staff.teamMembers.detail.activities.deleteError", "Failed to delete activity.")
      });
    }
  };
}
export {
  createStaffActivitiesAdapter
};
//# sourceMappingURL=activitiesAdapter.js.map
