import*as i18n from"../i18n/i18n.js";import*as Platform from"../platform/platform.js";const UIStrings={dec:"`dec`",hex:"`hex`",oct:"`oct`",sci:"`sci`",littleEndian:"Little Endian",bigEndian:"Big Endian",integerBit:"Integer 8-bit",integer16Bit:"Integer 16-bit",integer32Bit:"Integer 32-bit",integer64Bit:"Integer 64-bit",floatBit:"Float 32-bit",float64Bit:"Float 64-bit",string:"String"},str_=i18n.i18n.registerUIStrings("linear_memory_inspector/ValueInterpreterDisplayUtils.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export const VALUE_INTEPRETER_MAX_NUM_BYTES=8;export const DEFAULT_MODE_MAPPING=new Map([["Integer 8-bit","dec"],["Integer 16-bit","dec"],["Integer 32-bit","dec"],["Integer 64-bit","dec"],["Float 32-bit","dec"],["Float 64-bit","dec"]]);export const VALUE_TYPE_MODE_LIST=["dec","hex","oct","sci"];export function valueTypeModeToLocalizedString(t){switch(t){case"dec":return i18nString(UIStrings.dec);case"hex":return i18nString(UIStrings.hex);case"oct":return i18nString(UIStrings.oct);case"sci":return i18nString(UIStrings.sci);default:return Platform.assertNever(t,`Unknown mode: ${t}`)}}export function endiannessToLocalizedString(t){switch(t){case"Little Endian":return i18nString(UIStrings.littleEndian);case"Big Endian":return i18nString(UIStrings.bigEndian);default:return Platform.assertNever(t,`Unknown endianness: ${t}`)}}export function valueTypeToLocalizedString(t){switch(t){case"Integer 8-bit":return i18nString(UIStrings.integerBit);case"Integer 16-bit":return i18nString(UIStrings.integer16Bit);case"Integer 32-bit":return i18nString(UIStrings.integer32Bit);case"Integer 64-bit":return i18nString(UIStrings.integer64Bit);case"Float 32-bit":return i18nString(UIStrings.floatBit);case"Float 64-bit":return i18nString(UIStrings.float64Bit);default:return Platform.assertNever(t,`Unknown value type: ${t}`)}}export function isValidMode(t,e){switch(t){case"Integer 8-bit":case"Integer 16-bit":case"Integer 32-bit":case"Integer 64-bit":return"dec"===e||"hex"===e||"oct"===e;case"Float 32-bit":case"Float 64-bit":return"sci"===e||"dec"===e;default:return Platform.assertNever(t,`Unknown value type: ${t}`)}}export function isNumber(t){switch(t){case"Integer 8-bit":case"Integer 16-bit":case"Integer 32-bit":case"Integer 64-bit":case"Float 32-bit":case"Float 64-bit":return!0;default:return!1}}export function format(t){const e=new DataView(t.buffer),n="Little Endian"===t.endianness;let r;try{switch(t.type){case"Integer 8-bit":return r=t.signed?e.getInt8(0):e.getUint8(0),formatInteger(r,t.mode);case"Integer 16-bit":return r=t.signed?e.getInt16(0,n):e.getUint16(0,n),formatInteger(r,t.mode);case"Integer 32-bit":return r=t.signed?e.getInt32(0,n):e.getUint32(0,n),formatInteger(r,t.mode);case"Integer 64-bit":return r=t.signed?e.getBigInt64(0,n):e.getBigUint64(0,n),formatInteger(r,t.mode);case"Float 32-bit":return r=e.getFloat32(0,n),formatFloat(r,t.mode);case"Float 64-bit":return r=e.getFloat64(0,n),formatFloat(r,t.mode);default:return Platform.assertNever(t.type,`Unknown value type: ${t.type}`)}}catch(i){return"N/A"}}export function formatFloat(t,e){switch(e){case"dec":return t.toFixed(2).toString();case"sci":return t.toExponential(2).toString();default:throw new Error(`Unknown mode for floats: ${e}.`)}}export function formatInteger(t,e){switch(e){case"dec":return t.toString();case"hex":return"0x"+t.toString(16).toUpperCase();case"oct":return t.toString(8);default:throw new Error(`Unknown mode for integers: ${e}.`)}}