const AUTOMATION_ID = "data-id";

/**
 * https://zgit.csez.zohocorpin.com/zohodesk/desk-library/-/blob/unified-components-master/jsapps/unifiedcomponents/src/propTypes/Readme.automation.md#automation-props-support-in-component
 * @param {*} param customId, customIdPrefix , customIdSuffix
 * @param {*} defaultCustomId 
 * @param {*} otherCustomOption 
 * @returns 
 */
const getCompliedCustomId = (
  { customId, customIdPrefix = "", customIdSuffix = "" },
  defaultCustomId,
  otherCustomOption=[]
) => {
  let returnId = defaultCustomId || customId;

  if (typeof defaultCustomId === "function") {
    let options  = [ '',customIdPrefix, customIdSuffix, ...otherCustomOption];
    returnId = defaultCustomId.apply(null,options);
    //returnId = defaultCustomId`${customIdPrefix} ${customIdSuffix}`;
  }

  return returnId ? returnId.toLowerCase() : null;
};

/**
 * https://zgit.csez.zohocorpin.com/zohodesk/desk-library/-/blob/unified-components-master/jsapps/unifiedcomponents/src/propTypes/Readme.automation.md#to-avoid-prefix-and-suffix-in-nested-level-of-tags-in-html-structure-how-to-handle
 * @param  {...any} props 
 * @returns  { data-id : '...' }
 */
export const getCompliedCustomIdProps = (...props)=>{
    return { [AUTOMATION_ID] : getCompliedCustomId(...props) }
}


/**
 * https://zgit.csez.zohocorpin.com/zohodesk/desk-library/-/blob/unified-components-master/jsapps/unifiedcomponents/src/propTypes/Readme.automation.md#to-avoid-prefix-and-suffix-in-nested-level-of-tags-in-html-structure-how-to-handle
 * @param  {...any} props 
 * @returns { data-id : '...' }
 */
export const getCompliedCustomIdOnlyProps = (...props)=>{
    return { [AUTOMATION_ID] : getCompliedCustomIdOnly(...props) }
}


/**
 * https://zgit.csez.zohocorpin.com/zohodesk/desk-library/-/blob/unified-components-master/jsapps/unifiedcomponents/src/propTypes/Readme.automation.md#a-componentcustomidjs-in-html-part-of-component-for-only-root-level-supported-prefixsuffix
 * @param {*} defaultCustomId 
 * @param {*} otherCustomOption as array of strings
 * @returns 
 */
export const getCompliedCustomIdOnly=( defaultCustomId, otherCustomOption=[])=>{

  let returnId = defaultCustomId;

  if (typeof defaultCustomId === "function") {
    let options  = [ '', ...otherCustomOption];
    returnId = defaultCustomId.apply(null,options);
    //returnId = defaultCustomId`${customIdPrefix} ${customIdSuffix}`;
  }

  return returnId ? returnId.toLowerCase() : null;
}

export default  getCompliedCustomId;