export function getExtension(fileName, fallback = 'jpg') {
  const parts = fileName.split('.');
  return parts.length > 1 ? parts.pop().toLowerCase() : fallback;
}

export function clampDigits(value, fallback = 3) {
  return Math.max(1, Math.min(6, parseInt(value, 10) || fallback));
}

export function buildSequentialName(fileName, index, { prefix, digits }) {
  const ext = getExtension(fileName);
  return `${prefix}_${String(index + 1).padStart(digits, '0')}.${ext}`;
}

export function getNameFormat(prefixInput, digitsInput, digitsFallback = 3) {
  return {
    prefix: prefixInput.value.trim() || 'photo',
    digits: clampDigits(digitsInput.value, digitsFallback),
  };
}
