// @ts-check

/**
 * Manage layouts' templates files
 */
module.exports = function tplLayouts() {
  const path = require("path");
  const gulp = require("gulp");
  const rename = require("gulp-rename");
  const paths = require("../paths");
  const { src, dest } = paths.frontend;

  return gulp
    .src(path.join(src.layouts, "**/*.php"), { base: src.layouts })
    .pipe(
      rename((path) => {
        // flatten index file names by using the folder name
        if (path.basename.startsWith("index")) {
          path.basename = path.dirname + ".blade";
          path.dirname = "";
        }
      })
    )
    .pipe(gulp.dest(dest.layouts));
};
