load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary")
load("@rules_closure//closure:defs.bzl", "closure_js_library")
load("//javascript:defs.bzl", "closure_js_deps", "closure_test_suite")

package(default_visibility = ["//visibility:public"])

js_binary(
    name = "strip_trailing_semicolon",
    data = ["typescript/strip-trailing-semicolon.js"],
    entry_point = "typescript/strip-trailing-semicolon.js",
)

js_binary(
    name = "wrap_get_attribute_as_global",
    data = ["typescript/wrap-get-attribute-as-global.js"],
    entry_point = "typescript/wrap-get-attribute-as-global.js",
)

js_run_binary(
    name = "get-attribute-typescript-compiled",
    srcs = ["typescript/get-attribute.ts"],
    outs = ["typescript/get-attribute.compiled.js"],
    args = [
        "--target",
        "ES2017",
        "--module",
        "none",
        "--moduleResolution",
        "node",
        "--removeComments",
        "--pretty",
        "false",
        "--outFile",
        "$(rootpath :typescript/get-attribute.compiled.js)",
        "$(rootpath :typescript/get-attribute.ts)",
    ],
    tool = "@npm_typescript//:tsc",
)

js_run_binary(
    name = "get-attribute-typescript-generated",
    srcs = [":get-attribute-typescript-compiled"],
    outs = ["typescript/get-attribute.generated.js"],
    args = [
        "$(rootpath :get-attribute-typescript-compiled)",
        "$(rootpath :typescript/get-attribute.generated.js)",
    ],
    tool = ":strip_trailing_semicolon",
)

js_run_binary(
    name = "get-attribute-global",
    srcs = [":get-attribute-typescript-compiled"],
    outs = ["typescript/get-attribute-global.js"],
    args = [
        "$(rootpath :get-attribute-typescript-compiled)",
        "$(rootpath :typescript/get-attribute-global.js)",
    ],
    tool = ":wrap_get_attribute_as_global",
)

js_binary(
    name = "wrap_as_global",
    data = ["typescript/wrap-as-global.js"],
    entry_point = "typescript/wrap-as-global.js",
)

js_binary(
    name = "wrap_find_elements_as_global",
    data = ["typescript/wrap-find-elements-as-global.js"],
    entry_point = "typescript/wrap-find-elements-as-global.js",
)

js_run_binary(
    name = "find-elements-typescript-compiled",
    srcs = ["typescript/find-elements.ts"],
    outs = ["typescript/find-elements.compiled.js"],
    args = [
        "--target",
        "ES2017",
        "--module",
        "none",
        "--moduleResolution",
        "node",
        "--removeComments",
        "--pretty",
        "false",
        "--outFile",
        "$(rootpath :typescript/find-elements.compiled.js)",
        "$(rootpath :typescript/find-elements.ts)",
    ],
    tool = "@npm_typescript//:tsc",
)

js_run_binary(
    name = "find-elements-typescript-generated",
    srcs = [":find-elements-typescript-compiled"],
    outs = ["typescript/find-elements.generated.js"],
    args = [
        "$(rootpath :find-elements-typescript-compiled)",
        "$(rootpath :typescript/find-elements.generated.js)",
    ],
    tool = ":strip_trailing_semicolon",
)

js_run_binary(
    name = "find-elements-global",
    srcs = [":find-elements-typescript-compiled"],
    outs = ["typescript/find-elements-global.js"],
    args = [
        "$(rootpath :find-elements-typescript-compiled)",
        "$(rootpath :typescript/find-elements-global.js)",
    ],
    tool = ":wrap_find_elements_as_global",
)

js_run_binary(
    name = "is-displayed-typescript-compiled",
    srcs = ["typescript/is-displayed.ts"],
    outs = ["typescript/is-displayed.compiled.js"],
    args = [
        "--target",
        "ES2017",
        "--module",
        "none",
        "--moduleResolution",
        "node",
        "--removeComments",
        "--pretty",
        "false",
        "--outFile",
        "$(rootpath :typescript/is-displayed.compiled.js)",
        "$(rootpath typescript/is-displayed.ts)",
    ],
    tool = "@npm_typescript//:tsc",
)

