{"version":3,"file":"_error-state-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/core/common-behaviors/error-state.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {AbstractControl, FormGroupDirective, NgControl, NgForm} from '@angular/forms';\nimport {Subject} from 'rxjs';\nimport {ErrorStateMatcher as _ErrorStateMatcher} from '../error/error-options';\nimport {FormField} from '@angular/forms/signals';\nimport {isSignal} from '@angular/core';\n\n// Declare ErrorStateMatcher as an interface to have compatibility with Closure Compiler.\ninterface ErrorStateMatcher extends _ErrorStateMatcher {}\n\n/**\n * Class that tracks the error state of a component.\n * @docs-private\n */\nexport class _ErrorStateTracker {\n  /** Whether the tracker is currently in an error state. */\n  errorState = false;\n\n  /** User-defined matcher for the error state. */\n  matcher!: ErrorStateMatcher;\n\n  /** Reactive or template-based control directive. */\n  ngControl: NgControl | null;\n\n  /** Signal-based form field directive. */\n  formField: FormField<unknown> | null;\n\n  constructor(\n    private _defaultMatcher: ErrorStateMatcher | null,\n    directive: NgControl | FormField<unknown> | null,\n    private _parentFormGroup: FormGroupDirective | null,\n    private _parentForm: NgForm | null,\n    private _stateChanges: Subject<void>,\n  ) {\n    if (!directive) {\n      this.ngControl = this.formField = null;\n    } else if (\n      isSignal((directive as {field?: unknown}).field) &&\n      // Avoid false positives for interop controls.\n      !(directive as {updateValueAndValidity?: unknown}).updateValueAndValidity\n    ) {\n      this.formField = directive as FormField<unknown>;\n      this.ngControl = null;\n    } else {\n      this.formField = null;\n      this.ngControl = directive as NgControl;\n    }\n  }\n\n  /** Updates the error state based on the provided error state matcher. */\n  updateErrorState() {\n    const oldState = this.errorState;\n    const matcher = this.matcher || this._defaultMatcher;\n    let newState: boolean;\n\n    if (this.formField) {\n      if (\n        (typeof ngDevMode === 'undefined' || ngDevMode) &&\n        matcher &&\n        !matcher.isSignalErrorState\n      ) {\n        throw new Error(\n          'Current error state matcher does not support signal forms. ' +\n            'Please implement the `isSignalErrorState` method.',\n        );\n      }\n\n      newState = matcher?.isSignalErrorState?.(this.formField.field()) ?? false;\n    } else {\n      const parent = this._parentFormGroup || this._parentForm;\n      const control = this.ngControl ? (this.ngControl.control as AbstractControl) : null;\n      newState = matcher?.isErrorState(control, parent) ?? false;\n    }\n\n    if (newState !== oldState) {\n      this.errorState = newState;\n      this._stateChanges.next();\n    }\n  }\n}\n"],"names":["_ErrorStateTracker","_defaultMatcher","_parentFormGroup","_parentForm","_stateChanges","errorState","matcher","ngControl","formField","constructor","directive","isSignal","field","updateValueAndValidity","updateErrorState","oldState","newState","ngDevMode","isSignalErrorState","Error","parent","control","isErrorState","next"],"mappings":";;MAqBaA,kBAAkB,CAAA;EAcnBC,eAAA;EAEAC,gBAAA;EACAC,WAAA;EACAC,aAAA;AAhBVC,EAAAA,UAAU,GAAG,KAAK;EAGlBC,OAAO;EAGPC,SAAS;EAGTC,SAAS;EAETC,WAAAA,CACUR,eAAyC,EACjDS,SAAgD,EACxCR,gBAA2C,EAC3CC,WAA0B,EAC1BC,aAA4B,EAAA;IAJ5B,IAAA,CAAAH,eAAe,GAAfA,eAAe;IAEf,IAAA,CAAAC,gBAAgB,GAAhBA,gBAAgB;IAChB,IAAA,CAAAC,WAAW,GAAXA,WAAW;IACX,IAAA,CAAAC,aAAa,GAAbA,aAAa;IAErB,IAAI,CAACM,SAAS,EAAE;AACd,MAAA,IAAI,CAACH,SAAS,GAAG,IAAI,CAACC,SAAS,GAAG,IAAI;AACxC,IAAA,CAAA,MAAO,IACLG,QAAQ,CAAED,SAA+B,CAACE,KAAK,CAAC,IAEhD,CAAEF,SAAgD,CAACG,sBAAsB,EACzE;MACA,IAAI,CAACL,SAAS,GAAGE,SAA+B;MAChD,IAAI,CAACH,SAAS,GAAG,IAAI;AACvB,IAAA,CAAA,MAAO;MACL,IAAI,CAACC,SAAS,GAAG,IAAI;MACrB,I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