/**
 * Mixin for form error checking in checkout components.
 * Provides hasError() to check nested error paths.
 */
export default {
    methods: {
        // Walk a dotted path into this.errors; returns undefined if any segment is missing.
        _resolveError(path) {
            let obj = this.errors;
            for (const part of path.split('.')) {
                if (!obj || typeof obj !== 'object') return undefined;
                obj = obj[part];
            }
            return obj;
        },

        hasError(path) {
            return !!this._resolveError(path);
        },

        errorText(path) {
            return this._resolveError(path) || '';
        }
    }
};