js_run_binary(
    name = "is-displayed-typescript-generated",
    srcs = [":is-displayed-typescript-compiled"],
    outs = ["typescript/is-displayed.generated.js"],
    args = [
        "$(rootpath :is-displayed-typescript-compiled)",
        "$(rootpath :typescript/is-displayed.generated.js)",
    ],
    tool = ":strip_trailing_semicolon",
)

js_run_binary(
    name = "is-displayed-global",
    srcs = [":is-displayed-typescript-compiled"],
    outs = ["typescript/is-displayed-global.js"],
    args = [
        "$(rootpath :is-displayed-typescript-compiled)",
        "$(rootpath :typescript/is-displayed-global.js)",
    ],
    tool = ":wrap_as_global",
)

filegroup(
    name = "atoms",
    srcs = glob([
        "**/*.html",
        "**/*.jpg",
        "**/*.js",
        "**/*.png",
        "**/*.svg",
        "**/*.ts",
    ]) + [":get-attribute-global"] + [":is-displayed-global"] + [":find-elements-global"],
    visibility = [
        "//dotnet/test:__subpackages__",
        "//java/test/org/openqa/selenium/environment:__pkg__",
        "//javascript/selenium-webdriver:__pkg__",
    ],
)

closure_js_library(
    name = "action",
    srcs = ["action.js"],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    visibility = [
        "//javascript/atoms/fragments:__pkg__",
        "//javascript/selenium-atoms:__pkg__",
        "//javascript/webdriver/atoms:__pkg__",
        "//javascript/webdriver/atoms/inject:__pkg__",
    ],
    deps = [
        ":bot",
        ":devices",
        ":dom",
        ":errors",
        ":events",
        "//third_party/closure/goog/array",
        "//third_party/closure/goog/dom:tagname",
        "//third_party/closure/goog/math:coordinate",
        "//third_party/closure/goog/math:vec2",
        "//third_party/closure/goog/style",
        "//third_party/closure/goog/useragent",
        "//third_party/closure/goog/useragent:product",
        "//third_party/closure/goog/utils",
    ],
)

closure_js_library(
    name = "bot",
    srcs = ["bot.js"],
    suppress = [
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
)

closure_js_library(
    name = "color",
    srcs = ["color.js"],
    suppress = [
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        "//third_party/closure/goog/array",
        "//third_party/closure/goog/color:names",
    ],
)

closure_js_library(
    name = "devices",
    srcs = [
        "device.js",
        "keyboard.js",
        "mouse.js",
        "touchscreen.js",
    ],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":dom",
        ":errors",
        ":events",
        ":locators",
        ":useragent",
        "//third_party/closure/goog/array",
        "//third_party/closure/goog/dom",
        "//third_party/closure/goog/dom:selection",
        "//third_party/closure/goog/dom:tagname",
        "//third_party/closure/goog/math:coordinate",
        "//third_party/closure/goog/structs:map",
        "//third_party/closure/goog/structs:set",
        "//third_party/closure/goog/useragent",
        "//third_party/closure/goog/useragent:product",
        "//third_party/closure/goog/utils",
    ],
)

closure_js_library(
    name = "domcore",
    srcs = ["domcore.js"],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":errors",
        ":useragent",
        "//third_party/closure/goog/array",
        "//third_party/closure/goog/dom",
        "//third_party/closure/goog/dom:nodetype",
        "//third_party/closure/goog/dom:tagname",
    ],
)

closure_js_library(
    name = "dom",
    srcs = ["dom.js"],
    suppress = [
        "JSC_DEPRECATED_PROP",
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":color",
        ":css",
        ":domcore",
        ":json",
        ":useragent",
        "//third_party/closure/goog/array",
        "//third_party/closure/goog/dom",
        "//third_party/closure/goog/dom:nodetype",
        "//third_party/closure/goog/dom:tagname",
        "//third_party/closure/goog/math",
        "//third_party/closure/goog/math:coordinate",
        "//third_party/closure/goog/math:rect",
        "//third_party/closure/goog/string",
        "//third_party/closure/goog/style",
        "//third_party/closure/goog/useragent",
    ],
)

closure_js_library(
    name = "errors",
    srcs = [
        "error.js",
        "response.js",
    ],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        "//third_party/closure/goog/utils",
    ],
)

