"use client";
import {
  JsonApiContext
} from "../chunk-VOXD3ZLY.mjs";
import {
  __name
} from "../chunk-PAWJFY3S.mjs";

// src/testing/providers/MockJsonApiProvider.tsx
import { jsx } from "react/jsx-runtime";
var defaultMockConfig = {
  apiUrl: "https://api.test.com",
  tokenGetter: /* @__PURE__ */ __name(async () => "mock-token-for-testing", "tokenGetter"),
  languageGetter: /* @__PURE__ */ __name(async () => "en", "languageGetter"),
  defaultHeaders: {},
  onError: /* @__PURE__ */ __name(() => {
  }, "onError"),
  cacheConfig: {
    defaultProfile: "default"
  }
};
function MockJsonApiProvider({ children, config }) {
  const mergedConfig = {
    ...defaultMockConfig,
    ...config
  };
  return /* @__PURE__ */ jsx(JsonApiContext.Provider, { value: mergedConfig, children });
}
__name(MockJsonApiProvider, "MockJsonApiProvider");

// src/testing/factories/createMockModule.ts
function createMockModule(options) {
  class MockModel {
    static {
      __name(this, "MockModel");
    }
    id = "mock-id";
    type = options.name;
  }
  return {
    name: options.name,
    cache: options.cache,
    inclusions: options.inclusions,
    model: MockModel
  };
}
__name(createMockModule, "createMockModule");

// src/testing/factories/createMockResponse.ts
function createMockResponse(options = {}) {
  const {
    data = null,
    ok = true,
    response = ok ? 200 : 500,
    error = ok ? "" : "Error",
    meta,
    self,
    next,
    prev
  } = options;
  const mockResponse = {
    ok,
    response,
    data,
    error,
    meta,
    self,
    next,
    prev
  };
  if (next) {
    mockResponse.nextPage = async () => createMockResponse({ ...options, next: void 0, prev: self });
  }
  if (prev) {
    mockResponse.prevPage = async () => createMockResponse({ ...options, prev: void 0, next: self });
  }
  return mockResponse;
}
__name(createMockResponse, "createMockResponse");
function createMockErrorResponse(statusCode, errorMessage) {
  return createMockResponse({
    ok: false,
    response: statusCode,
    error: errorMessage,
    data: null
  });
}
__name(createMockErrorResponse, "createMockErrorResponse");

// src/testing/factories/createMockService.ts
import { vi } from "vitest";
function createMockService(options = {}) {
  const defaultResponse = options.defaultResponse ?? createMockResponse({ ok: true });
  return {
    get: vi.fn().mockResolvedValue(defaultResponse),
    post: vi.fn().mockResolvedValue(defaultResponse),
    put: vi.fn().mockResolvedValue(defaultResponse),
    patch: vi.fn().mockResolvedValue(defaultResponse),
    delete: vi.fn().mockResolvedValue(defaultResponse)
  };
}
__name(createMockService, "createMockService");
function createMockErrorService(statusCode = 500, errorMessage = "Error") {
  const errorResponse = createMockResponse({
    ok: false,
    response: statusCode,
    error: errorMessage
  });
  return {
    get: vi.fn().mockResolvedValue(errorResponse),
    post: vi.fn().mockResolvedValue(errorResponse),
    put: vi.fn().mockResolvedValue(errorResponse),
    patch: vi.fn().mockResolvedValue(errorResponse),
    delete: vi.fn().mockResolvedValue(errorResponse)
  };
}
__name(createMockErrorService, "createMockErrorService");

// src/testing/factories/createMockApiData.ts
function createMockApiData(options) {
  const {
    type,
    id = `mock-${type}-${Math.random().toString(36).substring(7)}`,
    attributes = {},
    relationships = {},
    included = [],
    createdAt = /* @__PURE__ */ new Date(),
    updatedAt = /* @__PURE__ */ new Date(),
    self
  } = options;
  const jsonApiData = {
    type,
    id,
    attributes: {
      ...attributes,
      createdAt: createdAt.toISOString(),
      updatedAt: updatedAt.toISOString()
    },
    relationships
  };
  const mockData = {
    get included() {
      return included;
    },
    get type() {
      return type;
    },
    get id() {
      return id;
    },
    get createdAt() {
      return createdAt;
    },
    get updatedAt() {
      return updatedAt;
    },
    get self() {
      return self;
    },
    get jsonApi() {
      return jsonApiData;
    },
    generateApiUrl: /* @__PURE__ */ __name((params) => {
      const baseUrl = `/${type}/${id}`;
      if (params) {
        const searchParams = new URLSearchParams(params);
        return `${baseUrl}?${searchParams.toString()}`;
      }
      return baseUrl;
    }, "generateApiUrl"),
    dehydrate: /* @__PURE__ */ __name(() => ({
      jsonApi: jsonApiData,
      included,
      allData: [jsonApiData]
    }), "dehydrate"),
    rehydrate: /* @__PURE__ */ __name(function(_data) {
      return this;
    }, "rehydrate"),
    createJsonApi: /* @__PURE__ */ __name((data) => ({
      type,
      id,
      attributes: data
    }), "createJsonApi")
  };
  Object.keys(attributes).forEach((key) => {
    Object.defineProperty(mockData, key, {
      get: /* @__PURE__ */ __name(() => attributes[key], "get"),
      enumerable: true
    });
  });
  return mockData;
}
__name(createMockApiData, "createMockApiData");
function createMockApiDataList(type, count, attributesFactory) {
  return Array.from(
    { length: count },
    (_, index) => createMockApiData({
      type,
      id: `${index + 1}`,
      attributes: attributesFactory?.(index) ?? {}
    })
  );
}
__name(createMockApiDataList, "createMockApiDataList");

