load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_deps", "closure_js_library")
load("//javascript:defs.bzl", "closure_test_suite")

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

filegroup(
    name = "atoms",
    srcs = glob([
        "**/*.html",
        "**/*.jpg",
        "**/*.js",
        "**/*.png",
        "**/*.svg",
    ]),
    visibility = [
        "//dotnet/test:__subpackages__",
        "//java/test/org/openqa/selenium/environment:__pkg__",
        "//javascript/node/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",
        "@io_bazel_rules_closure//closure/library",
    ],
)

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 = [
        "@io_bazel_rules_closure//closure/library",
    ],
)

closure_js_library(
    name = "devices",
    srcs = [
        "device.js",
        "keyboard.js",
        "mouse.js",
        "touchscreen.js",
    ],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_MISSING_CONST_PROPERTY",
        "JSC_NULLABLE_RETURN_WITH_NAME",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":dom",
        ":errors",
        ":events",
        ":locators",
        ":useragent",
        "@io_bazel_rules_closure//closure/library",
    ],
)

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",
        "@io_bazel_rules_closure//closure/library",
    ],
)

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",
        "@io_bazel_rules_closure//closure/library",
    ],
)

closure_js_library(
    name = "errors",
    srcs = [
        "error.js",
        "response.js",
    ],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_MISSING_CONST_PROPERTY",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
)

closure_js_library(
    name = "events",
    srcs = ["events.js"],
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_MISSING_CONST_PROPERTY",
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":dom",
        ":errors",
        ":json",
        ":useragent",
        "@io_bazel_rules_closure//closure/library",
    ],
)

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

closure_js_library(
    name = "html5",
    srcs = glob(["html5/*.js"]),
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_NULLABLE_RETURN_WITH_NAME",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":errors",
        ":json",
        ":useragent",
        "@io_bazel_rules_closure//closure/library/useragent:all_js",
    ],
)

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",
        "@io_bazel_rules_closure//closure/library",
    ],
)

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

closure_js_library(
    name = "locators",
    srcs = glob(
        ["locators/*.js"],
        exclude = ["locators/css.js"],
    ),
    suppress = [
        "JSC_IMPLICITLY_NULLABLE_JSDOC",
        "JSC_LATE_PROVIDE_ERROR",
        "JSC_NULLABLE_RETURN_WITH_NAME",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = [
        ":bot",
        ":css",
        ":dom",
        ":errors",
        ":json",
        ":useragent",
        "//third_party/js/wgxpath",
        "@io_bazel_rules_closure//closure/library",
    ],
)

closure_js_library(
    name = "useragent",
    srcs = ["userAgent.js"],
    suppress = [
        "JSC_STRICT_INEXISTENT_PROPERTY",
        "JSC_UNKNOWN_EXPR_TYPE",
        "JSC_USE_OF_GOOG_PROVIDE",
    ],
    deps = ["@io_bazel_rules_closure//closure/library"],
)

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",
        "@io_bazel_rules_closure//closure/library",
    ],
)

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

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",
    ],
)

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