closure_js_library(
    name = "events",
    srcs = ["events.js"],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":dom",
        ":errors",
        ":json",
        ":useragent",
        "//third_party/closure/goog/array",
        "//third_party/closure/goog/dom",
        "//third_party/closure/goog/events:browserevent",
        "//third_party/closure/goog/style",
        "//third_party/closure/goog/useragent",
        "//third_party/closure/goog/useragent:product",
        "//third_party/closure/goog/utils",
    ],
)

closure_js_library(
    name = "frame",
    srcs = ["frame.js"],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    visibility = [
        "//javascript/webdriver/atoms/inject:__pkg__",
    ],
    deps = [
        ":bot",
        ":dom",
        ":errors",
        ":locators",
        "//third_party/closure/goog/dom",
        "//third_party/closure/goog/dom:tagname",
    ],
)

closure_js_library(
    name = "html5",
    srcs = glob(["html5/*.js"]),
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":errors",
        ":json",
        ":useragent",
        "//third_party/closure/goog/useragent",
        "//third_party/closure/goog/useragent:product",
    ],
)

closure_js_library(
    name = "inject",
    srcs = ["inject.js"],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    visibility = [
        "//javascript/atoms/fragments:__pkg__",
        "//javascript/selenium-atoms:__pkg__",
        "//javascript/webdriver/atoms/inject:__pkg__",
    ],
    deps = [
        ":bot",
        ":errors",
        ":json",
        "//third_party/closure/goog/array",
        "//third_party/closure/goog/dom:nodetype",
        "//third_party/closure/goog/object",
        "//third_party/closure/goog/useragent",
        "//third_party/closure/goog/utils",
    ],
)

closure_js_library(
    name = "json",
    srcs = ["json.js"],
    suppress = [
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":useragent",
        "//third_party/closure/goog/json",
        "//third_party/closure/goog/useragent",
    ],
)

closure_js_library(
    name = "locators",
    srcs = glob(
        ["locators/*.js"],
        exclude = ["locators/css.js"],
    ),
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_LATE_PROVIDE_ERROR",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":css",
        ":dom",
        ":errors",
        ":json",
        ":useragent",
        "//third_party/closure/goog/array",
        "//third_party/closure/goog/dom",
        "//third_party/closure/goog/dom:nodetype",
        "//third_party/closure/goog/dom:tagname",
        "//third_party/closure/goog/math:rect",
        "//third_party/closure/goog/string",
        "//third_party/closure/goog/useragent",
        "//third_party/closure/goog/useragent:product",
        "//third_party/closure/goog/utils",
    ],
)

closure_js_library(
    name = "useragent",
    srcs = ["userAgent.js"],
    suppress = [
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        "//third_party/closure/goog/string",
        "//third_party/closure/goog/useragent",
        "//third_party/closure/goog/useragent:product",
        "//third_party/closure/goog/useragent:product_isversion",
    ],
)

closure_js_library(
    name = "window",
    srcs = [
        "frame.js",
        "window.js",
    ],
    suppress = [
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":errors",
        ":events",
        ":json",
        ":locators",
    ],
)

closure_js_library(
    name = "css",
    srcs = ["locators/css.js"],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":errors",
        ":useragent",
        "//third_party/closure/goog/dom:nodetype",
        "//third_party/closure/goog/string",
        "//third_party/closure/goog/useragent",
        "//third_party/closure/goog/utils",
    ],
)

closure_js_library(
    name = "test_util",
    testonly = 1,
    srcs = ["test/test_util.js"],
    suppress = [
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":useragent",
    ],
)

closure_js_deps(
    name = "deps",
    testonly = True,
    visibility = [
        "//:__pkg__",
        "//java/test/org/openqa/selenium/environment:__pkg__",
        "//javascript:__pkg__",
        "//javascript/webdriver:__pkg__",
    ],
    deps = [
        ":action",
        ":bot",
        ":color",
        ":css",
        ":devices",
        ":dom",
        ":domcore",
        ":errors",
        ":events",
        ":html5",
        ":inject",
        ":json",
        ":locators",
        ":test_util",
        ":useragent",
        ":window",
        "//third_party/closure/goog:library",
        "//third_party/closure/goog:testing",
    ],
)

closure_test_suite(
    name = "closure-test",
    data = [
        ":atoms",
        ":deps",
    ],
)
