/*
Copyright 2021 Q-CTRL. All rights reserved.

Licensed under the Q-CTRL Terms of service (the "License"). Unauthorized
copying or use of this file, via any medium, is strictly prohibited.
Proprietary and confidential. You may not use this file except in compliance
with the License. You may obtain a copy of the License at

     https://q-ctrl.com/terms

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS. See the
License for the specific language.
*/
const _ = require("lodash");

const plugin = require("tailwindcss/plugin"); // Spacing


module.exports = function ({
  addUtilities,
  theme,
  variants,
  e
}) {
  const spacersUtilities = _.map(theme("spacer"), (value, key) => {
    return {
      // Spacer Padding
      [`.${e(`sp-${key}`)}`]: {
        padding: `${value}`
      },
      [`.${e(`spy-${key}`)}`]: {
        paddingTop: `${value}`,
        paddingBottom: `${value}`
      },
      [`.${e(`spx-${key}`)}`]: {
        paddingLeft: `${value}`,
        paddingRight: `${value}`
      },
      [`.${e(`spt-${key}`)}`]: {
        paddingTop: `${value}`
      },
      [`.${e(`spb-${key}`)}`]: {
        paddingBottom: `${value}`
      },
      [`.${e(`spl-${key}`)}`]: {
        paddingLeft: `${value}`
      },
      [`.${e(`spr-${key}`)}`]: {
        paddingRight: `${value}`
      },
      // Spacer Margin
      [`.${e(`sm-${key}`)}`]: {
        margin: `${value}`
      },
      [`.${e(`smy-${key}`)}`]: {
        marginTop: `${value}`,
        marginBottom: `${value}`
      },
      [`.${e(`smx-${key}`)}`]: {
        marginLeft: `${value}`,
        marginRight: `${value}`
      },
      [`.${e(`smt-${key}`)}`]: {
        marginTop: `${value}`
      },
      [`.${e(`smb-${key}`)}`]: {
        marginBottom: `${value}`
      },
      [`.${e(`sml-${key}`)}`]: {
        marginLeft: `${value}`
      },
      [`.${e(`smr-${key}`)}`]: {
        marginRight: `${value}`
      },
      // Spacer Size
      [`.${e(`sw-${key}`)}`]: {
        width: `${value}`
      },
      [`.${e(`sh-${key}`)}`]: {
        height: `${value}`
      }
    };
  });

  const frameUtilities = _.map(theme("frame"), (value, key) => {
    return {
      [`.${e(`frame-${key}`)}`]: {
        padding: `${value}`
      }
    };
  });

  const frameBorderUtilities = _.map(theme("borderFrame"), (value, key) => {
    return {
      [`.${e(`b-frame-${key}`)}`]: {
        padding: `${value}`
      }
    };
  });

  const frameSquashUtilities = _.map(theme("squash"), (value, key) => {
    return {
      [`.${e(`squash-${key}`)}`]: {
        padding: `${value}`
      }
    };
  });

  const frameBorderSquashUtilities = _.map(theme("borderSquash"), (value, key) => {
    return {
      [`.${e(`b-squash-${key}`)}`]: {
        padding: `${value}`
      }
    };
  });

  const frameStretchUtilities = _.map(theme("stretch"), (value, key) => {
    return {
      [`.${e(`stretch-${key}`)}`]: {
        padding: `${value}`
      }
    };
  });

  const frameBorderStretchUtilities = _.map(theme("borderStretch"), (value, key) => {
    return {
      [`.${e(`b-stretch-${key}`)}`]: {
        padding: `${value}`
      }
    };
  });

  const stacksUtilities = _.map(theme("stack"), (value, key) => {
    return {
      [`.${e(`stack-${key}`)}`]: {
        margin: `0 0 ${value}`
      },
      [`.${e(`stack-t-${key}`)}`]: {
        margin: `${value} 0 0`
      }
    };
  });

  const inlinesUtilities = _.map(theme("inline"), (value, key) => {
    return {
      [`.${e(`inline-${key}`)}`]: {
        margin: `0 ${value} 0 0`
      },
      [`.${e(`inline-l-${key}`)}`]: {
        margin: `0 0 0 ${value}`
      },
      [`.${e(`inline-r-${key}`)}`]: {
        margin: `0 ${value} 0 0`
      }
    };
  });

  addUtilities([spacersUtilities, frameUtilities, frameBorderUtilities, frameSquashUtilities, frameBorderSquashUtilities, frameStretchUtilities, frameBorderStretchUtilities, stacksUtilities, inlinesUtilities], variants('spacers'));
};