/**
 * Shared URLs for application review (submitted forms + draft tabs).
 * - Applicants: `/dashboard/documents/review`
 * - Quản trị: `/dashboard/admin/applications/review` (không có Phiếu đánh giá).
 * - Hội đồng: `/dashboard/council/applications/review` (Phiếu đánh giá).
 */
export const FORMS_VIEW_SEARCH_PARAM = "formsView";

/** Which tab is active in {@link ReviewFormsPanel} (`report` | `application` | `contribution` | `bundle_review` | `evaluation`). */
export const REVIEW_FORMS_TAB_SEARCH_PARAM = "reviewTab";

export const APPLICANT_DOCUMENTS_REVIEW_PATH = "/dashboard/documents/review";

export const STAFF_APPLICATION_REVIEW_PATH = "/dashboard/admin/applications/review";

/** Hội đồng (editor): Phiếu đánh giá + duyệt. */
export const COUNCIL_APPLICATION_REVIEW_PATH = "/dashboard/council/applications/review";

export function buildApplicationReviewHref(options: {
  applicationId: string;
  returnTo: string;
  /** Read-only forms (same as applicant “eye” action). */
  viewOnly?: boolean;
}): string {
  const { applicationId, returnTo, viewOnly = false } = options;
  const sp = new URLSearchParams();
  sp.set("applicationId", applicationId);
  sp.set("returnTo", returnTo);
  if (viewOnly) sp.set(FORMS_VIEW_SEARCH_PARAM, "1");
  return `${APPLICANT_DOCUMENTS_REVIEW_PATH}?${sp.toString()}`;
}

/** Admin inbox: staff review route (no Phiếu đánh giá tab). */
export function buildStaffApplicationReviewHref(options: {
  applicationId: string;
  returnTo: string;
  viewOnly?: boolean;
  reviewTab?: "report" | "application" | "contribution" | "bundle_review" | "evaluation";
}): string {
  const { applicationId, returnTo, viewOnly = false, reviewTab } = options;
  const sp = new URLSearchParams();
  sp.set("applicationId", applicationId);
  sp.set("returnTo", returnTo);
  if (viewOnly) sp.set(FORMS_VIEW_SEARCH_PARAM, "1");
  if (reviewTab) sp.set(REVIEW_FORMS_TAB_SEARCH_PARAM, reviewTab);
  return `${STAFF_APPLICATION_REVIEW_PATH}?${sp.toString()}`;
}

/** Hội đồng: council review route (includes Phiếu đánh giá). */
export function buildCouncilApplicationReviewHref(options: {
  applicationId: string;
  returnTo: string;
  viewOnly?: boolean;
  reviewTab?: "report" | "application" | "contribution" | "bundle_review" | "evaluation";
}): string {
  const { applicationId, returnTo, viewOnly = false, reviewTab } = options;
  const sp = new URLSearchParams();
  sp.set("applicationId", applicationId);
  sp.set("returnTo", returnTo);
  if (viewOnly) sp.set(FORMS_VIEW_SEARCH_PARAM, "1");
  if (reviewTab) sp.set(REVIEW_FORMS_TAB_SEARCH_PARAM, reviewTab);
  return `${COUNCIL_APPLICATION_REVIEW_PATH}?${sp.toString()}`;
}
