package Koha::Plugin::Pt::KEEPS::FCSHItemsTable;

use Modern::Perl;

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

our $VERSION = '1.0';

our $metadata = {
    name   => 'KEEPS - Items Table (FCSH)',
    author => 'Keep Solutions',
    description => 'Changes some columns of items tables',
    date_authored   => '2024-07-19',
    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 ) = @_;
    startup();

    return 1;
}

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

    return 1;
}

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

    my $DIR = "/KEEPS/koha";
    my $INTRANET_EN= $DIR . "/intranet/htdocs/intranet-tmpl/prog/en/modules/catalogue";
    my $INTRANET_PT= $DIR . "/intranet/htdocs/intranet-tmpl/prog/pt-PT/modules/catalogue";
    my $OPAC_EN= $DIR . "/opac/htdocs/opac-tmpl/bootstrap/en/modules";
    my $OPAC_PT= $DIR . "/opac/htdocs/opac-tmpl/bootstrap/pt-PT/modules";

    system("rm $INTRANET_EN/detail.tt");
    system("mv $INTRANET_EN/detail_bkp.tt $INTRANET_EN/detail.tt");
    system("rm $INTRANET_PT/detail.tt");
    system("mv $INTRANET_PT/detail_bkp.tt $INTRANET_PT/detail.tt");
    system("rm $OPAC_EN/detail.tt");
    system("mv $OPAC_EN/detail_bkp.tt $OPAC_EN/detail.tt");
    system("rm $OPAC_PT/opac-detail.tt");
    system("mv $OPAC_PT/opac-detail_bkp.tt $OPAC_PT/opac-detail.tt");

    return 1;
}

sub startup {
    my $pluginsdir = C4::Context->config("pluginsdir");
    my $path = $pluginsdir . "/Koha/Plugin/Pt/KEEPS/FCSHItemsTable";

    my $DIR = "/KEEPS/koha";
    my $INTRANET_EN= $DIR . "/intranet/htdocs/intranet-tmpl/prog/en/modules/catalogue";
    my $INTRANET_PT= $DIR . "/intranet/htdocs/intranet-tmpl/prog/pt-PT/modules/catalogue";
    my $OPAC_EN= $DIR . "/opac/htdocs/opac-tmpl/bootstrap/en/modules";
    my $OPAC_PT= $DIR . "/opac/htdocs/opac-tmpl/bootstrap/pt-PT/modules";

    system("mv $INTRANET_EN/detail.tt $INTRANET_EN/detail_bck.tt");
    system("cp $path/detail_en.tt $INTRANET_EN/detail.tt");
    system("mv $INTRANET_PT/detail.tt $INTRANET_PT/detail_bck.tt");
    system("cp $path/detail_pt.tt $INTRANET_PT/detail.tt");
    system("mv $OPAC_EN/opac-detail.tt $OPAC_EN/opac-detail_bck.tt");
    system("cp $path/opac-detail_en.tt $OPAC_EN/opac-detail.tt");
    system("mv $OPAC_PT/opac-detail.tt $OPAC_PT/opac-detail_bck.tt");
    system("cp $path/opac-detail_pt.tt $OPAC_PT/opac-detail.tt");
}

1;
