package Koha::Plugin::Pt::KEEPS::BiblioDisable999;

use Modern::Perl;

use base qw(Koha::Plugins::Base);

our $VERSION = '1.0';

our $metadata = {
    name   => 'KEEPS - Biblio Disable Field 999',
    author => 'Keep Solutions',
    description => 'Sets all 999 MARC subfields as readonly',
    date_authored   => '2022-01-21',
    date_updated    => undef,
    minimum_version => '21.05',
    maximum_version => undef,
    version         => $VERSION,
};

sub new {
    my ( $class, $args ) = @_;

    $args->{'metadata'} = $metadata;
    $args->{'metadata'}->{'class'} = $class;

    my $self = $class->SUPER::new($args);

    return $self;
}

# Mandatory even if does nothing
sub install {
    my ( $self, $args ) = @_;

    return 1;
}

# Mandatory even if does nothing
sub upgrade {
    my ( $self, $args ) = @_;

    return 1;
}

# Mandatory even if does nothing
sub uninstall {
    my ( $self, $args ) = @_;

    return 1;
}

sub intranet_js {
    my ( $self ) = @_;

    return q%
<script>
    var pathname = window.location.pathname;
    if (pathname.match("/cgi-bin/koha/cataloguing/addbiblio.pl") && $("body#cat_addbiblio").length) {
        $('input[id^="tag_999_subfield_a"],input[id^="tag_999_subfield_b"],input[id^="tag_999_subfield_c"],input[id^="tag_999_subfield_d"]').attr("readonly", "readonly");
        $('input[id^="tag_999_subfield_a"],input[id^="tag_999_subfield_b"],input[id^="tag_999_subfield_c"],input[id^="tag_999_subfield_d"]').addClass("readonly");
    }
</script>
%;
}

1;