/**
 * Helper that maps an Aurora `Property` to a `<au-data-table>` column-width
 * pair (`size` for rigid columns; `size + minSize` for elastic columns).
 *
 * The consumer-side `<au-data-table>` distinguishes RIGID columns (locked to
 * `size`) from ELASTIC columns (locked to `minSize`, absorbing remaining
 * space) via `isElasticColumn` / `isRigidColumn` in
 * `frontend/src/@aurora/components/data-table/types.ts`. Without explicit
 * `size`/`minSize` values, TanStack injects its defaults (`size: 150`,
 * `minSize: 20`), which collapses every column into the elastic-no-minimum
 * bucket and causes width jitter between pages.
 *
 * The heuristic table is closed (decided at proposal time) and tuned for the
 * `iam/*` aggregates rendered with sort-buttons in narrow viewports. If a
 * specific column needs different sizing, the consumer hand-edits the
 * generated `<mod>.columns.ts` and accepts `.origin` review on next regen.
 *
 * Used by the `<mod>.columns.ts.eta` template via
 * `it.filters.getColumnSizingForProperty(property, options?)`.
 */
/** FK relation label sizing — applies regardless of the underlying property type. */
const FK_LABEL_SIZING = { minSize: 140, size: 220 };
/** Default branch for unmatched `PropertyType` values — keeps the helper total. */
const DEFAULT_SIZING = { minSize: 120, size: 200 };
const VARCHAR_LONG_THRESHOLD = 100;
const VARCHAR_SHORT = { minSize: 120, size: 200 };
const VARCHAR_LONG = { minSize: 160, size: 300 };
const TEXT_SIZING = { minSize: 160, size: 300 };
const PASSWORD_SIZING = { minSize: 120, size: 200 };
/**
 * Resolve the sizing pair for a column emitted from `property`.
 *
 * - With `options.isFkLabel === true`, returns `{ size: 220, minSize: 140 }`
 *   regardless of the underlying type — the column displays the related
 *   aggregate's display field, not the FK's UUID.
 * - Otherwise dispatches by `property.type`. For `varchar` and `char`,
 *   inspects `property.maxLength ?? property.length` (same precedence as
 *   `getDefaultSpan` in `property-width.ts`); `> 100` → long-form, else →
 *   short-form. `text` is unconditionally long-form. Unmatched types fall
 *   through to `DEFAULT_SIZING` (elastic short-form).
 */
export function getColumnSizingForProperty(property, options) {
    if (options?.isFkLabel === true) {
        return FK_LABEL_SIZING;
    }
    switch (property.type) {
        case 'boolean': {
            return { size: 100 };
        }
        case 'date':
        case 'timestamp': {
            return { size: 140 };
        }
        case 'enum': {
            return { size: 120 };
        }
        case 'bigint':
        case 'decimal':
        case 'float':
        case 'int':
        case 'smallint': {
            return { size: 100 };
        }
        case 'id': {
            return { size: 280 };
        }
        case 'char':
        case 'varchar': {
            const length = property.maxLength ?? property.length;
            if (length !== undefined && length > VARCHAR_LONG_THRESHOLD) {
                return VARCHAR_LONG;
            }
            return VARCHAR_SHORT;
        }
        case 'text': {
            return TEXT_SIZING;
        }
        case 'password': {
            return PASSWORD_SIZING;
        }
        default: {
            return DEFAULT_SIZING;
        }
    }
}
