/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
const SEGMENT_INDEX_DICT = {
    hours: 0,
    minutes: 1,
    seconds: 2,
    meridiem: 3
};
export class TimeSegmentParser {
    constructor(timeStr) {
        this._segments = this._parseSegments(timeStr);
    }
    get hours() {
        return this._segments[SEGMENT_INDEX_DICT.hours];
    }
    get minutes() {
        return this._segments[SEGMENT_INDEX_DICT.minutes];
    }
    get seconds() {
        return this._segments[SEGMENT_INDEX_DICT.seconds];
    }
    get meridiem() {
        return this._segments[SEGMENT_INDEX_DICT.meridiem];
    }
    applyValue(timeStr) {
        this._segments = this._parseSegments(timeStr);
    }
    patchSegmentValue(type, value) {
        const index = SEGMENT_INDEX_DICT[type];
        this._segments[index] = value.padStart(2, '0');
        return this._segments[index];
    }
    toString() {
        const [hours, minutes, seconds, meridiem] = this._segments;
        const timeStr = [hours, minutes, seconds].filter(v => !!v.length);
        return `${timeStr.join(':')}${meridiem}`;
    }
    _parseSegments(timeStr) {
        const [time, meridiem = ''] = timeStr.trim().replace(/\s+|_/g, '').split(/([AaPp][Mm]?)/);
        const [hours = '', minutes = '', seconds = ''] = time.split(':');
        return [hours, minutes, seconds, meridiem];
    }
}
