const isDevelopment = process.env.NODE_ENV === "development";
const isTest = process.env.NODE_ENV === "test";
const enableTestingAttributes = isDevelopment || isTest;
function createTestId(component, element, action) {
  if (!enableTestingAttributes) return void 0;
  const parts = [component, element, action].filter(Boolean);
  return parts.join("-");
}
function createCyId(domain, element) {
  if (!enableTestingAttributes) return void 0;
  return `${domain}-${element}`;
}
function createStateAttr(state) {
  return state;
}
function createPriorityAttr(priority) {
  return priority;
}
function createTestingProps(config) {
  const props = {};
  if (config.testId) {
    props["data-testid"] = enableTestingAttributes ? config.testId : void 0;
  }
  if (config.cyId) {
    props["data-cy"] = enableTestingAttributes ? config.cyId : void 0;
  }
  if (config.state) {
    props["data-state"] = config.state;
  }
  if (config.priority) {
    props["data-priority"] = config.priority;
  }
  if (config.taskId) {
    props["data-task-id"] = config.taskId;
  }
  if (config.userId) {
    props["data-user-id"] = config.userId;
  }
  return Object.fromEntries(
    Object.entries(props).filter((entry) => entry[1] !== void 0)
  );
}
function createAriaLabel(template, values) {
  return template.replace(/\{(\w+)\}/g, (match, key) => {
    return String(values[key] ?? match);
  });
}
const testingPatterns = {
  // Task/Todo components
  task: {
    card: (taskId) => createTestingProps({
      testId: createTestId("task", "card"),
      cyId: createCyId("task", "item"),
      taskId
    }),
    checkbox: () => createTestingProps({
      testId: createTestId("task", "checkbox"),
      cyId: createCyId("task", "toggle")
    }),
    title: () => createTestingProps({
      testId: createTestId("task", "title"),
      cyId: createCyId("task", "title")
    }),
    deleteButton: () => createTestingProps({
      testId: createTestId("task", "delete", "button"),
      cyId: createCyId("task", "delete")
    })
  },
  // Navigation components
  nav: {
    searchDropdown: () => createTestingProps({
      testId: createTestId("nav", "search", "dropdown"),
      cyId: createCyId("nav", "search")
    }),
    notifications: () => createTestingProps({
      testId: createTestId("nav", "notifications", "button"),
      cyId: createCyId("nav", "notifications")
    }),
    userMenu: () => createTestingProps({
      testId: createTestId("nav", "user", "menu"),
      cyId: createCyId("nav", "user-menu")
    })
  },
  // Form components
  form: {
    input: (fieldName) => createTestingProps({
      testId: createTestId("form", fieldName, "input"),
      cyId: createCyId("form", fieldName)
    }),
    submitButton: () => createTestingProps({
      testId: createTestId("form", "submit", "button"),
      cyId: createCyId("form", "submit")
    })
  }
};
const keyboardHelpers = {
  /**
   * Handle Enter and Space key activation
   */
  createActivationHandler: (onActivate) => {
    return (e) => {
      if (e.key === "Enter" || e.key === " ") {
        e.preventDefault();
        onActivate();
      }
    };
  },
  /**
   * Handle Escape key for closing
   */
  createEscapeHandler: (onClose) => {
    return (e) => {
      if (e.key === "Escape") {
        e.preventDefault();
        onClose();
      }
    };
  },
  /**
   * Handle arrow navigation in lists
   */
  createArrowNavigationHandler: (currentIndex, maxIndex, onIndexChange) => {
    return (e) => {
      switch (e.key) {
        case "ArrowDown":
          e.preventDefault();
          onIndexChange(currentIndex < maxIndex ? currentIndex + 1 : 0);
          break;
        case "ArrowUp":
          e.preventDefault();
          onIndexChange(currentIndex > 0 ? currentIndex - 1 : maxIndex);
          break;
      }
    };
  }
};
function createEntityCyId(entitySlug, component, detail) {
  if (!enableTestingAttributes) return void 0;
  const parts = [entitySlug, component, detail].filter(Boolean);
  return parts.join("-");
}
function createEntityTestingHelper(entitySlug) {
  return {
    // Generic (framework-agnostic)
    get: (component, detail) => createEntityCyId(entitySlug, component, detail),
    // Page
    page: () => createEntityCyId(entitySlug, "page"),
    formPage: () => createEntityCyId(entitySlug, "form-page"),
    // Form
    form: () => createEntityCyId(entitySlug, "form"),
    formSubmit: () => createEntityCyId(entitySlug, "form-submit"),
    formCancel: () => createEntityCyId(entitySlug, "form-cancel"),
    // Fields
    field: (name) => createEntityCyId(entitySlug, "field", name),
    fieldOption: (name, value) => createEntityCyId(entitySlug, `field-${name}-option`, value),
    fieldError: (name) => createEntityCyId(entitySlug, `field-${name}`, "error"),
    // Sections
    section: (name) => createEntityCyId(entitySlug, "section", name),
    // Card
    card: (id) => createEntityCyId(entitySlug, "card", id),
    // List/Table
    table: () => createEntityCyId(entitySlug, "table"),
    row: (id) => createEntityCyId(entitySlug, "row", id),
    createBtn: () => createEntityCyId(entitySlug, "create-btn"),
    searchInput: () => createEntityCyId(entitySlug, "search-input"),
    // Filters
    filter: (field) => createEntityCyId(entitySlug, "filter", field),
    filterTrigger: (field) => createEntityCyId(entitySlug, `filter-${field}`, "trigger"),
    filterOption: (field, value) => createEntityCyId(entitySlug, `filter-${field}-option`, value),
    // Actions
    action: (action, id) => createEntityCyId(entitySlug, `action-${action}`, id),
    actionsTrigger: (id) => createEntityCyId(entitySlug, "actions-trigger", id),
    // Dialogs
    confirmDelete: () => createEntityCyId(entitySlug, "confirm-delete"),
    confirmDeleteBtn: () => createEntityCyId(entitySlug, "confirm-delete-btn"),
    cancelDeleteBtn: () => createEntityCyId(entitySlug, "cancel-delete-btn")
  };
}
export {
  createAriaLabel,
  createCyId,
  createEntityCyId,
  createEntityTestingHelper,
  createPriorityAttr,
  createStateAttr,
  createTestId,
  createTestingProps,
  keyboardHelpers,
  testingPatterns
};
