/**
 * The profile listing's filter shape and its empty value.
 *
 * Four components outside the filter form import these — two card components
 * and two profile tabs — so they were being pulled out of a form component
 * that none of them render. They are the contract between the chips, the
 * modal and the query; the form is one consumer of that contract.
 */
export interface FiltersData {
  startDate: string;
  endDate: string;
  category: string;
  status: string;
  tags?: string[];
  opportunity_type?: string;
  opportunity_status?: string;
  /**
   * The role the profile owner played in the activity — `Participant` or
   * `Provider`. Set by the chips above the listing, not by the filter modal;
   * it rides along here so it reaches the query the same way
   * `opportunity_type` does. Empty means both.
   */
  profile_activity_tag?: string;
}

export const EMPTY_PROFILE_FILTERS: FiltersData = {
  startDate: "",
  endDate: "",
  category: "",
  status: "",
  tags: [],
  opportunity_type: "",
  opportunity_status: "",
};

/** What the filter modal needs from whoever opens it. */
export interface ProfileFilterFormProps {
  onApply: (filters: FiltersData) => void;
  initialValues?: FiltersData;
  formikRef?: React.RefObject<{ submitForm: () => Promise<void> } | null>;
  onDirtyChange?: (dirty: boolean) => void;
  isEventFilter?: boolean; // Optional prop to indicate if this is for events
  type?: boolean;
  activeTab?: string;
  allowDevelopmentRole?: boolean; // To identify which tab is active
}

/** Normalize legacy dropdown values and keep a hidden role out of non-development queries. */
export function profileOpportunityChip(value?: string): "all" | "volunteer" | "development" {
  if (value === "learn" || value === "learn_serve_opportunity") return "development";
  if (value === "volunteer" || value === "volunteer_opportunity") return "volunteer";
  return "all";
}
export function resolveProfileOpportunityFilters(filters: FiltersData, override?: string): FiltersData {
  const type = profileOpportunityChip(override || filters.opportunity_type);
  return { ...filters, opportunity_type: type === "development" ? "learn_serve_opportunity" : type === "volunteer" ? "volunteer_opportunity" : "",
    profile_activity_tag: type === "development" ? filters.profile_activity_tag || "" : "" };
}
