/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const FILE_TYPES=["html","js","css","json","all"];const defaultTabs={"all":{spaces:4}};function Tabs(){this._tabs={}};Tabs.prototype.validate=function(t,msgContext){var fileType,entry,count=0;if(!t){this._tabs=defaultTabs;return true}if(typeof t!=="object"){msgContext.error("invalid \"tabs\" property - object expected");this._tabs=defaultTabs;return false}for(fileType in t){if(!_isFileType(fileType)){msgContext.error("invalid 'tabs' property - unknown file type \""+fileType+"\"");this._tabs=defaultTabs;return false}entry=t[fileType];if(entry.spaces&&typeof entry.spaces!=="number"||entry.stops&&!_isTabStops(entry.stops)){msgContext.error("invalid 'tabs' property for file type \""+fileType+"\"");this._tabs=defaultTabs;return false}this._tabs[fileType]=entry;count++}if(count===0){this._tabs=defaultTabs}else if(!this._tabs.all){this._tabs.all=defaultTabs.all}return true};Tabs.prototype.getTabCol=function(col,fileType){var entry,len,stops,i;if(fileType&&_isFileType(fileType)){entry=this._tabs[fileType]}if(!entry){entry=this._tabs.all;if(!entry){entry=defaultTabs.all}}if(!entry.stops){return col+entry.spaces}else{len=len-1;stops=entry.stops;if(stops.length===0){return _computeTabStop(col,0,entry.spaces?entry.spaces:defaultTabs.spaces)}if(col>=stops[len]){return _computeTabStop(col,stops[len],entry.spaces?entry.spaces:defaultTabs.spaces)}if(col<stops[0]){return stops[0]}for(i=0;i<len;i++){if(col>=stops[i]&&col<stops[i+1]){return stops[i+1]}}}};function _computeTabStop(col,lastStop,inc){var span=col-lastStop;return col+span/inc*inc+span%inc};function _isArrayNumeric(a){var i,ret=-1;for(i=0;i<a.length;i++){if(typeof a[i]!=="number"){ret=i;break}}return ret};function _isTabStops(ts){return Array.isArray(ts)&&_isArrayNumeric(ts)}function _isFileType(fileType){return FILE_TYPES.includes(fileType.toLowerCase())};module.exports=Tabs;