/**
 * @since Last modified: 2024/05/06 00:30:41
 * @function getExpiration
 * @param {'s'|'m'|'h'|'d'} [type=d] - The date unit that calculates the expiration time.The optional value is 's'(second) | 'm'(minute) | 'h'(hour) | 'd'(day,default).
 * @paran {number | string} [value=365] - The value of The date unit.The default value is 365.
 * @paran {'utc' | 'locale'} [output='locale'] - Output timestamp type.
 * @description Get the expiration time.
 * @returns {string} Return a UTC date(e.g. 'Wed, 15 Nov 2023 02:52:40 GMT').
 * @see {@link https://codepen.io/axui/pen/bGzoYQz|demo @ codepen}
 * @example
 * ax.getExpiration('h',10);
 * <!-- return a timestamp -->
 */





'use strict';
import getUTCTimestamp from './getUTCTimestamp';
import isDateStr from './isDateStr';
const getExpiration = (type: 's' | 'm' | 'h' | 'd' = 'd', value: number | string = 365, output: 'utc' | 'locale' = 'locale'): string => {
    let dateExp: any;
    if (isDateStr(value)) {
        
        
        dateExp = new Date(value);
    } else {
        dateExp = new Date();
        
        switch (type) {
            case 's':
                
                dateExp.setSeconds(dateExp.getSeconds() + ~~value);
                
                
                break;
            case 'm':
                
                dateExp.setMinutes(dateExp.getMinutes() + ~~value);
                
                break;
            case 'h':
                
                dateExp.setHours(dateExp.getHours() + ~~value);
                
                break;
            default:
                
                dateExp.setDate(dateExp.getDate() + ~~value);
            
        }
    }
    return output === 'utc' ? getUTCTimestamp(dateExp) : dateExp.getTime();
}
export default getExpiration;
