/**
 * @since Last modified: 2024/06/10 17:48:16
 * @function breakpoints
 * @description Automatically modify the parameters according to the user terminal.
 * @param {object} obj - Original parameters  (object type).
 * @param {string|number} points - breakpoints.
 * @returns {object|false}  - Returns the the modified parameters.
 * @see {@link https://codepen.io/axui/pen/vYbmqYj|demo @ codepen}
 * @example
 * ax.breakpoints({},{'width-500':{},'width-800':{}});
 * <!--The param points Support five ways of writing-->
 * 1.{'screen-xs':{},'screen-sm':{}...}，
 * 2.{'width-500':{},'width-900':{}...}
 * 3.{'mobile-true':{},'mobile-false':{}}
 * 4.{500:{},900:{}}
 */








'use strict';
import isEmpty from "./isEmpty";
import isMobi from "./isMobi";
import screenSize from "./screenSize";
import extend from "./extend";
import { T_obj } from "../../../types/ax";
const breakpoints = (obj:T_obj, points:T_obj) => {
    if (isEmpty(obj)) {
        return false;
    }
    let valids:object[] = [],
        assign = {},
        width = document.body.clientWidth,
        validFun = (key:string, value:object) => {
            
            let _key = ~~key;
            if(_key === 0){
                if (key.startsWith('screen')) {
                    
                    screenSize === key.split('-')[1] ? valids.push(value) : null;
                } else if (key.startsWith('width')) {
                    
                    ~~key.split('-')[1] > width ? valids.push(value) : null;
                } else if (key.startsWith('mobile')) {
                    
                    JSON.parse(key.split('-')[1])  === isMobi ? valids.push(value) : null;
                } 
            }else{
                 
                _key > width ? valids.push(value) : null;
            }
        };
    for (let k in points) {
        if (points.hasOwnProperty(k)) {
            
            Reflect.deleteProperty(points[k], 'breakpoints');
            validFun(k, points[k]);
        }
    }
    if (valids.length === 0) {
        return false;
    }
    assign = Object.assign({},...valids);
    extend({target:obj,source: assign});
};
export default breakpoints;
