import { LitElement , property } from 'lit-element' ; import { get } from 'lit-translate' ; import { LogDetail , LogDetailBase , newIssueEvent , newLogEvent , } from '../foundation.js' ; import { validateChildren } from './templates/foundation.js' ; type ValidationResult = LogDetailBase | LogDetail ; export function dispatch ( detail , validatorId ) { const kind = ( < LogDetail > detail ) . kind ; const title = ( < LogDetailBase > detail ) . title ; const message = ( < LogDetailBase > detail ) . message ; if ( kind ) document . querySelector ( 'open-scd' ) ?. dispatchEvent ( newLogEvent ( < LogDetail > detail ) ) ; else document . querySelector ( 'open-scd' ) ?. dispatchEvent ( newIssueEvent ( { validatorId , title , message , } ) ) ; } export default class ValidateTemplates extends LitElement { @ property ( { attribute : false } ) doc ! : XMLDocument ; @ property ( ) docName ! : string ; @ property ( ) pluginId ! : string ; async validate ( ) { const promises = [ ] ; const [ version , revision , release ] = [ this . doc . documentElement . getAttribute ( 'version' ) ?? '' , this . doc . documentElement . getAttribute ( 'revision' ) ?? '' , this . doc . documentElement . getAttribute ( 'release' ) ?? '' , ] ; if ( ! ( version === '2007' && revision === 'B' && Number ( release ) > 3 ) ) { document . querySelector ( 'open-scd' ) ?. dispatchEvent ( newIssueEvent ( { validatorId : this . pluginId , title : get ( 'diag.missingnsd' ) , message : '' , } ) ) ; return ; } const data = this . doc . querySelector ( 'DataTypeTemplates' ) ; if ( ! data ) return ; const issuesTemaplte = await validateChildren ( data ) ; if ( issuesTemaplte . length === 0 ) issuesTemaplte . push ( { title : get ( 'diag.zeroissues' ) , } ) ; issuesTemaplte . forEach ( error => dispatch ( error , this . pluginId ) ) ; } }