import { warn } from '@delon/util/other' ; import type { NzSafeAny } from 'ng-zorro-antd/core/types' ; export type BooleanInput = boolean | string | undefined | null ; export type NumberInput = number | string | undefined | null ; function propDecoratorFactory < T , D > ( name , fallback , defaultValue ) { function propDecorator ( target , propName , originalDescriptor ? ) { const privatePropName = `$$__${ propName }` ; if ( typeof ngDevMode === 'undefined' || ngDevMode ) { if ( Object . prototype . hasOwnProperty . call ( target , privatePropName ) ) { warn ( `The prop "${ privatePropName }" is already exist, it will be overrided by ${ name } decorator.` ) ; } } Object . defineProperty ( target , privatePropName , { configurable : true , writable : true } ) ; return { get ( ) { return originalDescriptor && originalDescriptor . get ? originalDescriptor . get . bind ( this ) ( ) : this [ privatePropName ] ; } , set ( value ) { if ( originalDescriptor && originalDescriptor . set ) { originalDescriptor . set . bind ( this ) ( fallback ( value , defaultValue ) ) ; } this [ privatePropName ] = fallback ( value , defaultValue ) ; } } ; } return propDecorator ; } export function toBoolean ( value , defaultValue = false ) { return value == null ? defaultValue : `${ value }` !== 'false' ; } /**
 * Input decorator that handle a prop to do get/set automatically with toBoolean
 *
 * ```ts
 * {AT}Input() {AT}InputBoolean() visible: boolean = false;
 * {AT}Input() {AT}InputBoolean(null) visible: boolean = false;
 * ```
 */ export function InputBoolean ( defaultValue = false ) { return propDecoratorFactory ( 'InputBoolean' , toBoolean , defaultValue ) ; } export function toNumber ( value ) ; export function toNumber < D > ( value , fallback ) ; export function toNumber ( value , fallbackValue = 0 ) { return ! isNaN ( parseFloat ( value as NzSafeAny ) ) && ! isNaN ( Number ( value ) ) ? Number ( value ) : fallbackValue ; } /**
 * Input decorator that handle a prop to do get/set automatically with toNumber
 *
 * ```ts
 * {AT}Input() {AT}InputNumber() visible: number = 1;
 * {AT}Input() {AT}InputNumber(null) visible: number = 2;
 * ```
 */ export function InputNumber ( defaultValue = 0 ) { return propDecoratorFactory ( 'InputNumber' , toNumber , defaultValue ) ; }