// src/testing/matchers/jsonApiMatchers.ts
import { expect } from "vitest";
var jsonApiMatchers = {
  /**
   * Asserts that the response has a valid JSON:API structure with type and id.
   */
  toBeValidJsonApi(received) {
    const data = Array.isArray(received?.data) ? received.data[0] : received?.data;
    const hasType = typeof data?.type === "string" && data.type.length > 0;
    const hasId = typeof data?.id === "string" && data.id.length > 0;
    const isValid = hasType && hasId;
    return {
      pass: isValid,
      message: /* @__PURE__ */ __name(() => isValid ? `Expected response not to be valid JSON:API, but it has type "${data?.type}" and id "${data?.id}"` : `Expected response to be valid JSON:API with type and id, but got type: ${JSON.stringify(data?.type)}, id: ${JSON.stringify(data?.id)}`, "message")
    };
  },
  /**
   * Asserts that the response data has the expected JSON:API type.
   */
  toHaveJsonApiType(received, expectedType) {
    const data = Array.isArray(received?.data) ? received.data[0] : received?.data;
    const actualType = data?.type;
    const pass = actualType === expectedType;
    return {
      pass,
      message: /* @__PURE__ */ __name(() => pass ? `Expected response not to have JSON:API type "${expectedType}"` : `Expected response to have JSON:API type "${expectedType}", but got "${actualType}"`, "message")
    };
  },
  /**
   * Asserts that the response data has an attribute with the expected value.
   */
  toHaveJsonApiAttribute(received, attributeName, expectedValue) {
    const data = Array.isArray(received?.data) ? received.data[0] : received?.data;
    const attributes = data?.attributes ?? {};
    const hasAttribute = attributeName in attributes;
    const actualValue = attributes[attributeName];
    if (expectedValue === void 0) {
      return {
        pass: hasAttribute,
        message: /* @__PURE__ */ __name(() => hasAttribute ? `Expected response not to have JSON:API attribute "${attributeName}"` : `Expected response to have JSON:API attribute "${attributeName}", but it was not found. Available attributes: ${Object.keys(attributes).join(", ") || "none"}`, "message")
      };
    }
    const valuesMatch = actualValue === expectedValue;
    return {
      pass: hasAttribute && valuesMatch,
      message: /* @__PURE__ */ __name(() => hasAttribute && valuesMatch ? `Expected response not to have JSON:API attribute "${attributeName}" with value "${expectedValue}"` : !hasAttribute ? `Expected response to have JSON:API attribute "${attributeName}", but it was not found` : `Expected JSON:API attribute "${attributeName}" to be "${expectedValue}", but got "${actualValue}"`, "message")
    };
  },
  /**
   * Asserts that the response data has the specified relationship.
   */
  toHaveJsonApiRelationship(received, relationshipName) {
    const data = Array.isArray(received?.data) ? received.data[0] : received?.data;
    const relationships = data?.relationships ?? {};
    const hasRelationship = relationshipName in relationships;
    return {
      pass: hasRelationship,
      message: /* @__PURE__ */ __name(() => hasRelationship ? `Expected response not to have JSON:API relationship "${relationshipName}"` : `Expected response to have JSON:API relationship "${relationshipName}", but it was not found. Available relationships: ${Object.keys(relationships).join(", ") || "none"}`, "message")
    };
  },
  /**
   * Asserts that the response data array has the expected length.
   */
  toHaveJsonApiLength(received, expectedLength) {
    const data = received?.data;
    const isArray = Array.isArray(data);
    const actualLength = isArray ? data.length : data ? 1 : 0;
    const pass = actualLength === expectedLength;
    return {
      pass,
      message: /* @__PURE__ */ __name(() => pass ? `Expected response not to have ${expectedLength} items` : `Expected response to have ${expectedLength} items, but got ${actualLength}`, "message")
    };
  }
};
function extendExpectWithJsonApiMatchers() {
  expect.extend(jsonApiMatchers);
}
__name(extendExpectWithJsonApiMatchers, "extendExpectWithJsonApiMatchers");

// src/testing/utils/renderWithProviders.tsx
import { render } from "@testing-library/react";
import { render as render2, screen, waitFor, fireEvent, within } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { jsx as jsx2 } from "react/jsx-runtime";
function renderWithProviders(ui, options = {}) {
  const { jsonApiConfig, wrapper: AdditionalWrapper, ...renderOptions } = options;
  function AllProviders({ children }) {
    const content = /* @__PURE__ */ jsx2(MockJsonApiProvider, { config: jsonApiConfig, children });
    if (AdditionalWrapper) {
      return /* @__PURE__ */ jsx2(AdditionalWrapper, { children: content });
    }
    return content;
  }
  __name(AllProviders, "AllProviders");
  return render(ui, { wrapper: AllProviders, ...renderOptions });
}
__name(renderWithProviders, "renderWithProviders");
export {
  MockJsonApiProvider,
  createMockApiData,
  createMockApiDataList,
  createMockErrorResponse,
  createMockErrorService,
  createMockModule,
  createMockResponse,
  createMockService,
  defaultMockConfig,
  extendExpectWithJsonApiMatchers,
  fireEvent,
  jsonApiMatchers,
  render2 as render,
  renderWithProviders,
  screen,
  userEvent,
  waitFor,
  within
};
//# sourceMappingURL=index.mjs.map