import { AbstractControl, ValidationErrors, ValidatorFn } from "@angular/forms";

export const CONSTANTS = {
    POR_ORGACODE: '0005',
};

export const pageSizeOptions = [
  { value: 10, label: '10' },
  { value: 20, label: '20' },
  { value: 50, label: '50' },
];

export const toDateAfterFromDateValidator: ValidatorFn = (
  control: AbstractControl
): ValidationErrors | null => {

  const from = control.get('fromDate')?.value;
  const to = control.get('toDate')?.value;

  if (!from || !to) return null;

  // Normalize to midnight to avoid timezone bugs
  const fromDate = new Date(from);
  const toDate = new Date(to);

  fromDate.setHours(0, 0, 0, 0);
  toDate.setHours(0, 0, 0, 0);

  const today = new Date();
  today.setHours(0, 0, 0, 0);

  // Rule 1: fromDate must be < toDate
  if (fromDate > toDate) {
    return { fromDateGreaterThanOrEqualToToDate: true };
  }

  // Rule 2: no future dates
  if (fromDate > today || toDate > today) {
    return { futureDateNotAllowed: true };
  }

  return null;
};

export const EXCEL_FILE_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';

export const EXCEL_FILE_EXTENSION = '.xlsx';

export const LOGGING_DETAILS_FILE_NAME = 'Activity-Logs-Details';

export const TRANSACTION_LOGS_FILE_NAME = 'Transaction-Logs-Details';

export const LOGIN_ROUTE = '/login';
