export function mapDXFLineTypeToEsri(t,e){if(!t)return"solid";const n=t.toUpperCase(),o=mapBasicLineType(n,e?.pattern?.map((t=>parseFloat(t))));if(o)return o;const r=mapIsoPatterns(n);if(r)return r;const a=mapLineTypePattern(e);return a||"solid"}export function mapBasicLineType(t,e){if(!t)return;const n=t.toUpperCase().trim(),o={BYLAYER:"solid",BYBLOCK:"solid",CONTINUOUS:"solid",HIDDEN:"dash",DASHED:"dash",DASHEDX2:"dash",DASHED2:"dash",CENTER:"dash-dot",CENTERX2:"dash-dot",CENTER2:"dash-dot",DASHDOT:"dash-dot",DOTTED:"dot",DIVIDE:"short-dash",DIVIDEX2:"short-dash-dot",DIVIDE2:"short-dash-dot"};if(o[n])return o[n];if(e?.length){const t=Math.abs(e[0]??0),n=Math.abs(e[1]??0);if(2===e.length)return t<8&&n<6?"short-dash":t>=8&&t<=15&&n>=6&&n<=15?"dash":"long-dash";if(4===e.length)return t<6&&n<6?"short-dash-dot":t>=6&&t<=15&&n>=6&&n<=15?"dash-dot":"long-dash-dot"}}export function mapIsoPatterns(t){const e=t.toUpperCase();return e.includes("LONG")?"long-dash":e.includes("DOUBLE")?"long-dash-dot":e.includes("PHANTOM")?"dash-dot":void 0}export function mapLineTypePattern(t){if(t?.pattern&&Array.isArray(t.pattern)){const e=t.pattern,n=e.some((t=>parseFloat(t)>.2)),o=e.some((t=>0===parseFloat(t)));return n&&!o?"dash":!n&&o?"dot":n&&o?"dash-dot":"solid"}}export function intToRGB(t){if(t>=1&&t<=255)return{1:[255,0,0,1],2:[255,255,0,1],3:[0,255,0,1],4:[0,0,255,1],5:[255,0,255,1],6:[0,255,255,1],7:[255,255,255,1]}[t]||[0,0,0,1];const e=t>>16&255,n=t>>8&255,o=255&t;return 255===e&&255===n&&255===o?[0,0,0,1]:[e,n,o,1]}export const VALID_FILL_STYLES=["backward-diagonal","cross","diagonal-cross","forward-diagonal","horizontal","none","solid","vertical"];export function normalizeFillStyle(t){if("string"!=typeof t)return"solid";const e=t.toLowerCase();if(VALID_FILL_STYLES.includes(e))return e;if(e.startsWith("esrisfs")){const t=e.replace(/^esrisfs/,"").replace(/([a-z])([A-Z])/g,"$1-$2").replace(/_/g,"-").replace(/^[^a-z0-9]+/g,"").toLowerCase(),n="undefined"===t?"none":t;if(VALID_FILL_STYLES.includes(n))return n}return"solid"}export function normalizeLineOutline(t){return{type:"simple-line",color:t?.color??[0,0,0],width:t?.width??1.5}}export function deriveAnnotationMinScale(t,e,n){if(!t||0===e)return 0;const o=Math.max(t.width,t.height),r=Math.max(1,Math.sqrt(e/100));let a=2*o*Math.max(.5,Math.min(n/12,3))/r;return a=Math.max(1e3,Math.min(a,2e7)),Math.round(a)}export function sanitizeSymbolWidth(t){if(void 0!==t&&t>0){const e=t>25?t/100:t;return Math.min(e,25)}return 1.5}